|
5 | 5 | "sort" |
6 | 6 | "text/tabwriter" |
7 | 7 |
|
| 8 | + "github.com/secrethub/secrethub-go/pkg/secretpath" |
| 9 | + |
8 | 10 | "github.com/secrethub/secrethub-cli/internals/cli/ui" |
9 | 11 | "github.com/secrethub/secrethub-cli/internals/secrethub/command" |
10 | 12 |
|
@@ -38,12 +40,7 @@ func (cmd *ACLCheckCommand) Register(r command.Registerer) { |
38 | 40 |
|
39 | 41 | // Run prints the access level(s) on the given directory. |
40 | 42 | func (cmd *ACLCheckCommand) Run() error { |
41 | | - client, err := cmd.newClient() |
42 | | - if err != nil { |
43 | | - return err |
44 | | - } |
45 | | - |
46 | | - levels, err := client.AccessRules().ListLevels(cmd.path.Value()) |
| 43 | + levels, err := cmd.listLevels() |
47 | 44 | if err != nil { |
48 | 45 | return err |
49 | 46 | } |
@@ -79,3 +76,33 @@ func (cmd *ACLCheckCommand) Run() error { |
79 | 76 |
|
80 | 77 | return nil |
81 | 78 | } |
| 79 | + |
| 80 | +func (cmd *ACLCheckCommand) listLevels() ([]*api.AccessLevel, error) { |
| 81 | + client, err := cmd.newClient() |
| 82 | + if err != nil { |
| 83 | + return nil, err |
| 84 | + } |
| 85 | + |
| 86 | + path := cmd.path.Value() |
| 87 | + |
| 88 | + levels, listLevelsErr := client.AccessRules().ListLevels(path) |
| 89 | + if listLevelsErr == nil { |
| 90 | + return levels, nil |
| 91 | + } |
| 92 | + if !api.IsErrNotFound(listLevelsErr) { |
| 93 | + return nil, listLevelsErr |
| 94 | + } |
| 95 | + |
| 96 | + isSecret, isSecretErr := client.Secrets().Exists(path) |
| 97 | + if isSecretErr != nil { |
| 98 | + return nil, listLevelsErr |
| 99 | + } |
| 100 | + if isSecret { |
| 101 | + levels, err = client.AccessRules().ListLevels(secretpath.Parent(path)) |
| 102 | + if err != nil { |
| 103 | + return nil, err |
| 104 | + } |
| 105 | + return levels, nil |
| 106 | + } |
| 107 | + return nil, listLevelsErr |
| 108 | +} |
0 commit comments