satellite/console: support reading apikeys by name and project id
When performing re-authorizations for OAuth, we need to pull up an APIKey using it's project id and name. This change also updates the APIKeyInfo struct to return the head value associated with an API key. Change-Id: I4b40f7f13fb9b58a1927dd283b42a39015ea550e
This commit is contained in:
parent
7609bb9515
commit
75be1c0a28
@ -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"`
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user