martindstone / pagerduty-cli

A command line interface for PagerDuty
MIT License
91 stars 13 forks source link

pd service enable/disable commands do not respect -b, --useauth? #22

Closed gsreynolds closed 2 years ago

gsreynolds commented 2 years ago

When default auth token is one account but using -b or --useauth to use another account, service enable/disable commands will result in 404 as they are looking in the default account rather than the alias specified in -b or --useauth.

$ pd update                                                                                                                                                                                                                             
pagerduty-cli: Updating CLI... already on latest version: 0.0.79

$ # Default account selected and `-b` used to switch commands to another account
$ pd auth:list                                                                                                                                                                                                                                   
 Default Alias       Subdomain   Email Type
 ─────── ─────────── ─────────── ───── ───────────────
         accountB  accountB       Legacy (Global)
   ✅    primaryAccount   primaryAccount         Legacy (Global)
         accountA        accountA              Legacy (Global)
$ # Disable using -b for accountA alias
$ pd service:list -p -b accountA | pd service:disable -p -b accountA                                                                                                                                                                                      
Getting services from PD 1/1 👍, 0/1 👎... done
404 Not Found: Not Found  ×9
Setting status = 'disabled' on 9 services 0/9 👍, 9/9 👎... done
Failed to set service PSERVICEID1: 404 Not Found: Not Found
Failed to set service PSERVICEID2: 404 Not Found: Not Found
Failed to set service PSERVICEID3: 404 Not Found: Not Found
Failed to set service PSERVICEID4: 404 Not Found: Not Found
Failed to set service PSERVICEID5: 404 Not Found: Not Found
Failed to set service PSERVICEID6: 404 Not Found: Not Found
Failed to set service PSERVICEID7: 404 Not Found: Not Found
Failed to set service PSERVICEID8: 404 Not Found: Not Found
Failed to set service PSERVICEID9: 404 Not Found: Not Found

$ # Use accountA as the default auth token and it just works
$ pd auth:use -a accountA
$ pd service:list -p | pd service:disable -p                                                                                                                                                                                                      
Getting services from PD 1/1 👍, 0/1 👎... done
Setting status = 'disabled' on 9 services 9/9 👍, 0/9 👎... done

$ # Without switching default from accountA enable then disable a single service on "primaryAccount"
$ pd service:list -b primaryAccount
Getting services from PD 1/1 👍, 0/1 👎... done
 ID      Status   Name                        Escalation policy name             Team names
 ─────── ──────── ─────────────────────────── ────────────────────────────────── ────────────
 SOMEPDSERVICEID disabled ServiceOnPrimaryAccountAsExpected    Test App Default Escalation Policy
$ # Enable using -b for primaryAccount alias
$ pd service:enable -b primaryAccount --ids SOMEPDSERVICEID   
404 Not Found: Not Found
Setting status = 'active' on 1 services 0/1 👍, 1/1 👎... done
Failed to set service SOMEPDSERVICEID: 404 Not Found: Not Found
$ # Switch back to "primaryAccount" as default  and it just works                
$  pd service:enable -b primaryAccount --ids SOMEPDSERVICEID                                                                                                                                                                                                    
Setting status = 'active' on 1 services 1/1 👍, 0/1 👎... done