/
backend.go
63 lines (54 loc) · 1.4 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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package alicloud
import (
"context"
"net/http"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
)
// operationPrefixAliCloud is used as a prefix for OpenAPI operation id's.
const operationPrefixAliCloud = "ali-cloud"
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
client := cleanhttp.DefaultClient()
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
b := newBackend(client)
if err := b.Setup(ctx, conf); err != nil {
return nil, err
}
return b, nil
}
// newBackend exists for testability. It allows us to inject a fake client.
func newBackend(client *http.Client) *backend {
b := &backend{
identityClient: client,
}
b.Backend = &framework.Backend{
AuthRenew: b.pathLoginRenew,
Help: backendHelp,
PathsSpecial: &logical.Paths{
Unauthenticated: []string{
"login",
},
},
Paths: []*framework.Path{
pathLogin(b),
pathListRole(b),
pathListRoles(b),
pathRole(b),
},
BackendType: logical.TypeCredential,
}
return b
}
type backend struct {
*framework.Backend
identityClient *http.Client
}
const backendHelp = `
That AliCloud RAM auth method allows entities to authenticate based on their
identity and pre-configured roles.
`