Skip to content

Commit

Permalink
kafkauser endpoints were migrated to APIv3
Browse files Browse the repository at this point in the history
  • Loading branch information
tengu-alt committed Oct 2, 2023
1 parent 3723b60 commit 6cc29e8
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 48 deletions.
13 changes: 8 additions & 5 deletions apis/kafkamanagement/v1beta1/kafkauser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type KafkaUserSpec struct {
type KafkaUserOptions struct {
OverrideExistingUser bool `json:"overrideExistingUser,omitempty"`
SASLSCRAMMechanism string `json:"saslScramMechanism"`
AuthMechanism string `json:"authMechanism"`
}

// KafkaUserStatus defines the observed state of KafkaUser
Expand Down Expand Up @@ -121,11 +122,13 @@ func init() {

func (ks *KafkaUserSpec) ToInstAPI(clusterID string, username string, password string) *models.KafkaUser {
return &models.KafkaUser{
ClusterID: clusterID,
InitialPermissions: ks.InitialPermissions,
Options: ks.Options.ToInstAPI(),
Username: username,
Password: password,
Password: password,
OverrideExistingUser: ks.Options.OverrideExistingUser,
SASLSCRAMMechanism: ks.Options.SASLSCRAMMechanism,
AuthMechanism: ks.Options.AuthMechanism,
ClusterID: clusterID,
InitialPermissions: ks.InitialPermissions,
Username: username,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ spec:
type: string
options:
properties:
authMechanism:
type: string
overrideExistingUser:
type: boolean
saslScramMechanism:
type: string
required:
- authMechanism
- saslScramMechanism
type: object
secretRef:
Expand Down
5 changes: 3 additions & 2 deletions config/samples/kafkamanagement_v1beta1_kafkauser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: secret-test
data:
username: "U2FuY2gtdHdvCg=="
password: "Qm9oZGFuXyF1YmVyX3VudGVyX3ZhZmVsb2sxNDg4X2lnb3JfdG9saWsxNDg4Cg=="
password: "Qm9oZGFuX3ViZXJfdW50ZXJfaWdvcl90b2xpazEK"
---
apiVersion: kafkamanagement.instaclustr.com/v1beta1
kind: KafkaUser
Expand Down Expand Up @@ -36,4 +36,5 @@ spec:
initialPermissions: "standard"
options:
overrideExistingUser: true
saslScramMechanism: "SCRAM-SHA-256"
saslScramMechanism: "SCRAM-SHA-256"
authMechanism: "SASL"
34 changes: 0 additions & 34 deletions pkg/instaclustr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,40 +887,6 @@ func (c *Client) UpdateKafkaTopic(url string, t *kafkamanagementv1beta1.Topic) e
return nil
}

func (c *Client) GetKafkaUserStatus(
kafkaUserID,
kafkaUserEndpoint string,
) (*kafkamanagementv1beta1.KafkaUserStatus, error) {
url := c.serverHostname + kafkaUserEndpoint + kafkaUserID

resp, err := c.DoRequest(url, http.MethodGet, nil)
if err != nil {
return nil, err
}

defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}

if resp.StatusCode == http.StatusNotFound {
return nil, NotFound
}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("status code: %d, message: %s", resp.StatusCode, body)
}

var kafkaUserStatus kafkamanagementv1beta1.KafkaUserStatus
err = json.Unmarshal(body, &kafkaUserStatus)
if err != nil {
return nil, err
}

return &kafkaUserStatus, nil
}

func (c *Client) CreateKafkaUser(
url string,
kafkaUser *models.KafkaUser,
Expand Down
2 changes: 1 addition & 1 deletion pkg/instaclustr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
ClusterNetworkFirewallRuleEndpoint = "/cluster-management/v2/resources/network-firewall-rules/v2/"
AWSSecurityGroupFirewallRuleEndpoint = "/cluster-management/v2/resources/providers/aws/security-group-firewall-rules/v2/"
GCPPeeringEndpoint = "/cluster-management/v2/resources/providers/gcp/vpc-peers/v2/"
KafkaUserEndpoint = "/cluster-management/v2/resources/applications/kafka/users/v2/"
KafkaUserEndpoint = "/cluster-management/v2/resources/applications/kafka/users/v3/"
KafkauserCertificatesEndpoint = "/cluster-management/v2/resources/applications/kafka/user-certificates/v2/"
KafkaUserCertificatesRenewEndpoint = "/cluster-management/v2/operations/applications/kafka/user-certificates/renew/v2/"
KafkaACLEndpoint = "/cluster-management/v2/resources/applications/kafka/acls/v2/"
Expand Down
1 change: 0 additions & 1 deletion pkg/instaclustr/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type API interface {
GetFirewallRuleStatus(firewallRuleID string, firewallRuleEndpoint string) (*clusterresourcesv1beta1.FirewallRuleStatus, error)
CreateFirewallRule(url string, firewallRuleSpec any) (*clusterresourcesv1beta1.FirewallRuleStatus, error)
DeleteFirewallRule(firewallRuleID string, firewallRuleEndpoint string) error
GetKafkaUserStatus(kafkaUserID, kafkaUserEndpoint string) (*kafkamanagementv1beta1.KafkaUserStatus, error)
CreateKafkaUser(url string, kafkaUser *models.KafkaUser) (*kafkamanagementv1beta1.KafkaUserStatus, error)
UpdateKafkaUser(kafkaUserID string, kafkaUserSpec *models.KafkaUser) error
DeleteKafkaUser(kafkaUserID, kafkaUserEndpoint string) error
Expand Down
12 changes: 7 additions & 5 deletions pkg/models/kafka_user_apv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ limitations under the License.
package models

type KafkaUser struct {
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Options *KafkaUserOptions `json:"options"`
ClusterID string `json:"clusterId"`
InitialPermissions string `json:"initialPermissions"`
Password string `json:"password,omitempty"`
OverrideExistingUser bool `json:"overrideExistingUser,omitempty"`
SASLSCRAMMechanism string `json:"saslScramMechanism,omitempty"`
AuthMechanism string `json:"authMechanism"`
ClusterID string `json:"clusterId"`
InitialPermissions string `json:"initialPermissions"`
Username string `json:"username"`
}

type KafkaUserOptions struct {
Expand Down

0 comments on commit 6cc29e8

Please sign in to comment.