@@ -97,7 +97,7 @@ func NewPasswordsService(client *Client) *passwordsService {
9797
9898// Creates a new password for a branch.
9999func (d * passwordsService ) Create (ctx context.Context , createReq * DatabaseBranchPasswordRequest ) (* DatabaseBranchPassword , error ) {
100- path := passwordsAPIPath (createReq .Organization , createReq .Database , createReq .Branch )
100+ path := passwordsBranchAPIPath (createReq .Organization , createReq .Database , createReq .Branch )
101101 req , err := d .client .newRequest (http .MethodPost , path , createReq )
102102 if err != nil {
103103 return nil , errors .Wrap (err , "error creating http request" )
@@ -113,7 +113,7 @@ func (d *passwordsService) Create(ctx context.Context, createReq *DatabaseBranch
113113
114114// Delete an existing password for a branch.
115115func (d * passwordsService ) Delete (ctx context.Context , deleteReq * DeleteDatabaseBranchPasswordRequest ) error {
116- path := passwordAPIPath (deleteReq .Organization , deleteReq .Database , deleteReq .Branch , deleteReq .PasswordId )
116+ path := passwordBranchAPIPath (deleteReq .Organization , deleteReq .Database , deleteReq .Branch , deleteReq .PasswordId )
117117 req , err := d .client .newRequest (http .MethodDelete , path , nil )
118118 if err != nil {
119119 return errors .Wrap (err , "error creating http request" )
@@ -126,7 +126,7 @@ func (d *passwordsService) Delete(ctx context.Context, deleteReq *DeleteDatabase
126126
127127// Get an existing password for a branch.
128128func (d * passwordsService ) Get (ctx context.Context , getReq * GetDatabaseBranchPasswordRequest ) (* DatabaseBranchPassword , error ) {
129- path := passwordAPIPath (getReq .Organization , getReq .Database , getReq .Branch , getReq .PasswordId )
129+ path := passwordBranchAPIPath (getReq .Organization , getReq .Database , getReq .Branch , getReq .PasswordId )
130130 req , err := d .client .newRequest (http .MethodGet , path , nil )
131131 if err != nil {
132132 return nil , errors .Wrap (err , "error creating http request" )
@@ -141,9 +141,15 @@ func (d *passwordsService) Get(ctx context.Context, getReq *GetDatabaseBranchPas
141141
142142}
143143
144- // List all existing passwords for a branch.
144+ // List all existing passwords. If req.Branch is set, all passwords for that
145+ // branch will be listed.
145146func (d * passwordsService ) List (ctx context.Context , listReq * ListDatabaseBranchPasswordRequest ) ([]* DatabaseBranchPassword , error ) {
146- req , err := d .client .newRequest (http .MethodGet , passwordsAPIPath (listReq .Organization , listReq .Database , listReq .Branch ), nil )
147+ path := passwordsAPIPath (listReq .Organization , listReq .Database )
148+ if listReq .Branch != "" {
149+ path = passwordBranchAPIPath (listReq .Organization , listReq .Database , listReq .Branch , "" )
150+ }
151+
152+ req , err := d .client .newRequest (http .MethodGet , path , nil )
147153 if err != nil {
148154 return nil , errors .Wrap (err , "error creating http request to list passwords" )
149155 }
@@ -156,10 +162,14 @@ func (d *passwordsService) List(ctx context.Context, listReq *ListDatabaseBranch
156162 return passwordsResp .Passwords , nil
157163}
158164
159- func passwordAPIPath (org , db , branch , password string ) string {
160- return fmt .Sprintf ("%s/%s" , passwordsAPIPath (org , db , branch ), password )
165+ func passwordBranchAPIPath (org , db , branch , password string ) string {
166+ return fmt .Sprintf ("%s/%s" , passwordsBranchAPIPath (org , db , branch ), password )
161167}
162168
163- func passwordsAPIPath (org , db , branch string ) string {
169+ func passwordsBranchAPIPath (org , db , branch string ) string {
164170 return fmt .Sprintf ("%s/passwords" , databaseBranchAPIPath (org , db , branch ))
165171}
172+
173+ func passwordsAPIPath (org , db string ) string {
174+ return fmt .Sprintf ("%s/%s/passwords" , databasesAPIPath (org ), db )
175+ }
0 commit comments