forked from ilijamt/vault-plugin-secrets-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry_role.go
More file actions
47 lines (41 loc) · 1.41 KB
/
entry_role.go
File metadata and controls
47 lines (41 loc) · 1.41 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
package gitlab
import (
"context"
"fmt"
"github.com/hashicorp/vault/sdk/logical"
"time"
)
type entryRole struct {
RoleName string `json:"role_name" structs:"role_name" mapstructure:"role_name"`
TokenTTL time.Duration `json:"token_ttl" structs:"token_ttl" mapstructure:"token_ttl"`
Path string `json:"path" structs:"path" mapstructure:"path"`
Name string `json:"name" structs:"name" mapstructure:"name"`
Scopes []string `json:"scopes" structs:"scopes" mapstructure:"scopes"`
AccessLevel AccessLevel `json:"access_level" structs:"access_level" mapstructure:"access_level,omitempty"`
TokenType TokenType `json:"token_type" structs:"token_type" mapstructure:"token_type"`
}
func (e entryRole) LogicalResponseData() map[string]interface{} {
return map[string]interface{}{
"role_name": e.RoleName,
"path": e.Path,
"name": e.Name,
"scopes": e.Scopes,
"access_level": e.AccessLevel.String(),
"token_ttl": int64(e.TokenTTL / time.Second),
"token_type": e.TokenType.String(),
}
}
func getRole(ctx context.Context, name string, s logical.Storage) (*entryRole, error) {
entry, err := s.Get(ctx, fmt.Sprintf("%s/%s", PathRoleStorage, name))
if err != nil {
return nil, err
}
if entry == nil {
return nil, nil
}
role := new(entryRole)
if err := entry.DecodeJSON(role); err != nil {
return nil, err
}
return role, nil
}