-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from dfds/feature/2226-make-sure-old-capabilit…
…ies-have-access-to-schema-registry copy pasted schema registry access into schema registration process
- Loading branch information
Showing
8 changed files
with
367 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package schema | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/dfds/confluent-gateway/internal/models" | ||
) | ||
|
||
type accountService struct { | ||
context context.Context | ||
confluent Confluent | ||
repo serviceAccountRepository | ||
} | ||
|
||
type serviceAccountRepository interface { | ||
GetServiceAccount(capabilityId models.CapabilityId) (*models.ServiceAccount, error) | ||
} | ||
|
||
func NewSchemaAccountService(ctx context.Context, confluent Confluent, repo serviceAccountRepository) *accountService { | ||
return &accountService{ | ||
context: ctx, | ||
confluent: confluent, | ||
repo: repo, | ||
} | ||
} | ||
|
||
func (h *accountService) GetServiceAccount(capabilityId models.CapabilityId) (*models.ServiceAccount, error) { | ||
return h.repo.GetServiceAccount(capabilityId) | ||
} | ||
|
||
func (h *accountService) DeleteSchemaRegistryApiKey(clusterAccess *models.ClusterAccess) error { | ||
return h.confluent.DeleteSchemaRegistryApiKey(h.context, clusterAccess.ClusterId, clusterAccess.ServiceAccountId) | ||
} | ||
|
||
func (h *accountService) GetClusterAccess(capabilityId models.CapabilityId, clusterId models.ClusterId) (*models.ClusterAccess, error) { | ||
serviceAccount, err := h.repo.GetServiceAccount(capabilityId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if serviceAccount == nil { | ||
return nil, fmt.Errorf("no service account for capability '%s' found", capabilityId) | ||
} | ||
|
||
clusterAccess, hasClusterAccess := serviceAccount.TryGetClusterAccess(clusterId) | ||
|
||
if !hasClusterAccess { | ||
return nil, fmt.Errorf("no cluster access for service account '%s' found", serviceAccount.Id) | ||
} | ||
return clusterAccess, nil | ||
} | ||
|
||
func (h *accountService) CountSchemaRegistryApiKeys(clusterAccess *models.ClusterAccess) (int, error) { | ||
keyCount, err := h.confluent.CountSchemaRegistryApiKeys(h.context, clusterAccess.ServiceAccountId, clusterAccess.ClusterId) | ||
if err != nil { | ||
return 0, err | ||
} | ||
return keyCount, nil | ||
} | ||
|
||
func (h *accountService) CreateSchemaRegistryApiKey(clusterAccess *models.ClusterAccess) (models.ApiKey, error) { | ||
return h.confluent.CreateSchemaRegistryApiKey(h.context, clusterAccess.ClusterId, clusterAccess.ServiceAccountId) | ||
|
||
} | ||
|
||
func (h *accountService) CreateServiceAccountRoleBinding(clusterAccess *models.ClusterAccess) error { | ||
err := h.confluent.CreateServiceAccountRoleBinding(h.context, clusterAccess.ServiceAccountId, clusterAccess.ClusterId) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package schema | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/dfds/confluent-gateway/internal/models" | ||
) | ||
|
||
type Confluent interface { | ||
CreateServiceAccount(ctx context.Context, name string, description string) (models.ServiceAccountId, error) | ||
CreateSchemaRegistryApiKey(ctx context.Context, clusterId models.ClusterId, serviceAccountId models.ServiceAccountId) (models.ApiKey, error) | ||
CreateServiceAccountRoleBinding(ctx context.Context, serviceAccount models.ServiceAccountId, clusterId models.ClusterId) error | ||
CountSchemaRegistryApiKeys(ctx context.Context, clusterAccess models.ServiceAccountId, clusterId models.ClusterId) (int, error) | ||
DeleteSchemaRegistryApiKey(ctx context.Context, clusterId models.ClusterId, serviceAccountId models.ServiceAccountId) error | ||
RegisterSchema(ctx context.Context, clusterId models.ClusterId, subject string, schema string) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.