-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeys.go
More file actions
35 lines (29 loc) · 1001 Bytes
/
keys.go
File metadata and controls
35 lines (29 loc) · 1001 Bytes
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
package keysiface
import (
"context"
apikeys "cloud.google.com/go/apikeys/apiv2"
"cloud.google.com/go/apikeys/apiv2/apikeyspb"
"github.com/googleapis/gax-go/v2"
)
type keysImpl struct {
client *apikeys.Client
}
// NewKeys creates an instance of the keys implementation.
func NewKeys(k *apikeys.Client) *keysImpl {
return &keysImpl{
client: k,
}
}
// GetKeyString returns a struct containing the API key string.
func (c *keysImpl) GetKeyString(ctx context.Context, req *apikeyspb.GetKeyStringRequest, opts ...gax.CallOption) (*apikeyspb.GetKeyStringResponse, error) {
return c.client.GetKeyString(ctx, req)
}
// CreateKey returns an API key based on the given request. CreateKey is a blocking request.
func (c *keysImpl) CreateKey(ctx context.Context, req *apikeyspb.CreateKeyRequest, opts ...gax.CallOption) (*apikeyspb.Key, error) {
key, err := c.client.CreateKey(ctx, req)
if err != nil {
return nil, err
}
// Wait for the create operation to complete.
return key.Wait(ctx)
}