diff --git a/satellite/console/apikeys.go b/satellite/console/apikeys.go index eca81a529..790c6d343 100644 --- a/satellite/console/apikeys.go +++ b/satellite/console/apikeys.go @@ -37,6 +37,7 @@ type APIKeyInfo struct { PartnerID uuid.UUID `json:"partnerId"` UserAgent []byte `json:"userAgent"` Name string `json:"name"` + Head []byte `json:"-"` Secret []byte `json:"-"` CreatedAt time.Time `json:"createdAt"` } diff --git a/satellite/console/service.go b/satellite/console/service.go index 32a580ea7..fcc1c2322 100644 --- a/satellite/console/service.go +++ b/satellite/console/service.go @@ -1487,6 +1487,31 @@ func (s *Service) CreateAPIKey(ctx context.Context, projectID uuid.UUID, name st return info, key, nil } +// GetAPIKeyInfoByName retrieves an api key by its name and project id. +func (s *Service) GetAPIKeyInfoByName(ctx context.Context, projectID uuid.UUID, name string) (_ *APIKeyInfo, err error) { + defer mon.Task()(&ctx)(&err) + + auth, err := s.getAuthAndAuditLog(ctx, "get api key info", + zap.String("projectID", projectID.String()), + zap.String("name", name)) + + if err != nil { + return nil, err + } + + key, err := s.store.APIKeys().GetByNameAndProjectID(ctx, name, projectID) + if err != nil { + return nil, Error.Wrap(err) + } + + _, err = s.isProjectMember(ctx, auth.User.ID, key.ProjectID) + if err != nil { + return nil, Error.Wrap(err) + } + + return key, nil +} + // GetAPIKeyInfo retrieves api key by id. func (s *Service) GetAPIKeyInfo(ctx context.Context, id uuid.UUID) (_ *APIKeyInfo, err error) { defer mon.Task()(&ctx)(&err) diff --git a/satellite/satellitedb/apikeys.go b/satellite/satellitedb/apikeys.go index e7164f8ee..4ab1f8288 100644 --- a/satellite/satellitedb/apikeys.go +++ b/satellite/satellitedb/apikeys.go @@ -234,6 +234,7 @@ func fromDBXAPIKey(ctx context.Context, key *dbx.ApiKey) (_ *console.APIKeyInfo, ProjectID: projectID, Name: key.Name, CreatedAt: key.CreatedAt, + Head: key.Head, Secret: key.Secret, }