Skip to content

Commit b71cb7a

Browse files
alexbondar92assaf758
authored andcommitted
[ControlPlane] add GetRunningUserAttributesSync api
1 parent e30898c commit b71cb7a

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

pkg/controlplane/http/session.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,56 @@ func (s *session) DeleteAccessKeySync(deleteAccessKeyInput *v3ioc.DeleteAccessKe
226226
&deleteAccessKeyInput.ControlPlaneInput)
227227
}
228228

229+
// DeleteAccessKeySync deletes an access key (blocking)
230+
func (s *session) GetUserNameSync(getUserNameInput *v3ioc.GetUserNameInput) (*v3ioc.GetUserNameOutput, error) {
231+
232+
// prepare session response resource
233+
userNameOutput := v3ioc.GetUserNameOutput{}
234+
235+
// allocate request
236+
httpRequest := fasthttp.AcquireRequest()
237+
defer fasthttp.ReleaseRequest(httpRequest)
238+
239+
responseInstance, err := s.sendRequest(getUserNameInput.ControlPlaneInput.Ctx,
240+
&request{
241+
method: http.MethodGet,
242+
path: fmt.Sprintf("api/%s", "self"),
243+
httpRequest: httpRequest,
244+
}, getUserNameInput.ControlPlaneInput.Timeout)
245+
246+
if err != nil {
247+
return nil, err
248+
}
249+
250+
// if we got cookies, set them
251+
if len(responseInstance.cookies) > 0 {
252+
s.cookies = responseInstance.cookies
253+
}
254+
255+
var objmap map[string]json.RawMessage
256+
err = json.Unmarshal(responseInstance.body, &objmap)
257+
if err != nil {
258+
return nil, err
259+
}
260+
261+
err = json.Unmarshal(objmap["data"], &objmap)
262+
if err != nil {
263+
return nil, err
264+
}
265+
266+
err = json.Unmarshal(objmap["attributes"], &objmap)
267+
if err != nil {
268+
return nil, err
269+
}
270+
271+
err = json.Unmarshal(objmap["username"], &userNameOutput.Username)
272+
if err != nil {
273+
return nil, err
274+
}
275+
276+
return &userNameOutput, err
277+
}
278+
229279
func (s *session) createResource(ctx context.Context,
230280
path string,
231281
kind string,

pkg/controlplane/test/controlplane_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ func (suite *githubClientSuite) TestCreateEventUsingAccessKey() {
172172
err = accessKeySession.CreateEventSync(&createEventInput)
173173
suite.Require().NoError(err)
174174

175+
getUserNameInput := v3ioc.GetUserNameInput{}
176+
getUserNameInput.Ctx = suite.ctx
177+
178+
_, err = accessKeySession.GetUserNameSync(&getUserNameInput)
179+
suite.Require().NoError(err)
180+
175181
// Delete access key
176182
deleteAccessKeyInput := v3ioc.DeleteAccessKeyInput{}
177183
deleteAccessKeyInput.ID = createAccessKeyOutput.ID

pkg/controlplane/types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ type Session interface {
4646

4747
// DeleteAccessKeySync deletes an access key (blocking)
4848
DeleteAccessKeySync(*DeleteAccessKeyInput) error
49+
50+
// GetUserNameSync returns username related to session's access key (blocking)
51+
GetUserNameSync(*GetUserNameInput) (*GetUserNameOutput, error)
4952
}
5053

5154
type ControlPlaneInput struct {
@@ -137,3 +140,14 @@ type CreateAccessKeyOutput struct {
137140
type DeleteAccessKeyInput struct {
138141
ControlPlaneInput
139142
}
143+
144+
// GetUserNameInput specifies what access key
145+
type GetUserNameInput struct {
146+
ControlPlaneInput
147+
}
148+
149+
// GetUserNameOutput holds the response from get username
150+
type GetUserNameOutput struct {
151+
ControlPlaneOutput
152+
Username string
153+
}

0 commit comments

Comments
 (0)