-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
68 lines (53 loc) · 1.03 KB
/
path.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
package secfs
import (
"path"
"strings"
"syscall"
"github.com/postfinance/secfs/internal/backend"
)
type secretPath struct {
namespace string
secret string
key string
isDir bool
}
// newSecretPath returns the secretPath for name
func newSecretPath(name string) (*secretPath, error) {
parts := strings.Split(strings.Trim(name, "/"), "/")
if len(parts) < 2 || len(parts) > 3 {
return nil, syscall.EINVAL
}
p := &secretPath{
namespace: parts[0],
secret: parts[1],
}
switch len(parts) {
case 2:
p.isDir = true
case 3:
p.key = parts[2]
}
return p, nil
}
func (p secretPath) Name() string {
if p.key != "" {
return p.key
}
return p.secret
}
func (p secretPath) Absolute() string {
return path.Join(p.namespace, p.secret, p.key)
}
func (p secretPath) IsDir() bool {
return p.isDir
}
var _ backend.Metadata = secretPath{}
func (p secretPath) Namespace() string {
return p.namespace
}
func (p secretPath) Secret() string {
return p.secret
}
func (p secretPath) Key() string {
return p.key
}