Skip to content

Commit

Permalink
chore: use api group
Browse files Browse the repository at this point in the history
  • Loading branch information
wtrocki committed Jul 28, 2021
1 parent 605112a commit 060c489
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type API struct {
Kafka func() kafkamgmtclient.DefaultApi
ServiceAccount func() kafkamgmtclient.SecurityApi
KafkaAdmin func(kafkaID string) (kafkainstanceclient.TopicsApi, kafkainstanceclient.GroupsApi, *kafkamgmtclient.KafkaRequest, error)
KafkaAdmin func(kafkaID string) (*kafkainstanceclient.APIClient, *kafkamgmtclient.KafkaRequest, error)
AccountMgmt func() amsclient.DefaultApi

ServiceRegistryMgmt func() srsmgmtclient.RegistriesApi
Expand Down
24 changes: 12 additions & 12 deletions pkg/connection/keycloak_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,45 +179,45 @@ func (c *KeycloakConnection) API() *api.API {
return srsAPIClient.RegistriesApi
}

kafkaAdminAPIFunc := func(kafkaID string) (kafkainstanceclient.TopicsApi, kafkainstanceclient.GroupsApi, *kafkamgmtclient.KafkaRequest, error) {
kafkaAdminAPIFunc := func(kafkaID string) (*kafkainstanceclient.APIClient, *kafkamgmtclient.KafkaRequest, error) {
api := kafkaAPIFunc()

kafkaInstance, resp, err := api.GetKafkaById(context.Background(), kafkaID).Execute()
defer resp.Body.Close()
if kas.IsErr(err, kas.ErrorNotFound) {
return nil, nil, nil, kafkaerr.NotFoundByIDError(kafkaID)
return nil, nil, kafkaerr.NotFoundByIDError(kafkaID)
} else if err != nil {
return nil, nil, nil, fmt.Errorf("%w", err)
return nil, nil, fmt.Errorf("%w", err)
}

kafkaStatus := kafkaInstance.GetStatus()

switch kafkaStatus {
case "provisioning", "accepted":
err = fmt.Errorf(`Kafka instance "%v" is not ready yet`, kafkaInstance.GetName())
return nil, nil, nil, err
return nil, nil, err
case "failed":
err = fmt.Errorf(`Kafka instance "%v" has failed`, kafkaInstance.GetName())
return nil, nil, nil, err
return nil, nil, err
case "deprovision":
err = fmt.Errorf(`Kafka instance "%v" is being deprovisioned`, kafkaInstance.GetName())
return nil, nil, nil, err
return nil, nil, err
case "deleting":
err = fmt.Errorf(`Kafka instance "%v" is being deleted`, kafkaInstance.GetName())
return nil, nil, nil, err
return nil, nil, err
}

bootstrapURL := kafkaInstance.GetBootstrapServerHost()
if bootstrapURL == "" {
err = fmt.Errorf(`bootstrap URL is missing for Kafka instance "%v"`, kafkaInstance.GetName())

return nil, nil, nil, err
return nil, nil, err
}

// create the client
topics, groups := c.createKafkaAdminAPI(bootstrapURL)
client := c.createKafkaAdminAPI(bootstrapURL)

return *topics, *groups, &kafkaInstance, nil
return client, &kafkaInstance, nil
}

return &api.API{
Expand Down Expand Up @@ -254,7 +254,7 @@ func (c *KeycloakConnection) createServiceRegistryAPIClient() *registrymgmtclien
}

// Create a new KafkaAdmin API client
func (c *KeycloakConnection) createKafkaAdminAPI(bootstrapURL string) (*kafkainstanceclient.TopicsApi, *kafkainstanceclient.GroupsApi) {
func (c *KeycloakConnection) createKafkaAdminAPI(bootstrapURL string) *kafkainstanceclient.APIClient {
host, port, _ := net.SplitHostPort(bootstrapURL)

var apiURL *url.URL
Expand Down Expand Up @@ -282,7 +282,7 @@ func (c *KeycloakConnection) createKafkaAdminAPI(bootstrapURL string) (*kafkains
HTTPClient: c.createOAuthTransport(c.MASToken.AccessToken),
})

return &client.TopicsApi, &client.GroupsApi
return client
}

func (c *KeycloakConnection) createAmsAPIClient() *amsclient.APIClient {
Expand Down

0 comments on commit 060c489

Please sign in to comment.