@@ -40,29 +40,11 @@ func (cmd *ACLCheckCommand) Register(r command.Registerer) {
4040
4141// Run prints the access level(s) on the given directory.
4242func (cmd * ACLCheckCommand ) Run () error {
43- client , err := cmd .newClient ()
43+ levels , err := cmd .listLevels ()
4444 if err != nil {
4545 return err
4646 }
4747
48- path := cmd .path .Value ()
49-
50- levels , err := client .AccessRules ().ListLevels (path )
51- if api .IsErrNotFound (err ) {
52- isSecret , err := client .Secrets ().Exists (path )
53- if err != nil {
54- return err
55- }
56- if isSecret {
57- levels , err = client .AccessRules ().ListLevels (secretpath .Parent (path ))
58- if err != nil {
59- return err
60- }
61- }
62- } else if err != nil {
63- return err
64- }
65-
6648 if cmd .accountName != "" {
6749 for _ , level := range levels {
6850 if level .Account .Name == cmd .accountName {
@@ -94,3 +76,31 @@ func (cmd *ACLCheckCommand) Run() error {
9476
9577 return nil
9678}
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 , err := client .AccessRules ().ListLevels (path )
89+ if api .IsErrNotFound (err ) {
90+ isSecret , isSecretErr := client .Secrets ().Exists (path )
91+ if isSecretErr != nil {
92+ return nil , err
93+ }
94+ if isSecret {
95+ levels , err = client .AccessRules ().ListLevels (secretpath .Parent (path ))
96+ if err != nil {
97+ return nil , err
98+ }
99+ return levels , nil
100+ }
101+ } else if err != nil {
102+ return nil , err
103+ }
104+
105+ return levels , nil
106+ }
0 commit comments