Repository navigation
Expand file tree
/
Copy pathapikey.go
More file actions
75 lines (68 loc) · 2.1 KB
/
Copy pathapikey.go
File metadata and controls
75 lines (68 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package blnk
import (
"context"
"time"
"github.com/blnkfinance/blnk/model"
)
// CreateAPIKey creates a new API key for the specified owner
//
// Parameters:
// - ctx: The context for the operation
// - name: Name of the API key
// - ownerID: ID of the key owner
// - scopes: List of permission scopes
// - expiresAt: Expiration time for the key
//
// Returns:
// - *model.APIKey: The created API key
// - error: An error if the operation fails
func (l *Blnk) CreateAPIKey(ctx context.Context, name, ownerID string, scopes []string, expiresAt time.Time) (*model.APIKey, error) {
return l.datasource.CreateAPIKey(ctx, name, ownerID, scopes, expiresAt)
}
// ListAPIKeys retrieves all API keys for a specific owner
//
// Parameters:
// - ctx: The context for the operation
// - ownerID: ID of the key owner
//
// Returns:
// - []*model.APIKey: List of API keys
// - error: An error if the operation fails
func (l *Blnk) ListAPIKeys(ctx context.Context, ownerID string) ([]*model.APIKey, error) {
return l.datasource.ListAPIKeys(ctx, ownerID)
}
// RevokeAPIKey revokes an API key if it belongs to the specified owner
//
// Parameters:
// - ctx: The context for the operation
// - id: ID of the API key to revoke
// - ownerID: ID of the key owner
//
// Returns:
// - error: An error if the operation fails
func (l *Blnk) RevokeAPIKey(ctx context.Context, id, ownerID string) error {
return l.datasource.RevokeAPIKey(ctx, id, ownerID)
}
// GetAPIKeyByKey retrieves an API key by its key string
//
// Parameters:
// - ctx: The context for the operation
// - key: The API key string
//
// Returns:
// - *model.APIKey: The API key if found
// - error: An error if the operation fails
func (l *Blnk) GetAPIKeyByKey(ctx context.Context, key string) (*model.APIKey, error) {
return l.datasource.GetAPIKey(ctx, key)
}
// UpdateLastUsed updates the last used timestamp of an API key
//
// Parameters:
// - ctx: The context for the operation
// - id: ID of the API key to update
//
// Returns:
// - error: An error if the operation fails
func (l *Blnk) UpdateLastUsed(ctx context.Context, id string) error {
return l.datasource.UpdateLastUsed(ctx, id)
}