-
Notifications
You must be signed in to change notification settings - Fork 8
/
secrets.go
94 lines (75 loc) · 2.41 KB
/
secrets.go
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Code generated by op-codegen - DO NOT EDIT
package onepassword
import (
"context"
"encoding/json"
"github.com/1password/onepassword-sdk-go/internal"
)
// The Secrets API includes all operations the SDK client can perform on secrets.
// Use secret reference URIs to securely load secrets from 1Password: op://<vault-name>/<item-name>[/<section-name>]/<field-name>
type SecretsAPI interface {
// Resolve returns the secret the provided secret reference points to.
Resolve(ctx context.Context, secretReference string) (string, error)
}
type SecretsSource struct {
internal.InnerClient
}
func NewSecretsSource(inner internal.InnerClient) *SecretsSource {
return &SecretsSource{inner}
}
type secretsUtil struct{}
var Secrets = secretsUtil{}
// Resolve returns the secret the provided secret reference points to.
func (s SecretsSource) Resolve(ctx context.Context, secretReference string) (string, error) {
resultString, err := clientInvoke(ctx, s.InnerClient, "SecretsResolve", map[string]interface{}{
"secret_reference": secretReference,
})
if err != nil {
return "", err
}
var result string
err = json.Unmarshal([]byte(*resultString), &result)
if err != nil {
return "", err
}
return result, nil
}
// Validate the secret reference to ensure there are no syntax errors.
func (s secretsUtil) ValidateSecretReference(ctx context.Context, secretReference string) error {
core, err := internal.GetSharedCore()
if err != nil {
return err
}
_, err = core.Invoke(ctx, internal.InvokeConfig{
Invocation: internal.Invocation{
Parameters: internal.Parameters{
MethodName: "ValidateSecretReference",
SerializedParams: map[string]interface{}{"secret_reference": secretReference},
},
},
})
return err
}
func (s secretsUtil) GeneratePassword(ctx context.Context, recipe PasswordRecipe) (GeneratePasswordResponse, error) {
core, err := internal.GetSharedCore()
if err != nil {
return GeneratePasswordResponse{}, err
}
resultString, err := core.Invoke(ctx, internal.InvokeConfig{
Invocation: internal.Invocation{
Parameters: internal.Parameters{
MethodName: "GeneratePassword",
SerializedParams: map[string]interface{}{"recipe": recipe},
},
},
})
if err != nil {
return GeneratePasswordResponse{}, err
}
var result GeneratePasswordResponse
err = json.Unmarshal([]byte(*resultString), &result)
if err != nil {
return GeneratePasswordResponse{}, err
}
return result, nil
}