Skip to content

Commit

Permalink
Minor code style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
christeredvartsen committed Oct 16, 2024
1 parent 94400a2 commit 3eb6877
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
13 changes: 4 additions & 9 deletions internal/v1/workload/secret/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ func (s *Secret) GetObjectKind() schema.ObjectKind {
}

func toGraphSecret(o *unstructured.Unstructured, environmentName string) (*Secret, bool) {
managedByConsole := secretIsManagedByConsole(o)
if !managedByConsole {
if !secretIsManagedByConsole(o) {
return nil, false
}

Expand Down Expand Up @@ -129,15 +128,11 @@ type SecretVariable struct {
}

type DeleteSecretInput struct {
// The name of the secret.
Name string `json:"name"`
// The environment the secret is deployed to.
Environment string `json:"environment"`
// The team that owns the secret.
Team slug.Slug `json:"team"`
Name string `json:"name"`
Environment string `json:"environment"`
Team slug.Slug `json:"team"`
}

type DeleteSecretPayload struct {
// The deleted secret.
SecretDeleted bool `json:"secretDeleted"`
}
30 changes: 10 additions & 20 deletions internal/v1/workload/secret/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ var ErrSecretUnmanaged = errors.New("secret is not managed by console")

func ListForTeam(ctx context.Context, teamSlug slug.Slug, page *pagination.Pagination) (*SecretConnection, error) {
all := fromContext(ctx).secretWatcher.GetByNamespace(teamSlug.String())

secrets := pagination.Slice(watcher.Objects(all), page)

return pagination.NewConnection(secrets, page, int32(len(all))), nil
}

Expand Down Expand Up @@ -83,13 +81,12 @@ func GetSecretData(ctx context.Context, teamSlug slug.Slug, environmentName, nam
}

func Delete(ctx context.Context, teamSlug slug.Slug, environment, name string) (bool, error) {
_, err := fromContext(ctx).secretWatcher.Get(environment, teamSlug.String(), name)
if err != nil {
sw := fromContext(ctx).secretWatcher
if _, err := sw.Get(environment, teamSlug.String(), name); err != nil {
return false, err
}

err = fromContext(ctx).secretWatcher.Delete(ctx, environment, teamSlug.String(), name)
if err != nil {
if err := sw.Delete(ctx, environment, teamSlug.String(), name); err != nil {
return false, err
}

Expand All @@ -102,8 +99,7 @@ func Update(ctx context.Context, teamSlug slug.Slug, environment, name string, d
return nil, err
}

err = validateSecretData(data)
if err != nil {
if err := validateSecretData(data); err != nil {
return nil, err
}

Expand All @@ -113,13 +109,11 @@ func Update(ctx context.Context, teamSlug slug.Slug, environment, name string, d
}

existingSecret := &corev1.Secret{}
err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &existingSecret)
if err != nil {
if err = runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, &existingSecret); err != nil {
return nil, err
}

secretIsManaged := secretIsManagedByConsole(obj)
if !secretIsManaged {
if !secretIsManagedByConsole(obj) {
return nil, fmt.Errorf("%q: %w", name, ErrSecretUnmanaged)
}

Expand Down Expand Up @@ -152,13 +146,11 @@ func Create(ctx context.Context, teamSlug slug.Slug, environment, name string, d
return nil, err
}

nameErrs := validation.IsDNS1123Subdomain(name)
if len(nameErrs) > 0 {
if nameErrs := validation.IsDNS1123Subdomain(name); len(nameErrs) > 0 {
return nil, fmt.Errorf("invalid name %q: %s", name, strings.Join(nameErrs, ", "))
}

err = validateSecretData(data)
if err != nil {
if err = validateSecretData(data); err != nil {
return nil, err
}

Expand Down Expand Up @@ -233,8 +225,7 @@ func validateSecretData(data []*SecretVariableInput) error {
seen := make(map[string]bool)

for _, d := range data {
_, found := seen[d.Name]
if found {
if _, found := seen[d.Name]; found {
return fmt.Errorf("duplicate key: %q", d.Name)
}

Expand All @@ -244,8 +235,7 @@ func validateSecretData(data []*SecretVariableInput) error {
return fmt.Errorf("%q is too long: %d characters, max %d", d.Name, len(d.Name), validation.DNS1123SubdomainMaxLength)
}

isEnvVarName := validation.IsEnvVarName(d.Name)
if len(isEnvVarName) > 0 {
if isEnvVarName := validation.IsEnvVarName(d.Name); len(isEnvVarName) > 0 {
return fmt.Errorf("%q: %s", d.Name, strings.Join(isEnvVarName, ", "))
}
}
Expand Down

0 comments on commit 3eb6877

Please sign in to comment.