Skip to content

Commit

Permalink
chore: remove old GetAPIKeyBySearchingAllEnvironments api
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Yuichi Okimoto <[email protected]>
  • Loading branch information
cre8ivejp committed Dec 12, 2024
1 parent df660fc commit b1d2eb1
Show file tree
Hide file tree
Showing 14 changed files with 1,084 additions and 2,280 deletions.
60 changes: 0 additions & 60 deletions api-description/web-api.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -772,54 +772,6 @@ paths:
type: string
tags:
- API Key
post:
summary: Get Environment API Key
description: Get an environment API Key.
operationId: web.v1.account.get_environment_api_key
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/accountGetAPIKeyBySearchingAllEnvironmentsResponse'
"400":
description: Returned for bad requests that may have failed validation.
schema:
$ref: '#/definitions/rpcStatus'
examples:
application/json:
code: 3
details: []
message: invalid arguments error
"401":
description: Request could not be authenticated (authentication required).
schema:
$ref: '#/definitions/rpcStatus'
examples:
application/json:
code: 16
details: []
message: not authenticated
"503":
description: Returned for internal errors.
schema:
$ref: '#/definitions/rpcStatus'
examples:
application/json:
code: 13
details: []
message: internal
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/rpcStatus'
parameters:
- name: body
in: body
required: true
schema:
$ref: '#/definitions/accountGetAPIKeyBySearchingAllEnvironmentsRequest'
tags:
- API Key
/v1/account/get_me:
post:
summary: Get Me
Expand Down Expand Up @@ -3349,18 +3301,6 @@ definitions:
- UNKNOWN
- FEATURE_FLAG
default: UNKNOWN
accountGetAPIKeyBySearchingAllEnvironmentsRequest:
type: object
properties:
id:
type: string
apiKey:
type: string
accountGetAPIKeyBySearchingAllEnvironmentsResponse:
type: object
properties:
environmentApiKey:
$ref: '#/definitions/accountEnvironmentAPIKey'
accountGetAPIKeyResponse:
type: object
properties:
Expand Down
2 changes: 1 addition & 1 deletion manifests/bucketeer/charts/api/values.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifests/bucketeer/charts/web/values.yaml

Large diffs are not rendered by default.

134 changes: 0 additions & 134 deletions pkg/account/api/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,140 +632,6 @@ func (s *AccountService) newAPIKeyListOrders(
return []*mysql.Order{mysql.NewOrder(column, direction)}, nil
}

func (s *AccountService) GetAPIKeyBySearchingAllEnvironments(
ctx context.Context,
req *proto.GetAPIKeyBySearchingAllEnvironmentsRequest,
) (*proto.GetAPIKeyBySearchingAllEnvironmentsResponse, error) {
localizer := locale.NewLocalizer(ctx)
_, err := s.checkSystemAdminRole(ctx, localizer)
if err != nil {
return nil, err
}

// TODO: support both fields, when migration finished, remove this block
if req.ApiKey == "" {
req.ApiKey = req.Id
}

if req.ApiKey == "" {
dt, err := statusMissingAPIKeyID.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalizeWithTemplate(locale.RequiredFieldTemplate, "api_key_id"),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
}
projects, err := s.listProjects(ctx)
if err != nil {
s.logger.Error(
"Failed to get project list",
log.FieldsFromImcomingContext(ctx).AddFields(zap.Error(err))...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
}
if len(projects) == 0 {
s.logger.Error(
"Could not find any projects",
log.FieldsFromImcomingContext(ctx).AddFields(zap.Error(err))...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
}
environments, err := s.listEnvironments(ctx)
if err != nil {
s.logger.Error(
"Failed to get environment list",
log.FieldsFromImcomingContext(ctx).AddFields(zap.Error(err))...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
}
if len(environments) == 0 {
s.logger.Error(
"Could not find any environments",
log.FieldsFromImcomingContext(ctx).AddFields(zap.Error(err))...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
}
projectSet := s.makeProjectSet(projects)
for _, e := range environments {
p, ok := projectSet[e.ProjectId]
if !ok || p.Disabled {
continue
}
apiKey, err := s.accountStorage.GetAPIKeyByAPIKey(ctx, req.ApiKey, e.Id)
if err != nil {
if errors.Is(err, v2as.ErrAPIKeyNotFound) {
continue
}
s.logger.Error(
"Failed to get api key",
log.FieldsFromImcomingContext(ctx).AddFields(
zap.Error(err),
zap.String("environmentId", e.Id),
)...,
)
dt, err := statusInternal.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.InternalServerError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
}

// for security, obfuscate the returned key
shadowLen := int(float64(len(apiKey.ApiKey)) * apiKeyShadowPercentage)
apiKey.ApiKey = apiKey.ApiKey[shadowLen:]

return &proto.GetAPIKeyBySearchingAllEnvironmentsResponse{
EnvironmentApiKey: &proto.EnvironmentAPIKey{
ApiKey: apiKey.APIKey,
ProjectId: p.Id,
ProjectUrlCode: p.UrlCode,
Environment: e,
},
}, nil
}
dt, err := statusNotFound.WithDetails(&errdetails.LocalizedMessage{
Locale: localizer.GetLocale(),
Message: localizer.MustLocalize(locale.NotFoundError),
})
if err != nil {
return nil, statusInternal.Err()
}
return nil, dt.Err()
}

func (s *AccountService) GetEnvironmentAPIKey(
ctx context.Context,
req *proto.GetEnvironmentAPIKeyRequest,
Expand Down
20 changes: 0 additions & 20 deletions pkg/account/client/mock/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified proto/account/proto_descriptor.pb
Binary file not shown.
Loading

0 comments on commit b1d2eb1

Please sign in to comment.