-
Notifications
You must be signed in to change notification settings - Fork 1
/
secret_access_token.go
44 lines (35 loc) · 1.22 KB
/
secret_access_token.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
package artifactory
import (
"context"
"fmt"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
rtTokenService "github.com/jsok/vault-plugin-secrets-artifactory/pkg/token"
)
const accessTokenSecretType = "artifactory_access_token"
func secretAccessToken(b *backend) *framework.Secret {
return &framework.Secret{
Type: accessTokenSecretType,
Fields: map[string]*framework.FieldSchema{
"access_token": {
Type: framework.TypeString,
Description: "Artifactory Access Token",
},
},
Revoke: b.secretAccessTokenRevoke,
}
}
func (b *backend) secretAccessTokenRevoke(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
accessToken := d.Get("access_token").(string)
client, rtDetails, err := b.rtClient(ctx, req.Storage)
if client == nil || rtDetails == nil {
return nil, fmt.Errorf("Failed to create Artifactory client: %v\n", err)
}
tokenService := rtTokenService.NewAccessTokenService(client)
tokenService.SetArtifactoryDetails(rtDetails)
err = tokenService.RevokeToken(&rtTokenService.RevokeTokenRequest{Token: accessToken})
if err != nil {
return nil, fmt.Errorf("Failed to revoke token:\n%v\n", err)
}
return nil, nil
}