-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsecret_token.go
More file actions
executable file
·77 lines (66 loc) · 1.93 KB
/
secret_token.go
File metadata and controls
executable file
·77 lines (66 loc) · 1.93 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
76
77
package openstack
import (
"context"
"errors"
"fmt"
"github.com/gophercloud/gophercloud/v2/openstack/identity/v3/applicationcredentials"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
)
const (
SecretTokenType = "token"
)
func secretToken(b *backend) *framework.Secret {
return &framework.Secret{
Type: SecretTokenType,
Fields: map[string]*framework.FieldSchema{
"token": {
Type: framework.TypeString,
Description: "Application credential token",
},
},
Revoke: b.secretTokenRevoke,
}
}
func (b *backend) secretTokenRevoke(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
// Get the roleset name from the lease
rolesetRaw, ok := req.Secret.InternalData["roleset"]
if !ok {
return nil, errors.New("roleset is missing on the lease")
}
rolesetName, ok := rolesetRaw.(string)
if !ok {
return nil, errors.New("unable to convert roleset name")
}
// Load the roleset
role, err := b.Role(ctx, req.Storage, rolesetName)
if err != nil {
return nil, fmt.Errorf("error retrieving roleset: %w", err)
}
if role == nil {
return nil, fmt.Errorf("roleset %q not found", rolesetName)
}
cfg, err := b.readConfigAccess(ctx, req.Storage)
if err != nil {
return nil, fmt.Errorf("error reading access config: %w", err)
}
if cfg == nil {
return nil, errors.New("access config not found")
}
identityClient, err := client(ctx, cfg, role)
if err != nil {
return nil, fmt.Errorf("error creating identity client: %w", err)
}
IDRaw, ok := req.Secret.InternalData["application_credential_id"]
if !ok {
return nil, fmt.Errorf("application_credential_id is missing on the lease")
}
id, ok := IDRaw.(string)
if !ok {
return nil, errors.New("unable to convert application_credential_id")
}
if err := applicationcredentials.Delete(ctx, identityClient, cfg.UserID, id).ExtractErr(); err != nil {
return nil, err
}
return nil, nil
}