MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / NewAPIKey

Function NewAPIKey

model/api_key.go:32–47  ·  view source on GitHub ↗

NewAPIKey creates a new API key instance

(name, ownerID string, scopes []string, expiresAt time.Time)

Source from the content-addressed store, hash-verified

30
31// NewAPIKey creates a new API key instance
32func NewAPIKey(name, ownerID string, scopes []string, expiresAt time.Time) (*APIKey, error) {
33 key, err := GenerateKey()
34 if err != nil {
35 return nil, err
36 }
37
38 return &APIKey{
39 APIKeyID: GenerateUUIDWithSuffix("api_key"),
40 Key: key,
41 Name: name,
42 OwnerID: ownerID,
43 Scopes: scopes,
44 ExpiresAt: expiresAt,
45 CreatedAt: time.Now(),
46 }, nil
47}
48
49// IsValid checks if the API key is valid
50func (k *APIKey) IsValid() bool {

Callers 2

CreateAPIKeyMethod · 0.92
TestNewAPIKeyFunction · 0.85

Calls 2

GenerateKeyFunction · 0.85
GenerateUUIDWithSuffixFunction · 0.85

Tested by 1

TestNewAPIKeyFunction · 0.68