This repository has been archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.go
61 lines (52 loc) · 1.58 KB
/
operations.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
package main
import (
"fmt"
"code.cloudfoundry.org/credhub-cli/credhub"
)
func ensureNoExistingPermissions(path string, credhub *credhub.CredHub) error {
permissions, err := credhub.GetPermissions(path)
if err == nil && len(permissions) > 0 {
return fmt.Errorf("path '%s' had existing permissions", path)
}
return nil
}
func writeJSONCredential(path string, json map[string]interface{}, credhub *credhub.CredHub) error {
_, err := credhub.SetJSON(path, json)
return err
}
func ensureCredentialExists(path string, credhub *credhub.CredHub) error {
_, err := credhub.GetLatestVersion(fmt.Sprintf("%s", path))
return err
}
func deletePermissions(path string, credhub *credhub.CredHub) error {
permissions, err := credhub.GetPermissions(path)
if err != nil {
return err
}
for _, permission := range permissions {
// FIXME: This is awful
permissionObjectWithUUID, err := credhub.GetPermissionByPathActor(path, permission.Actor)
if err != nil {
return err
}
if _, err = credhub.DeletePermission(permissionObjectWithUUID.UUID); err != nil {
return err
}
}
return nil
}
func deleteCredential(path string, credhub *credhub.CredHub) error {
return credhub.Delete(path)
}
func grantReadAccess(actor, path string, credhub *credhub.CredHub) error {
_, err := credhub.AddPermission(path, actor, []string{"read"})
return err
}
func revokeReadAccess(actor, path string, credhub *credhub.CredHub) error {
existingPermission, err := credhub.GetPermissionByPathActor(path, actor)
if err != nil {
return err
}
_, err = credhub.DeletePermission(existingPermission.UUID)
return err
}