MCPcopy Index your code
hub / github.com/apache/answer / AddAPIKey

Method AddAPIKey

internal/service/apikey/apikey_service.go:91–108  ·  view source on GitHub ↗
(ctx context.Context, req *schema.AddAPIKeyReq)

Source from the content-addressed store, hash-verified

89}
90
91func (s *APIKeyService) AddAPIKey(ctx context.Context, req *schema.AddAPIKeyReq) (resp *schema.AddAPIKeyResp, err error) {
92 ak := "sk_" + strings.ReplaceAll(token.GenerateToken(), "-", "")
93 apiKey := entity.APIKey{
94 Description: req.Description,
95 AccessKey: ak,
96 Scope: req.Scope,
97 LastUsedAt: time.Now(),
98 UserID: req.UserID,
99 }
100 err = s.apiKeyRepo.AddAPIKey(ctx, apiKey)
101 if err != nil {
102 return nil, err
103 }
104 resp = &schema.AddAPIKeyResp{
105 AccessKey: apiKey.AccessKey,
106 }
107 return resp, nil
108}
109
110func (s *APIKeyService) DeleteAPIKey(ctx context.Context, req *schema.DeleteAPIKeyReq) (err error) {
111 err = s.apiKeyRepo.DeleteAPIKey(ctx, req.ID)

Callers

nothing calls this directly

Calls 2

GenerateTokenFunction · 0.92
AddAPIKeyMethod · 0.65

Tested by

no test coverage detected