Skip to content

Commit b56ad13

Browse files
authored
Add AuthInfoV2 (#688)
Add AuthInfoV2
1 parent 9b7f0be commit b56ad13

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

clients/instance/ibm-pi-workspaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (f *IBMPIWorkspacesClient) Get(cloudInstanceID string) (*models.Workspace,
4545
return nil, fmt.Errorf(helpers.NotOnPremSupported)
4646
}
4747
params := workspaces.NewV1WorkspacesGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithWorkspaceID(cloudInstanceID)
48-
resp, err := f.session.Power.Workspaces.V1WorkspacesGet(params, f.session.AuthInfo(f.cloudInstanceID))
48+
resp, err := f.session.Power.Workspaces.V1WorkspacesGet(params, f.session.AuthInfoV2())
4949
if err != nil {
5050
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf(errors.GetWorkspaceOperationFailed, f.cloudInstanceID, err))
5151
}
@@ -61,7 +61,7 @@ func (f *IBMPIWorkspacesClient) GetAll() (*models.Workspaces, error) {
6161
return nil, fmt.Errorf(helpers.NotOnPremSupported)
6262
}
6363
params := workspaces.NewV1WorkspacesGetallParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
64-
resp, err := f.session.Power.Workspaces.V1WorkspacesGetall(params, f.session.AuthInfo(f.cloudInstanceID))
64+
resp, err := f.session.Power.Workspaces.V1WorkspacesGetall(params, f.session.AuthInfoV2())
6565
if err != nil {
6666
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get all Workspaces: %w", err))
6767
}

ibmpisession/session.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ func (s *IBMPISession) AuthInfo(cloudInstanceID string) runtime.ClientAuthInfoWr
125125
})
126126
}
127127

128+
// AuthInfoV2 only set Authorization since some apis do not require CRN in the header
129+
func (s *IBMPISession) AuthInfoV2() runtime.ClientAuthInfoWriter {
130+
return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error {
131+
auth, err := fetchAuthorizationData(s.Options.Authenticator)
132+
if err != nil {
133+
return err
134+
}
135+
return r.SetHeaderParam("Authorization", auth)
136+
})
137+
}
138+
128139
// IsOnPrem returns true if the operation is being done on premise (at a satellite region)
129140
func (s *IBMPISession) IsOnPrem() bool {
130141
return strings.Contains(s.Options.Zone, helpers.PIStratosRegionPrefix)

0 commit comments

Comments
 (0)