-
Notifications
You must be signed in to change notification settings - Fork 1
/
backend.go
72 lines (59 loc) · 1.54 KB
/
backend.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
package artifactory
import (
"context"
"fmt"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
rtAuth "github.com/jfrog/jfrog-client-go/artifactory/auth"
rtHttpClient "github.com/jfrog/jfrog-client-go/artifactory/httpclient"
)
type backend struct {
*framework.Backend
}
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
b := Backend()
if err := b.Setup(ctx, conf); err != nil {
return nil, err
}
return b, nil
}
func Backend() *backend {
var b backend
b.Backend = &framework.Backend{
PathsSpecial: &logical.Paths{
SealWrapStorage: []string{
"config",
},
},
Paths: []*framework.Path{
pathConfig(&b),
pathListRoles(&b),
pathRoles(&b),
pathToken(&b),
},
Secrets: []*framework.Secret{
secretAccessToken(&b),
},
BackendType: logical.TypeLogical,
}
return &b
}
func (b *backend) rtClient(ctx context.Context, s logical.Storage) (*rtHttpClient.ArtifactoryHttpClient, rtAuth.ArtifactoryDetails, error) {
config, err := b.readConfig(ctx, s)
if err != nil {
return nil, nil, err
}
rtDetails := rtAuth.NewArtifactoryDetails()
rtDetails.SetUrl(config.Address)
rtDetails.SetApiKey(config.ApiKey)
rtDetails.SetUser(config.Username)
rtDetails.SetPassword(config.Password)
client, err := rtHttpClient.ArtifactoryClientBuilder().
SetInsecureTls(!config.TlsVerify).
SetArtDetails(&rtDetails).
Build()
if err != nil {
return nil, nil, fmt.Errorf("Failed to create Artifactory client: %v\n", err)
}
return client, rtDetails, nil
}