From 6cc29e8e19bcaf5d25e452008328d616b6336668 Mon Sep 17 00:00:00 2001 From: tengu-alt Date: Mon, 2 Oct 2023 16:44:17 +0300 Subject: [PATCH] kafkauser endpoints were migrated to APIv3 --- .../v1beta1/kafkauser_types.go | 13 ++++--- ...management.instaclustr.com_kafkausers.yaml | 3 ++ .../kafkamanagement_v1beta1_kafkauser.yaml | 5 +-- pkg/instaclustr/client.go | 34 ------------------- pkg/instaclustr/config.go | 2 +- pkg/instaclustr/interfaces.go | 1 - pkg/models/kafka_user_apv2.go | 12 ++++--- 7 files changed, 22 insertions(+), 48 deletions(-) diff --git a/apis/kafkamanagement/v1beta1/kafkauser_types.go b/apis/kafkamanagement/v1beta1/kafkauser_types.go index ea7979c17..572247521 100644 --- a/apis/kafkamanagement/v1beta1/kafkauser_types.go +++ b/apis/kafkamanagement/v1beta1/kafkauser_types.go @@ -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 @@ -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, } } diff --git a/config/crd/bases/kafkamanagement.instaclustr.com_kafkausers.yaml b/config/crd/bases/kafkamanagement.instaclustr.com_kafkausers.yaml index fac3c07b5..c95013f77 100644 --- a/config/crd/bases/kafkamanagement.instaclustr.com_kafkausers.yaml +++ b/config/crd/bases/kafkamanagement.instaclustr.com_kafkausers.yaml @@ -70,11 +70,14 @@ spec: type: string options: properties: + authMechanism: + type: string overrideExistingUser: type: boolean saslScramMechanism: type: string required: + - authMechanism - saslScramMechanism type: object secretRef: diff --git a/config/samples/kafkamanagement_v1beta1_kafkauser.yaml b/config/samples/kafkamanagement_v1beta1_kafkauser.yaml index 8fc250079..7187288e3 100644 --- a/config/samples/kafkamanagement_v1beta1_kafkauser.yaml +++ b/config/samples/kafkamanagement_v1beta1_kafkauser.yaml @@ -4,7 +4,7 @@ metadata: name: secret-test data: username: "U2FuY2gtdHdvCg==" - password: "Qm9oZGFuXyF1YmVyX3VudGVyX3ZhZmVsb2sxNDg4X2lnb3JfdG9saWsxNDg4Cg==" + password: "Qm9oZGFuX3ViZXJfdW50ZXJfaWdvcl90b2xpazEK" --- apiVersion: kafkamanagement.instaclustr.com/v1beta1 kind: KafkaUser @@ -36,4 +36,5 @@ spec: initialPermissions: "standard" options: overrideExistingUser: true - saslScramMechanism: "SCRAM-SHA-256" \ No newline at end of file + saslScramMechanism: "SCRAM-SHA-256" + authMechanism: "SASL" \ No newline at end of file diff --git a/pkg/instaclustr/client.go b/pkg/instaclustr/client.go index 4df1a7e2a..f95cb1421 100644 --- a/pkg/instaclustr/client.go +++ b/pkg/instaclustr/client.go @@ -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, diff --git a/pkg/instaclustr/config.go b/pkg/instaclustr/config.go index f814da91e..8bd94f499 100644 --- a/pkg/instaclustr/config.go +++ b/pkg/instaclustr/config.go @@ -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/" diff --git a/pkg/instaclustr/interfaces.go b/pkg/instaclustr/interfaces.go index ad65e0764..710943a03 100644 --- a/pkg/instaclustr/interfaces.go +++ b/pkg/instaclustr/interfaces.go @@ -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 diff --git a/pkg/models/kafka_user_apv2.go b/pkg/models/kafka_user_apv2.go index 97d556123..3324dcda0 100644 --- a/pkg/models/kafka_user_apv2.go +++ b/pkg/models/kafka_user_apv2.go @@ -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 {