@@ -97,7 +97,7 @@ func NewPasswordsService(client *Client) *passwordsService {
97
97
98
98
// Creates a new password for a branch.
99
99
func (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 )
101
101
req , err := d .client .newRequest (http .MethodPost , path , createReq )
102
102
if err != nil {
103
103
return nil , errors .Wrap (err , "error creating http request" )
@@ -113,7 +113,7 @@ func (d *passwordsService) Create(ctx context.Context, createReq *DatabaseBranch
113
113
114
114
// Delete an existing password for a branch.
115
115
func (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 )
117
117
req , err := d .client .newRequest (http .MethodDelete , path , nil )
118
118
if err != nil {
119
119
return errors .Wrap (err , "error creating http request" )
@@ -126,7 +126,7 @@ func (d *passwordsService) Delete(ctx context.Context, deleteReq *DeleteDatabase
126
126
127
127
// Get an existing password for a branch.
128
128
func (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 )
130
130
req , err := d .client .newRequest (http .MethodGet , path , nil )
131
131
if err != nil {
132
132
return nil , errors .Wrap (err , "error creating http request" )
@@ -141,9 +141,15 @@ func (d *passwordsService) Get(ctx context.Context, getReq *GetDatabaseBranchPas
141
141
142
142
}
143
143
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.
145
146
func (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 )
147
153
if err != nil {
148
154
return nil , errors .Wrap (err , "error creating http request to list passwords" )
149
155
}
@@ -156,10 +162,14 @@ func (d *passwordsService) List(ctx context.Context, listReq *ListDatabaseBranch
156
162
return passwordsResp .Passwords , nil
157
163
}
158
164
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 )
161
167
}
162
168
163
- func passwordsAPIPath (org , db , branch string ) string {
169
+ func passwordsBranchAPIPath (org , db , branch string ) string {
164
170
return fmt .Sprintf ("%s/passwords" , databaseBranchAPIPath (org , db , branch ))
165
171
}
172
+
173
+ func passwordsAPIPath (org , db string ) string {
174
+ return fmt .Sprintf ("%s/%s/passwords" , databasesAPIPath (org ), db )
175
+ }
0 commit comments