diff --git a/okta/appUser.go b/okta/appUser.go index 7f7f02cdf..8e01fbf50 100644 --- a/okta/appUser.go +++ b/okta/appUser.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -52,7 +53,7 @@ func (a *AppUser) IsApplicationInstance() bool { } // Updates a user's profile for an application -func (m *AppUserResource) UpdateApplicationUser(appId string, userId string, body AppUser) (*AppUser, *Response, error) { +func (m *AppUserResource) UpdateApplicationUser(ctx context.Context, appId string, userId string, body AppUser) (*AppUser, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/users/%v", appId, userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -62,7 +63,7 @@ func (m *AppUserResource) UpdateApplicationUser(appId string, userId string, bod var appUser *AppUser - resp, err := m.client.requestExecutor.Do(req, &appUser) + resp, err := m.client.requestExecutor.Do(ctx, req, &appUser) if err != nil { return nil, resp, err } @@ -71,7 +72,7 @@ func (m *AppUserResource) UpdateApplicationUser(appId string, userId string, bod } // Removes an assignment for a user from an application. -func (m *AppUserResource) DeleteApplicationUser(appId string, userId string, qp *query.Params) (*Response, error) { +func (m *AppUserResource) DeleteApplicationUser(ctx context.Context, appId string, userId string, qp *query.Params) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/users/%v", appId, userId) if qp != nil { url = url + qp.String() @@ -82,7 +83,7 @@ func (m *AppUserResource) DeleteApplicationUser(appId string, userId string, qp return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } diff --git a/okta/application.go b/okta/application.go index 775e80ae7..f35f43842 100644 --- a/okta/application.go +++ b/okta/application.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -58,7 +59,7 @@ func (a *Application) IsApplicationInstance() bool { } // Fetches an application from your Okta organization by `id`. -func (m *ApplicationResource) GetApplication(appId string, appInstance App, qp *query.Params) (App, *Response, error) { +func (m *ApplicationResource) GetApplication(ctx context.Context, appId string, appInstance App, qp *query.Params) (App, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v", appId) if qp != nil { url = url + qp.String() @@ -71,7 +72,7 @@ func (m *ApplicationResource) GetApplication(appId string, appInstance App, qp * application := appInstance - resp, err := m.client.requestExecutor.Do(req, &application) + resp, err := m.client.requestExecutor.Do(ctx, req, &application) if err != nil { return nil, resp, err } @@ -80,7 +81,7 @@ func (m *ApplicationResource) GetApplication(appId string, appInstance App, qp * } // Updates an application in your organization. -func (m *ApplicationResource) UpdateApplication(appId string, body App) (App, *Response, error) { +func (m *ApplicationResource) UpdateApplication(ctx context.Context, appId string, body App) (App, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v", appId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -90,7 +91,7 @@ func (m *ApplicationResource) UpdateApplication(appId string, body App) (App, *R application := body - resp, err := m.client.requestExecutor.Do(req, &application) + resp, err := m.client.requestExecutor.Do(ctx, req, &application) if err != nil { return nil, resp, err } @@ -99,7 +100,7 @@ func (m *ApplicationResource) UpdateApplication(appId string, body App) (App, *R } // Removes an inactive application. -func (m *ApplicationResource) DeleteApplication(appId string) (*Response, error) { +func (m *ApplicationResource) DeleteApplication(ctx context.Context, appId string) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v", appId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -107,7 +108,7 @@ func (m *ApplicationResource) DeleteApplication(appId string) (*Response, error) return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -116,7 +117,7 @@ func (m *ApplicationResource) DeleteApplication(appId string) (*Response, error) } // Enumerates apps added to your organization with pagination. A subset of apps can be returned that match a supported filter expression or query. -func (m *ApplicationResource) ListApplications(qp *query.Params) ([]App, *Response, error) { +func (m *ApplicationResource) ListApplications(ctx context.Context, qp *query.Params) ([]App, *Response, error) { url := fmt.Sprintf("/api/v1/apps") if qp != nil { url = url + qp.String() @@ -129,7 +130,7 @@ func (m *ApplicationResource) ListApplications(qp *query.Params) ([]App, *Respon var application []Application - resp, err := m.client.requestExecutor.Do(req, &application) + resp, err := m.client.requestExecutor.Do(ctx, req, &application) if err != nil { return nil, resp, err } @@ -143,7 +144,7 @@ func (m *ApplicationResource) ListApplications(qp *query.Params) ([]App, *Respon } // Adds a new application to your Okta organization. -func (m *ApplicationResource) CreateApplication(body App, qp *query.Params) (App, *Response, error) { +func (m *ApplicationResource) CreateApplication(ctx context.Context, body App, qp *query.Params) (App, *Response, error) { url := fmt.Sprintf("/api/v1/apps") if qp != nil { url = url + qp.String() @@ -156,7 +157,7 @@ func (m *ApplicationResource) CreateApplication(body App, qp *query.Params) (App application := body - resp, err := m.client.requestExecutor.Do(req, &application) + resp, err := m.client.requestExecutor.Do(ctx, req, &application) if err != nil { return nil, resp, err } @@ -165,7 +166,7 @@ func (m *ApplicationResource) CreateApplication(body App, qp *query.Params) (App } // Enumerates CSRs for an application -func (m *ApplicationResource) ListCsrsForApplication(appId string) ([]*CSR, *Response, error) { +func (m *ApplicationResource) ListCsrsForApplication(ctx context.Context, appId string) ([]*CSR, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs", appId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -175,7 +176,7 @@ func (m *ApplicationResource) ListCsrsForApplication(appId string) ([]*CSR, *Res var csr []*CSR - resp, err := m.client.requestExecutor.Do(req, &csr) + resp, err := m.client.requestExecutor.Do(ctx, req, &csr) if err != nil { return nil, resp, err } @@ -184,7 +185,7 @@ func (m *ApplicationResource) ListCsrsForApplication(appId string) ([]*CSR, *Res } // Generates a new key pair and returns the Certificate Signing Request for it. -func (m *ApplicationResource) GenerateCsrForApplication(appId string, body CSRMetadata) (*CSR, *Response, error) { +func (m *ApplicationResource) GenerateCsrForApplication(ctx context.Context, appId string, body CSRMetadata) (*CSR, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs", appId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -194,7 +195,7 @@ func (m *ApplicationResource) GenerateCsrForApplication(appId string, body CSRMe var csr *CSR - resp, err := m.client.requestExecutor.Do(req, &csr) + resp, err := m.client.requestExecutor.Do(ctx, req, &csr) if err != nil { return nil, resp, err } @@ -202,7 +203,7 @@ func (m *ApplicationResource) GenerateCsrForApplication(appId string, body CSRMe return csr, resp, nil } -func (m *ApplicationResource) RevokeCSRFromApplication(appId string, csrId string) (*Response, error) { +func (m *ApplicationResource) RevokeCSRFromApplication(ctx context.Context, appId string, csrId string) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs/%v", appId, csrId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -210,7 +211,7 @@ func (m *ApplicationResource) RevokeCSRFromApplication(appId string, csrId strin return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -218,7 +219,7 @@ func (m *ApplicationResource) RevokeCSRFromApplication(appId string, csrId strin return resp, nil } -func (m *ApplicationResource) GetCsrForApplication(appId string, csrId string) (*CSR, *Response, error) { +func (m *ApplicationResource) GetCsrForApplication(ctx context.Context, appId string, csrId string) (*CSR, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs/%v", appId, csrId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -228,7 +229,7 @@ func (m *ApplicationResource) GetCsrForApplication(appId string, csrId string) ( var csr *CSR - resp, err := m.client.requestExecutor.Do(req, &csr) + resp, err := m.client.requestExecutor.Do(ctx, req, &csr) if err != nil { return nil, resp, err } @@ -236,7 +237,7 @@ func (m *ApplicationResource) GetCsrForApplication(appId string, csrId string) ( return csr, resp, nil } -func (m *ApplicationResource) PublishCerCert(appId string, csrId string, body string) (*JsonWebKey, *Response, error) { +func (m *ApplicationResource) PublishCerCert(ctx context.Context, appId string, csrId string, body string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs/%v/lifecycle/publish", appId, csrId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/x-x509-ca-cert").NewRequest("POST", url, body) @@ -246,7 +247,7 @@ func (m *ApplicationResource) PublishCerCert(appId string, csrId string, body st var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -254,7 +255,7 @@ func (m *ApplicationResource) PublishCerCert(appId string, csrId string, body st return jsonWebKey, resp, nil } -func (m *ApplicationResource) PublishBinaryCerCert(appId string, csrId string, body string) (*JsonWebKey, *Response, error) { +func (m *ApplicationResource) PublishBinaryCerCert(ctx context.Context, appId string, csrId string, body string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs/%v/lifecycle/publish", appId, csrId) req, err := m.client.requestExecutor.AsBinary().WithAccept("application/json").WithContentType("application/x-x509-ca-cert").NewRequest("POST", url, body) @@ -264,7 +265,7 @@ func (m *ApplicationResource) PublishBinaryCerCert(appId string, csrId string, b var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -272,7 +273,7 @@ func (m *ApplicationResource) PublishBinaryCerCert(appId string, csrId string, b return jsonWebKey, resp, nil } -func (m *ApplicationResource) PublishDerCert(appId string, csrId string, body string) (*JsonWebKey, *Response, error) { +func (m *ApplicationResource) PublishDerCert(ctx context.Context, appId string, csrId string, body string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs/%v/lifecycle/publish", appId, csrId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/pkix-cert").NewRequest("POST", url, body) @@ -282,7 +283,7 @@ func (m *ApplicationResource) PublishDerCert(appId string, csrId string, body st var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -290,7 +291,7 @@ func (m *ApplicationResource) PublishDerCert(appId string, csrId string, body st return jsonWebKey, resp, nil } -func (m *ApplicationResource) PublishBinaryDerCert(appId string, csrId string, body string) (*JsonWebKey, *Response, error) { +func (m *ApplicationResource) PublishBinaryDerCert(ctx context.Context, appId string, csrId string, body string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs/%v/lifecycle/publish", appId, csrId) req, err := m.client.requestExecutor.AsBinary().WithAccept("application/json").WithContentType("application/pkix-cert").NewRequest("POST", url, body) @@ -300,7 +301,7 @@ func (m *ApplicationResource) PublishBinaryDerCert(appId string, csrId string, b var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -308,7 +309,7 @@ func (m *ApplicationResource) PublishBinaryDerCert(appId string, csrId string, b return jsonWebKey, resp, nil } -func (m *ApplicationResource) PublishBinaryPemCert(appId string, csrId string, body string) (*JsonWebKey, *Response, error) { +func (m *ApplicationResource) PublishBinaryPemCert(ctx context.Context, appId string, csrId string, body string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs/%v/lifecycle/publish", appId, csrId) req, err := m.client.requestExecutor.AsBinary().WithAccept("application/json").WithContentType("application/x-pem-file").NewRequest("POST", url, body) @@ -318,7 +319,7 @@ func (m *ApplicationResource) PublishBinaryPemCert(appId string, csrId string, b var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -327,7 +328,7 @@ func (m *ApplicationResource) PublishBinaryPemCert(appId string, csrId string, b } // Enumerates key credentials for an application -func (m *ApplicationResource) ListApplicationKeys(appId string) ([]*JsonWebKey, *Response, error) { +func (m *ApplicationResource) ListApplicationKeys(ctx context.Context, appId string) ([]*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/keys", appId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -337,7 +338,7 @@ func (m *ApplicationResource) ListApplicationKeys(appId string) ([]*JsonWebKey, var jsonWebKey []*JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -346,7 +347,7 @@ func (m *ApplicationResource) ListApplicationKeys(appId string) ([]*JsonWebKey, } // Gets a specific [application key credential](#application-key-credential-model) by `kid` -func (m *ApplicationResource) GetApplicationKey(appId string, keyId string) (*JsonWebKey, *Response, error) { +func (m *ApplicationResource) GetApplicationKey(ctx context.Context, appId string, keyId string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/keys/%v", appId, keyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -356,7 +357,7 @@ func (m *ApplicationResource) GetApplicationKey(appId string, keyId string) (*Js var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -365,7 +366,7 @@ func (m *ApplicationResource) GetApplicationKey(appId string, keyId string) (*Js } // Clones a X.509 certificate for an application key credential from a source application to target application. -func (m *ApplicationResource) CloneApplicationKey(appId string, keyId string, qp *query.Params) (*JsonWebKey, *Response, error) { +func (m *ApplicationResource) CloneApplicationKey(ctx context.Context, appId string, keyId string, qp *query.Params) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/credentials/keys/%v/clone", appId, keyId) if qp != nil { url = url + qp.String() @@ -378,7 +379,7 @@ func (m *ApplicationResource) CloneApplicationKey(appId string, keyId string, qp var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -387,7 +388,7 @@ func (m *ApplicationResource) CloneApplicationKey(appId string, keyId string, qp } // Lists all scope consent grants for the application -func (m *ApplicationResource) ListScopeConsentGrants(appId string, qp *query.Params) ([]*OAuth2ScopeConsentGrant, *Response, error) { +func (m *ApplicationResource) ListScopeConsentGrants(ctx context.Context, appId string, qp *query.Params) ([]*OAuth2ScopeConsentGrant, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/grants", appId) if qp != nil { url = url + qp.String() @@ -400,7 +401,7 @@ func (m *ApplicationResource) ListScopeConsentGrants(appId string, qp *query.Par var oAuth2ScopeConsentGrant []*OAuth2ScopeConsentGrant - resp, err := m.client.requestExecutor.Do(req, &oAuth2ScopeConsentGrant) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2ScopeConsentGrant) if err != nil { return nil, resp, err } @@ -409,7 +410,7 @@ func (m *ApplicationResource) ListScopeConsentGrants(appId string, qp *query.Par } // Grants consent for the application to request an OAuth 2.0 Okta scope -func (m *ApplicationResource) GrantConsentToScope(appId string, body OAuth2ScopeConsentGrant) (*OAuth2ScopeConsentGrant, *Response, error) { +func (m *ApplicationResource) GrantConsentToScope(ctx context.Context, appId string, body OAuth2ScopeConsentGrant) (*OAuth2ScopeConsentGrant, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/grants", appId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -419,7 +420,7 @@ func (m *ApplicationResource) GrantConsentToScope(appId string, body OAuth2Scope var oAuth2ScopeConsentGrant *OAuth2ScopeConsentGrant - resp, err := m.client.requestExecutor.Do(req, &oAuth2ScopeConsentGrant) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2ScopeConsentGrant) if err != nil { return nil, resp, err } @@ -428,7 +429,7 @@ func (m *ApplicationResource) GrantConsentToScope(appId string, body OAuth2Scope } // Revokes permission for the application to request the given scope -func (m *ApplicationResource) RevokeScopeConsentGrant(appId string, grantId string) (*Response, error) { +func (m *ApplicationResource) RevokeScopeConsentGrant(ctx context.Context, appId string, grantId string) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/grants/%v", appId, grantId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -436,7 +437,7 @@ func (m *ApplicationResource) RevokeScopeConsentGrant(appId string, grantId stri return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -445,7 +446,7 @@ func (m *ApplicationResource) RevokeScopeConsentGrant(appId string, grantId stri } // Fetches a single scope consent grant for the application -func (m *ApplicationResource) GetScopeConsentGrant(appId string, grantId string, qp *query.Params) (*OAuth2ScopeConsentGrant, *Response, error) { +func (m *ApplicationResource) GetScopeConsentGrant(ctx context.Context, appId string, grantId string, qp *query.Params) (*OAuth2ScopeConsentGrant, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/grants/%v", appId, grantId) if qp != nil { url = url + qp.String() @@ -458,7 +459,7 @@ func (m *ApplicationResource) GetScopeConsentGrant(appId string, grantId string, var oAuth2ScopeConsentGrant *OAuth2ScopeConsentGrant - resp, err := m.client.requestExecutor.Do(req, &oAuth2ScopeConsentGrant) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2ScopeConsentGrant) if err != nil { return nil, resp, err } @@ -467,7 +468,7 @@ func (m *ApplicationResource) GetScopeConsentGrant(appId string, grantId string, } // Enumerates group assignments for an application. -func (m *ApplicationResource) ListApplicationGroupAssignments(appId string, qp *query.Params) ([]*ApplicationGroupAssignment, *Response, error) { +func (m *ApplicationResource) ListApplicationGroupAssignments(ctx context.Context, appId string, qp *query.Params) ([]*ApplicationGroupAssignment, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/groups", appId) if qp != nil { url = url + qp.String() @@ -480,7 +481,7 @@ func (m *ApplicationResource) ListApplicationGroupAssignments(appId string, qp * var applicationGroupAssignment []*ApplicationGroupAssignment - resp, err := m.client.requestExecutor.Do(req, &applicationGroupAssignment) + resp, err := m.client.requestExecutor.Do(ctx, req, &applicationGroupAssignment) if err != nil { return nil, resp, err } @@ -489,7 +490,7 @@ func (m *ApplicationResource) ListApplicationGroupAssignments(appId string, qp * } // Removes a group assignment from an application. -func (m *ApplicationResource) DeleteApplicationGroupAssignment(appId string, groupId string) (*Response, error) { +func (m *ApplicationResource) DeleteApplicationGroupAssignment(ctx context.Context, appId string, groupId string) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/groups/%v", appId, groupId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -497,7 +498,7 @@ func (m *ApplicationResource) DeleteApplicationGroupAssignment(appId string, gro return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -506,7 +507,7 @@ func (m *ApplicationResource) DeleteApplicationGroupAssignment(appId string, gro } // Fetches an application group assignment -func (m *ApplicationResource) GetApplicationGroupAssignment(appId string, groupId string, qp *query.Params) (*ApplicationGroupAssignment, *Response, error) { +func (m *ApplicationResource) GetApplicationGroupAssignment(ctx context.Context, appId string, groupId string, qp *query.Params) (*ApplicationGroupAssignment, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/groups/%v", appId, groupId) if qp != nil { url = url + qp.String() @@ -519,7 +520,7 @@ func (m *ApplicationResource) GetApplicationGroupAssignment(appId string, groupI var applicationGroupAssignment *ApplicationGroupAssignment - resp, err := m.client.requestExecutor.Do(req, &applicationGroupAssignment) + resp, err := m.client.requestExecutor.Do(ctx, req, &applicationGroupAssignment) if err != nil { return nil, resp, err } @@ -528,7 +529,7 @@ func (m *ApplicationResource) GetApplicationGroupAssignment(appId string, groupI } // Assigns a group to an application -func (m *ApplicationResource) CreateApplicationGroupAssignment(appId string, groupId string, body ApplicationGroupAssignment) (*ApplicationGroupAssignment, *Response, error) { +func (m *ApplicationResource) CreateApplicationGroupAssignment(ctx context.Context, appId string, groupId string, body ApplicationGroupAssignment) (*ApplicationGroupAssignment, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/groups/%v", appId, groupId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -538,7 +539,7 @@ func (m *ApplicationResource) CreateApplicationGroupAssignment(appId string, gro var applicationGroupAssignment *ApplicationGroupAssignment - resp, err := m.client.requestExecutor.Do(req, &applicationGroupAssignment) + resp, err := m.client.requestExecutor.Do(ctx, req, &applicationGroupAssignment) if err != nil { return nil, resp, err } @@ -547,7 +548,7 @@ func (m *ApplicationResource) CreateApplicationGroupAssignment(appId string, gro } // Activates an inactive application. -func (m *ApplicationResource) ActivateApplication(appId string) (*Response, error) { +func (m *ApplicationResource) ActivateApplication(ctx context.Context, appId string) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/lifecycle/activate", appId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -555,7 +556,7 @@ func (m *ApplicationResource) ActivateApplication(appId string) (*Response, erro return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -564,7 +565,7 @@ func (m *ApplicationResource) ActivateApplication(appId string) (*Response, erro } // Deactivates an active application. -func (m *ApplicationResource) DeactivateApplication(appId string) (*Response, error) { +func (m *ApplicationResource) DeactivateApplication(ctx context.Context, appId string) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/lifecycle/deactivate", appId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -572,7 +573,7 @@ func (m *ApplicationResource) DeactivateApplication(appId string) (*Response, er return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -581,7 +582,7 @@ func (m *ApplicationResource) DeactivateApplication(appId string) (*Response, er } // Previews SAML metadata based on a specific key credential for an application -func (m *ApplicationResource) PreviewSamlMetadataForApplication(appId string, qp *query.Params) (*Response, error) { +func (m *ApplicationResource) PreviewSamlMetadataForApplication(ctx context.Context, appId string, qp *query.Params) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/sso/saml/metadata", appId) if qp != nil { url = url + qp.String() @@ -592,7 +593,7 @@ func (m *ApplicationResource) PreviewSamlMetadataForApplication(appId string, qp return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -601,7 +602,7 @@ func (m *ApplicationResource) PreviewSamlMetadataForApplication(appId string, qp } // Revokes all tokens for the specified application -func (m *ApplicationResource) RevokeOAuth2TokensForApplication(appId string) (*Response, error) { +func (m *ApplicationResource) RevokeOAuth2TokensForApplication(ctx context.Context, appId string) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/tokens", appId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -609,7 +610,7 @@ func (m *ApplicationResource) RevokeOAuth2TokensForApplication(appId string) (*R return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -618,7 +619,7 @@ func (m *ApplicationResource) RevokeOAuth2TokensForApplication(appId string) (*R } // Lists all tokens for the application -func (m *ApplicationResource) ListOAuth2TokensForApplication(appId string, qp *query.Params) ([]*OAuth2Token, *Response, error) { +func (m *ApplicationResource) ListOAuth2TokensForApplication(ctx context.Context, appId string, qp *query.Params) ([]*OAuth2Token, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/tokens", appId) if qp != nil { url = url + qp.String() @@ -631,7 +632,7 @@ func (m *ApplicationResource) ListOAuth2TokensForApplication(appId string, qp *q var oAuth2Token []*OAuth2Token - resp, err := m.client.requestExecutor.Do(req, &oAuth2Token) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Token) if err != nil { return nil, resp, err } @@ -640,7 +641,7 @@ func (m *ApplicationResource) ListOAuth2TokensForApplication(appId string, qp *q } // Revokes the specified token for the specified application -func (m *ApplicationResource) RevokeOAuth2TokenForApplication(appId string, tokenId string) (*Response, error) { +func (m *ApplicationResource) RevokeOAuth2TokenForApplication(ctx context.Context, appId string, tokenId string) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/tokens/%v", appId, tokenId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -648,7 +649,7 @@ func (m *ApplicationResource) RevokeOAuth2TokenForApplication(appId string, toke return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -657,7 +658,7 @@ func (m *ApplicationResource) RevokeOAuth2TokenForApplication(appId string, toke } // Gets a token for the specified application -func (m *ApplicationResource) GetOAuth2TokenForApplication(appId string, tokenId string, qp *query.Params) (*OAuth2Token, *Response, error) { +func (m *ApplicationResource) GetOAuth2TokenForApplication(ctx context.Context, appId string, tokenId string, qp *query.Params) (*OAuth2Token, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/tokens/%v", appId, tokenId) if qp != nil { url = url + qp.String() @@ -670,7 +671,7 @@ func (m *ApplicationResource) GetOAuth2TokenForApplication(appId string, tokenId var oAuth2Token *OAuth2Token - resp, err := m.client.requestExecutor.Do(req, &oAuth2Token) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Token) if err != nil { return nil, resp, err } @@ -679,7 +680,7 @@ func (m *ApplicationResource) GetOAuth2TokenForApplication(appId string, tokenId } // Enumerates all assigned [application users](#application-user-model) for an application. -func (m *ApplicationResource) ListApplicationUsers(appId string, qp *query.Params) ([]*AppUser, *Response, error) { +func (m *ApplicationResource) ListApplicationUsers(ctx context.Context, appId string, qp *query.Params) ([]*AppUser, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/users", appId) if qp != nil { url = url + qp.String() @@ -692,7 +693,7 @@ func (m *ApplicationResource) ListApplicationUsers(appId string, qp *query.Param var appUser []*AppUser - resp, err := m.client.requestExecutor.Do(req, &appUser) + resp, err := m.client.requestExecutor.Do(ctx, req, &appUser) if err != nil { return nil, resp, err } @@ -701,7 +702,7 @@ func (m *ApplicationResource) ListApplicationUsers(appId string, qp *query.Param } // Assigns an user to an application with [credentials](#application-user-credentials-object) and an app-specific [profile](#application-user-profile-object). Profile mappings defined for the application are first applied before applying any profile properties specified in the request. -func (m *ApplicationResource) AssignUserToApplication(appId string, body AppUser) (*AppUser, *Response, error) { +func (m *ApplicationResource) AssignUserToApplication(ctx context.Context, appId string, body AppUser) (*AppUser, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/users", appId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -711,7 +712,7 @@ func (m *ApplicationResource) AssignUserToApplication(appId string, body AppUser var appUser *AppUser - resp, err := m.client.requestExecutor.Do(req, &appUser) + resp, err := m.client.requestExecutor.Do(ctx, req, &appUser) if err != nil { return nil, resp, err } @@ -720,7 +721,7 @@ func (m *ApplicationResource) AssignUserToApplication(appId string, body AppUser } // Removes an assignment for a user from an application. -func (m *ApplicationResource) DeleteApplicationUser(appId string, userId string, qp *query.Params) (*Response, error) { +func (m *ApplicationResource) DeleteApplicationUser(ctx context.Context, appId string, userId string, qp *query.Params) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/users/%v", appId, userId) if qp != nil { url = url + qp.String() @@ -731,7 +732,7 @@ func (m *ApplicationResource) DeleteApplicationUser(appId string, userId string, return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -740,7 +741,7 @@ func (m *ApplicationResource) DeleteApplicationUser(appId string, userId string, } // Fetches a specific user assignment for application by `id`. -func (m *ApplicationResource) GetApplicationUser(appId string, userId string, qp *query.Params) (*AppUser, *Response, error) { +func (m *ApplicationResource) GetApplicationUser(ctx context.Context, appId string, userId string, qp *query.Params) (*AppUser, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/users/%v", appId, userId) if qp != nil { url = url + qp.String() @@ -753,7 +754,7 @@ func (m *ApplicationResource) GetApplicationUser(appId string, userId string, qp var appUser *AppUser - resp, err := m.client.requestExecutor.Do(req, &appUser) + resp, err := m.client.requestExecutor.Do(ctx, req, &appUser) if err != nil { return nil, resp, err } @@ -762,7 +763,7 @@ func (m *ApplicationResource) GetApplicationUser(appId string, userId string, qp } // Updates a user's profile for an application -func (m *ApplicationResource) UpdateApplicationUser(appId string, userId string, body AppUser) (*AppUser, *Response, error) { +func (m *ApplicationResource) UpdateApplicationUser(ctx context.Context, appId string, userId string, body AppUser) (*AppUser, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/users/%v", appId, userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -772,7 +773,7 @@ func (m *ApplicationResource) UpdateApplicationUser(appId string, userId string, var appUser *AppUser - resp, err := m.client.requestExecutor.Do(req, &appUser) + resp, err := m.client.requestExecutor.Do(ctx, req, &appUser) if err != nil { return nil, resp, err } diff --git a/okta/applicationGroupAssignment.go b/okta/applicationGroupAssignment.go index 67770d724..8140e4f72 100644 --- a/okta/applicationGroupAssignment.go +++ b/okta/applicationGroupAssignment.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "time" ) @@ -43,7 +44,7 @@ func (a *ApplicationGroupAssignment) IsApplicationInstance() bool { } // Removes a group assignment from an application. -func (m *ApplicationGroupAssignmentResource) DeleteApplicationGroupAssignment(appId string, groupId string) (*Response, error) { +func (m *ApplicationGroupAssignmentResource) DeleteApplicationGroupAssignment(ctx context.Context, appId string, groupId string) (*Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/groups/%v", appId, groupId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -51,7 +52,7 @@ func (m *ApplicationGroupAssignmentResource) DeleteApplicationGroupAssignment(ap return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } diff --git a/okta/authorizationServer.go b/okta/authorizationServer.go index 75ab570ee..1316d72df 100644 --- a/okta/authorizationServer.go +++ b/okta/authorizationServer.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -40,7 +41,7 @@ type AuthorizationServer struct { Status string `json:"status,omitempty"` } -func (m *AuthorizationServerResource) CreateAuthorizationServer(body AuthorizationServer) (*AuthorizationServer, *Response, error) { +func (m *AuthorizationServerResource) CreateAuthorizationServer(ctx context.Context, body AuthorizationServer) (*AuthorizationServer, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -50,7 +51,7 @@ func (m *AuthorizationServerResource) CreateAuthorizationServer(body Authorizati var authorizationServer *AuthorizationServer - resp, err := m.client.requestExecutor.Do(req, &authorizationServer) + resp, err := m.client.requestExecutor.Do(ctx, req, &authorizationServer) if err != nil { return nil, resp, err } @@ -58,7 +59,7 @@ func (m *AuthorizationServerResource) CreateAuthorizationServer(body Authorizati return authorizationServer, resp, nil } -func (m *AuthorizationServerResource) GetAuthorizationServer(authServerId string) (*AuthorizationServer, *Response, error) { +func (m *AuthorizationServerResource) GetAuthorizationServer(ctx context.Context, authServerId string) (*AuthorizationServer, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -68,7 +69,7 @@ func (m *AuthorizationServerResource) GetAuthorizationServer(authServerId string var authorizationServer *AuthorizationServer - resp, err := m.client.requestExecutor.Do(req, &authorizationServer) + resp, err := m.client.requestExecutor.Do(ctx, req, &authorizationServer) if err != nil { return nil, resp, err } @@ -76,7 +77,7 @@ func (m *AuthorizationServerResource) GetAuthorizationServer(authServerId string return authorizationServer, resp, nil } -func (m *AuthorizationServerResource) UpdateAuthorizationServer(authServerId string, body AuthorizationServer) (*AuthorizationServer, *Response, error) { +func (m *AuthorizationServerResource) UpdateAuthorizationServer(ctx context.Context, authServerId string, body AuthorizationServer) (*AuthorizationServer, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -86,7 +87,7 @@ func (m *AuthorizationServerResource) UpdateAuthorizationServer(authServerId str var authorizationServer *AuthorizationServer - resp, err := m.client.requestExecutor.Do(req, &authorizationServer) + resp, err := m.client.requestExecutor.Do(ctx, req, &authorizationServer) if err != nil { return nil, resp, err } @@ -94,7 +95,7 @@ func (m *AuthorizationServerResource) UpdateAuthorizationServer(authServerId str return authorizationServer, resp, nil } -func (m *AuthorizationServerResource) DeleteAuthorizationServer(authServerId string) (*Response, error) { +func (m *AuthorizationServerResource) DeleteAuthorizationServer(ctx context.Context, authServerId string) (*Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -102,7 +103,7 @@ func (m *AuthorizationServerResource) DeleteAuthorizationServer(authServerId str return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -110,7 +111,7 @@ func (m *AuthorizationServerResource) DeleteAuthorizationServer(authServerId str return resp, nil } -func (m *AuthorizationServerResource) ListAuthorizationServers(qp *query.Params) ([]*AuthorizationServer, *Response, error) { +func (m *AuthorizationServerResource) ListAuthorizationServers(ctx context.Context, qp *query.Params) ([]*AuthorizationServer, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers") if qp != nil { url = url + qp.String() @@ -123,7 +124,7 @@ func (m *AuthorizationServerResource) ListAuthorizationServers(qp *query.Params) var authorizationServer []*AuthorizationServer - resp, err := m.client.requestExecutor.Do(req, &authorizationServer) + resp, err := m.client.requestExecutor.Do(ctx, req, &authorizationServer) if err != nil { return nil, resp, err } @@ -131,7 +132,7 @@ func (m *AuthorizationServerResource) ListAuthorizationServers(qp *query.Params) return authorizationServer, resp, nil } -func (m *AuthorizationServerResource) ListOAuth2Claims(authServerId string) ([]*OAuth2Claim, *Response, error) { +func (m *AuthorizationServerResource) ListOAuth2Claims(ctx context.Context, authServerId string) ([]*OAuth2Claim, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/claims", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -141,7 +142,7 @@ func (m *AuthorizationServerResource) ListOAuth2Claims(authServerId string) ([]* var oAuth2Claim []*OAuth2Claim - resp, err := m.client.requestExecutor.Do(req, &oAuth2Claim) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Claim) if err != nil { return nil, resp, err } @@ -149,7 +150,7 @@ func (m *AuthorizationServerResource) ListOAuth2Claims(authServerId string) ([]* return oAuth2Claim, resp, nil } -func (m *AuthorizationServerResource) CreateOAuth2Claim(authServerId string, body OAuth2Claim) (*OAuth2Claim, *Response, error) { +func (m *AuthorizationServerResource) CreateOAuth2Claim(ctx context.Context, authServerId string, body OAuth2Claim) (*OAuth2Claim, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/claims", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -159,7 +160,7 @@ func (m *AuthorizationServerResource) CreateOAuth2Claim(authServerId string, bod var oAuth2Claim *OAuth2Claim - resp, err := m.client.requestExecutor.Do(req, &oAuth2Claim) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Claim) if err != nil { return nil, resp, err } @@ -167,7 +168,7 @@ func (m *AuthorizationServerResource) CreateOAuth2Claim(authServerId string, bod return oAuth2Claim, resp, nil } -func (m *AuthorizationServerResource) DeleteOAuth2Claim(authServerId string, claimId string) (*Response, error) { +func (m *AuthorizationServerResource) DeleteOAuth2Claim(ctx context.Context, authServerId string, claimId string) (*Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/claims/%v", authServerId, claimId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -175,7 +176,7 @@ func (m *AuthorizationServerResource) DeleteOAuth2Claim(authServerId string, cla return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -183,7 +184,7 @@ func (m *AuthorizationServerResource) DeleteOAuth2Claim(authServerId string, cla return resp, nil } -func (m *AuthorizationServerResource) GetOAuth2Claim(authServerId string, claimId string) (*OAuth2Claim, *Response, error) { +func (m *AuthorizationServerResource) GetOAuth2Claim(ctx context.Context, authServerId string, claimId string) (*OAuth2Claim, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/claims/%v", authServerId, claimId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -193,7 +194,7 @@ func (m *AuthorizationServerResource) GetOAuth2Claim(authServerId string, claimI var oAuth2Claim *OAuth2Claim - resp, err := m.client.requestExecutor.Do(req, &oAuth2Claim) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Claim) if err != nil { return nil, resp, err } @@ -201,7 +202,7 @@ func (m *AuthorizationServerResource) GetOAuth2Claim(authServerId string, claimI return oAuth2Claim, resp, nil } -func (m *AuthorizationServerResource) UpdateOAuth2Claim(authServerId string, claimId string, body OAuth2Claim) (*OAuth2Claim, *Response, error) { +func (m *AuthorizationServerResource) UpdateOAuth2Claim(ctx context.Context, authServerId string, claimId string, body OAuth2Claim) (*OAuth2Claim, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/claims/%v", authServerId, claimId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -211,7 +212,7 @@ func (m *AuthorizationServerResource) UpdateOAuth2Claim(authServerId string, cla var oAuth2Claim *OAuth2Claim - resp, err := m.client.requestExecutor.Do(req, &oAuth2Claim) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Claim) if err != nil { return nil, resp, err } @@ -219,7 +220,7 @@ func (m *AuthorizationServerResource) UpdateOAuth2Claim(authServerId string, cla return oAuth2Claim, resp, nil } -func (m *AuthorizationServerResource) ListOAuth2ClientsForAuthorizationServer(authServerId string) ([]*OAuth2Client, *Response, error) { +func (m *AuthorizationServerResource) ListOAuth2ClientsForAuthorizationServer(ctx context.Context, authServerId string) ([]*OAuth2Client, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/clients", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -229,7 +230,7 @@ func (m *AuthorizationServerResource) ListOAuth2ClientsForAuthorizationServer(au var oAuth2Client []*OAuth2Client - resp, err := m.client.requestExecutor.Do(req, &oAuth2Client) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Client) if err != nil { return nil, resp, err } @@ -237,7 +238,7 @@ func (m *AuthorizationServerResource) ListOAuth2ClientsForAuthorizationServer(au return oAuth2Client, resp, nil } -func (m *AuthorizationServerResource) RevokeRefreshTokensForAuthorizationServerAndClient(authServerId string, clientId string) (*Response, error) { +func (m *AuthorizationServerResource) RevokeRefreshTokensForAuthorizationServerAndClient(ctx context.Context, authServerId string, clientId string) (*Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/clients/%v/tokens", authServerId, clientId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -245,7 +246,7 @@ func (m *AuthorizationServerResource) RevokeRefreshTokensForAuthorizationServerA return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -253,7 +254,7 @@ func (m *AuthorizationServerResource) RevokeRefreshTokensForAuthorizationServerA return resp, nil } -func (m *AuthorizationServerResource) ListRefreshTokensForAuthorizationServerAndClient(authServerId string, clientId string, qp *query.Params) ([]*OAuth2RefreshToken, *Response, error) { +func (m *AuthorizationServerResource) ListRefreshTokensForAuthorizationServerAndClient(ctx context.Context, authServerId string, clientId string, qp *query.Params) ([]*OAuth2RefreshToken, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/clients/%v/tokens", authServerId, clientId) if qp != nil { url = url + qp.String() @@ -266,7 +267,7 @@ func (m *AuthorizationServerResource) ListRefreshTokensForAuthorizationServerAnd var oAuth2RefreshToken []*OAuth2RefreshToken - resp, err := m.client.requestExecutor.Do(req, &oAuth2RefreshToken) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2RefreshToken) if err != nil { return nil, resp, err } @@ -274,7 +275,7 @@ func (m *AuthorizationServerResource) ListRefreshTokensForAuthorizationServerAnd return oAuth2RefreshToken, resp, nil } -func (m *AuthorizationServerResource) RevokeRefreshTokenForAuthorizationServerAndClient(authServerId string, clientId string, tokenId string) (*Response, error) { +func (m *AuthorizationServerResource) RevokeRefreshTokenForAuthorizationServerAndClient(ctx context.Context, authServerId string, clientId string, tokenId string) (*Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/clients/%v/tokens/%v", authServerId, clientId, tokenId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -282,7 +283,7 @@ func (m *AuthorizationServerResource) RevokeRefreshTokenForAuthorizationServerAn return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -290,7 +291,7 @@ func (m *AuthorizationServerResource) RevokeRefreshTokenForAuthorizationServerAn return resp, nil } -func (m *AuthorizationServerResource) GetRefreshTokenForAuthorizationServerAndClient(authServerId string, clientId string, tokenId string, qp *query.Params) (*OAuth2RefreshToken, *Response, error) { +func (m *AuthorizationServerResource) GetRefreshTokenForAuthorizationServerAndClient(ctx context.Context, authServerId string, clientId string, tokenId string, qp *query.Params) (*OAuth2RefreshToken, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/clients/%v/tokens/%v", authServerId, clientId, tokenId) if qp != nil { url = url + qp.String() @@ -303,7 +304,7 @@ func (m *AuthorizationServerResource) GetRefreshTokenForAuthorizationServerAndCl var oAuth2RefreshToken *OAuth2RefreshToken - resp, err := m.client.requestExecutor.Do(req, &oAuth2RefreshToken) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2RefreshToken) if err != nil { return nil, resp, err } @@ -311,7 +312,7 @@ func (m *AuthorizationServerResource) GetRefreshTokenForAuthorizationServerAndCl return oAuth2RefreshToken, resp, nil } -func (m *AuthorizationServerResource) ListAuthorizationServerKeys(authServerId string) ([]*JsonWebKey, *Response, error) { +func (m *AuthorizationServerResource) ListAuthorizationServerKeys(ctx context.Context, authServerId string) ([]*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/credentials/keys", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -321,7 +322,7 @@ func (m *AuthorizationServerResource) ListAuthorizationServerKeys(authServerId s var jsonWebKey []*JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -329,7 +330,7 @@ func (m *AuthorizationServerResource) ListAuthorizationServerKeys(authServerId s return jsonWebKey, resp, nil } -func (m *AuthorizationServerResource) RotateAuthorizationServerKeys(authServerId string, body JwkUse) ([]*JsonWebKey, *Response, error) { +func (m *AuthorizationServerResource) RotateAuthorizationServerKeys(ctx context.Context, authServerId string, body JwkUse) ([]*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/credentials/lifecycle/keyRotate", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -339,7 +340,7 @@ func (m *AuthorizationServerResource) RotateAuthorizationServerKeys(authServerId var jsonWebKey []*JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -347,7 +348,7 @@ func (m *AuthorizationServerResource) RotateAuthorizationServerKeys(authServerId return jsonWebKey, resp, nil } -func (m *AuthorizationServerResource) ActivateAuthorizationServer(authServerId string) (*Response, error) { +func (m *AuthorizationServerResource) ActivateAuthorizationServer(ctx context.Context, authServerId string) (*Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/lifecycle/activate", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -355,7 +356,7 @@ func (m *AuthorizationServerResource) ActivateAuthorizationServer(authServerId s return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -363,7 +364,7 @@ func (m *AuthorizationServerResource) ActivateAuthorizationServer(authServerId s return resp, nil } -func (m *AuthorizationServerResource) DeactivateAuthorizationServer(authServerId string) (*Response, error) { +func (m *AuthorizationServerResource) DeactivateAuthorizationServer(ctx context.Context, authServerId string) (*Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/lifecycle/deactivate", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -371,7 +372,7 @@ func (m *AuthorizationServerResource) DeactivateAuthorizationServer(authServerId return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -379,7 +380,7 @@ func (m *AuthorizationServerResource) DeactivateAuthorizationServer(authServerId return resp, nil } -func (m *AuthorizationServerResource) ListAuthorizationServerPolicies(authServerId string) ([]*Policy, *Response, error) { +func (m *AuthorizationServerResource) ListAuthorizationServerPolicies(ctx context.Context, authServerId string) ([]*Policy, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/policies", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -389,7 +390,7 @@ func (m *AuthorizationServerResource) ListAuthorizationServerPolicies(authServer var policy []*Policy - resp, err := m.client.requestExecutor.Do(req, &policy) + resp, err := m.client.requestExecutor.Do(ctx, req, &policy) if err != nil { return nil, resp, err } @@ -397,7 +398,7 @@ func (m *AuthorizationServerResource) ListAuthorizationServerPolicies(authServer return policy, resp, nil } -func (m *AuthorizationServerResource) CreateAuthorizationServerPolicy(authServerId string, body Policy) (*Policy, *Response, error) { +func (m *AuthorizationServerResource) CreateAuthorizationServerPolicy(ctx context.Context, authServerId string, body Policy) (*Policy, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/policies", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -407,7 +408,7 @@ func (m *AuthorizationServerResource) CreateAuthorizationServerPolicy(authServer var policy *Policy - resp, err := m.client.requestExecutor.Do(req, &policy) + resp, err := m.client.requestExecutor.Do(ctx, req, &policy) if err != nil { return nil, resp, err } @@ -415,7 +416,7 @@ func (m *AuthorizationServerResource) CreateAuthorizationServerPolicy(authServer return policy, resp, nil } -func (m *AuthorizationServerResource) DeleteAuthorizationServerPolicy(authServerId string, policyId string) (*Response, error) { +func (m *AuthorizationServerResource) DeleteAuthorizationServerPolicy(ctx context.Context, authServerId string, policyId string) (*Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/policies/%v", authServerId, policyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -423,7 +424,7 @@ func (m *AuthorizationServerResource) DeleteAuthorizationServerPolicy(authServer return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -431,7 +432,7 @@ func (m *AuthorizationServerResource) DeleteAuthorizationServerPolicy(authServer return resp, nil } -func (m *AuthorizationServerResource) GetAuthorizationServerPolicy(authServerId string, policyId string) (*Policy, *Response, error) { +func (m *AuthorizationServerResource) GetAuthorizationServerPolicy(ctx context.Context, authServerId string, policyId string) (*Policy, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/policies/%v", authServerId, policyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -441,7 +442,7 @@ func (m *AuthorizationServerResource) GetAuthorizationServerPolicy(authServerId var policy *Policy - resp, err := m.client.requestExecutor.Do(req, &policy) + resp, err := m.client.requestExecutor.Do(ctx, req, &policy) if err != nil { return nil, resp, err } @@ -449,7 +450,7 @@ func (m *AuthorizationServerResource) GetAuthorizationServerPolicy(authServerId return policy, resp, nil } -func (m *AuthorizationServerResource) UpdateAuthorizationServerPolicy(authServerId string, policyId string, body Policy) (*Policy, *Response, error) { +func (m *AuthorizationServerResource) UpdateAuthorizationServerPolicy(ctx context.Context, authServerId string, policyId string, body Policy) (*Policy, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/policies/%v", authServerId, policyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -459,7 +460,7 @@ func (m *AuthorizationServerResource) UpdateAuthorizationServerPolicy(authServer var policy *Policy - resp, err := m.client.requestExecutor.Do(req, &policy) + resp, err := m.client.requestExecutor.Do(ctx, req, &policy) if err != nil { return nil, resp, err } @@ -467,7 +468,7 @@ func (m *AuthorizationServerResource) UpdateAuthorizationServerPolicy(authServer return policy, resp, nil } -func (m *AuthorizationServerResource) ListOAuth2Scopes(authServerId string, qp *query.Params) ([]*OAuth2Scope, *Response, error) { +func (m *AuthorizationServerResource) ListOAuth2Scopes(ctx context.Context, authServerId string, qp *query.Params) ([]*OAuth2Scope, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/scopes", authServerId) if qp != nil { url = url + qp.String() @@ -480,7 +481,7 @@ func (m *AuthorizationServerResource) ListOAuth2Scopes(authServerId string, qp * var oAuth2Scope []*OAuth2Scope - resp, err := m.client.requestExecutor.Do(req, &oAuth2Scope) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Scope) if err != nil { return nil, resp, err } @@ -488,7 +489,7 @@ func (m *AuthorizationServerResource) ListOAuth2Scopes(authServerId string, qp * return oAuth2Scope, resp, nil } -func (m *AuthorizationServerResource) CreateOAuth2Scope(authServerId string, body OAuth2Scope) (*OAuth2Scope, *Response, error) { +func (m *AuthorizationServerResource) CreateOAuth2Scope(ctx context.Context, authServerId string, body OAuth2Scope) (*OAuth2Scope, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/scopes", authServerId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -498,7 +499,7 @@ func (m *AuthorizationServerResource) CreateOAuth2Scope(authServerId string, bod var oAuth2Scope *OAuth2Scope - resp, err := m.client.requestExecutor.Do(req, &oAuth2Scope) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Scope) if err != nil { return nil, resp, err } @@ -506,7 +507,7 @@ func (m *AuthorizationServerResource) CreateOAuth2Scope(authServerId string, bod return oAuth2Scope, resp, nil } -func (m *AuthorizationServerResource) DeleteOAuth2Scope(authServerId string, scopeId string) (*Response, error) { +func (m *AuthorizationServerResource) DeleteOAuth2Scope(ctx context.Context, authServerId string, scopeId string) (*Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/scopes/%v", authServerId, scopeId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -514,7 +515,7 @@ func (m *AuthorizationServerResource) DeleteOAuth2Scope(authServerId string, sco return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -522,7 +523,7 @@ func (m *AuthorizationServerResource) DeleteOAuth2Scope(authServerId string, sco return resp, nil } -func (m *AuthorizationServerResource) GetOAuth2Scope(authServerId string, scopeId string) (*OAuth2Scope, *Response, error) { +func (m *AuthorizationServerResource) GetOAuth2Scope(ctx context.Context, authServerId string, scopeId string) (*OAuth2Scope, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/scopes/%v", authServerId, scopeId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -532,7 +533,7 @@ func (m *AuthorizationServerResource) GetOAuth2Scope(authServerId string, scopeI var oAuth2Scope *OAuth2Scope - resp, err := m.client.requestExecutor.Do(req, &oAuth2Scope) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Scope) if err != nil { return nil, resp, err } @@ -540,7 +541,7 @@ func (m *AuthorizationServerResource) GetOAuth2Scope(authServerId string, scopeI return oAuth2Scope, resp, nil } -func (m *AuthorizationServerResource) UpdateOAuth2Scope(authServerId string, scopeId string, body OAuth2Scope) (*OAuth2Scope, *Response, error) { +func (m *AuthorizationServerResource) UpdateOAuth2Scope(ctx context.Context, authServerId string, scopeId string, body OAuth2Scope) (*OAuth2Scope, *Response, error) { url := fmt.Sprintf("/api/v1/authorizationServers/%v/scopes/%v", authServerId, scopeId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -550,7 +551,7 @@ func (m *AuthorizationServerResource) UpdateOAuth2Scope(authServerId string, sco var oAuth2Scope *OAuth2Scope - resp, err := m.client.requestExecutor.Do(req, &oAuth2Scope) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Scope) if err != nil { return nil, resp, err } diff --git a/okta/eventHook.go b/okta/eventHook.go index c145c9a4f..6f5fcb98a 100644 --- a/okta/eventHook.go +++ b/okta/eventHook.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "time" ) @@ -38,7 +39,7 @@ type EventHook struct { VerificationStatus string `json:"verificationStatus,omitempty"` } -func (m *EventHookResource) CreateEventHook(body EventHook) (*EventHook, *Response, error) { +func (m *EventHookResource) CreateEventHook(ctx context.Context, body EventHook) (*EventHook, *Response, error) { url := fmt.Sprintf("/api/v1/eventHooks") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -48,7 +49,7 @@ func (m *EventHookResource) CreateEventHook(body EventHook) (*EventHook, *Respon var eventHook *EventHook - resp, err := m.client.requestExecutor.Do(req, &eventHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &eventHook) if err != nil { return nil, resp, err } @@ -56,7 +57,7 @@ func (m *EventHookResource) CreateEventHook(body EventHook) (*EventHook, *Respon return eventHook, resp, nil } -func (m *EventHookResource) GetEventHook(eventHookId string) (*EventHook, *Response, error) { +func (m *EventHookResource) GetEventHook(ctx context.Context, eventHookId string) (*EventHook, *Response, error) { url := fmt.Sprintf("/api/v1/eventHooks/%v", eventHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -66,7 +67,7 @@ func (m *EventHookResource) GetEventHook(eventHookId string) (*EventHook, *Respo var eventHook *EventHook - resp, err := m.client.requestExecutor.Do(req, &eventHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &eventHook) if err != nil { return nil, resp, err } @@ -74,7 +75,7 @@ func (m *EventHookResource) GetEventHook(eventHookId string) (*EventHook, *Respo return eventHook, resp, nil } -func (m *EventHookResource) UpdateEventHook(eventHookId string, body EventHook) (*EventHook, *Response, error) { +func (m *EventHookResource) UpdateEventHook(ctx context.Context, eventHookId string, body EventHook) (*EventHook, *Response, error) { url := fmt.Sprintf("/api/v1/eventHooks/%v", eventHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -84,7 +85,7 @@ func (m *EventHookResource) UpdateEventHook(eventHookId string, body EventHook) var eventHook *EventHook - resp, err := m.client.requestExecutor.Do(req, &eventHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &eventHook) if err != nil { return nil, resp, err } @@ -92,7 +93,7 @@ func (m *EventHookResource) UpdateEventHook(eventHookId string, body EventHook) return eventHook, resp, nil } -func (m *EventHookResource) DeleteEventHook(eventHookId string) (*Response, error) { +func (m *EventHookResource) DeleteEventHook(ctx context.Context, eventHookId string) (*Response, error) { url := fmt.Sprintf("/api/v1/eventHooks/%v", eventHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -100,7 +101,7 @@ func (m *EventHookResource) DeleteEventHook(eventHookId string) (*Response, erro return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -108,7 +109,7 @@ func (m *EventHookResource) DeleteEventHook(eventHookId string) (*Response, erro return resp, nil } -func (m *EventHookResource) ListEventHooks() ([]*EventHook, *Response, error) { +func (m *EventHookResource) ListEventHooks(ctx context.Context) ([]*EventHook, *Response, error) { url := fmt.Sprintf("/api/v1/eventHooks") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -118,7 +119,7 @@ func (m *EventHookResource) ListEventHooks() ([]*EventHook, *Response, error) { var eventHook []*EventHook - resp, err := m.client.requestExecutor.Do(req, &eventHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &eventHook) if err != nil { return nil, resp, err } @@ -126,7 +127,7 @@ func (m *EventHookResource) ListEventHooks() ([]*EventHook, *Response, error) { return eventHook, resp, nil } -func (m *EventHookResource) ActivateEventHook(eventHookId string) (*EventHook, *Response, error) { +func (m *EventHookResource) ActivateEventHook(ctx context.Context, eventHookId string) (*EventHook, *Response, error) { url := fmt.Sprintf("/api/v1/eventHooks/%v/lifecycle/activate", eventHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -136,7 +137,7 @@ func (m *EventHookResource) ActivateEventHook(eventHookId string) (*EventHook, * var eventHook *EventHook - resp, err := m.client.requestExecutor.Do(req, &eventHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &eventHook) if err != nil { return nil, resp, err } @@ -144,7 +145,7 @@ func (m *EventHookResource) ActivateEventHook(eventHookId string) (*EventHook, * return eventHook, resp, nil } -func (m *EventHookResource) DeactivateEventHook(eventHookId string) (*EventHook, *Response, error) { +func (m *EventHookResource) DeactivateEventHook(ctx context.Context, eventHookId string) (*EventHook, *Response, error) { url := fmt.Sprintf("/api/v1/eventHooks/%v/lifecycle/deactivate", eventHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -154,7 +155,7 @@ func (m *EventHookResource) DeactivateEventHook(eventHookId string) (*EventHook, var eventHook *EventHook - resp, err := m.client.requestExecutor.Do(req, &eventHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &eventHook) if err != nil { return nil, resp, err } @@ -162,7 +163,7 @@ func (m *EventHookResource) DeactivateEventHook(eventHookId string) (*EventHook, return eventHook, resp, nil } -func (m *EventHookResource) VerifyEventHook(eventHookId string) (*EventHook, *Response, error) { +func (m *EventHookResource) VerifyEventHook(ctx context.Context, eventHookId string) (*EventHook, *Response, error) { url := fmt.Sprintf("/api/v1/eventHooks/%v/lifecycle/verify", eventHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -172,7 +173,7 @@ func (m *EventHookResource) VerifyEventHook(eventHookId string) (*EventHook, *Re var eventHook *EventHook - resp, err := m.client.requestExecutor.Do(req, &eventHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &eventHook) if err != nil { return nil, resp, err } diff --git a/okta/feature.go b/okta/feature.go index 100ae30a3..11cbce48e 100644 --- a/okta/feature.go +++ b/okta/feature.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" ) @@ -35,7 +36,7 @@ type Feature struct { Type string `json:"type,omitempty"` } -func (m *FeatureResource) GetFeature(featureId string) (*Feature, *Response, error) { +func (m *FeatureResource) GetFeature(ctx context.Context, featureId string) (*Feature, *Response, error) { url := fmt.Sprintf("/api/v1/features/%v", featureId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -45,7 +46,7 @@ func (m *FeatureResource) GetFeature(featureId string) (*Feature, *Response, err var feature *Feature - resp, err := m.client.requestExecutor.Do(req, &feature) + resp, err := m.client.requestExecutor.Do(ctx, req, &feature) if err != nil { return nil, resp, err } @@ -53,7 +54,7 @@ func (m *FeatureResource) GetFeature(featureId string) (*Feature, *Response, err return feature, resp, nil } -func (m *FeatureResource) ListFeatures() ([]*Feature, *Response, error) { +func (m *FeatureResource) ListFeatures(ctx context.Context) ([]*Feature, *Response, error) { url := fmt.Sprintf("/api/v1/features") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -63,7 +64,7 @@ func (m *FeatureResource) ListFeatures() ([]*Feature, *Response, error) { var feature []*Feature - resp, err := m.client.requestExecutor.Do(req, &feature) + resp, err := m.client.requestExecutor.Do(ctx, req, &feature) if err != nil { return nil, resp, err } @@ -71,7 +72,7 @@ func (m *FeatureResource) ListFeatures() ([]*Feature, *Response, error) { return feature, resp, nil } -func (m *FeatureResource) ListFeatureDependencies(featureId string) ([]*Feature, *Response, error) { +func (m *FeatureResource) ListFeatureDependencies(ctx context.Context, featureId string) ([]*Feature, *Response, error) { url := fmt.Sprintf("/api/v1/features/%v/dependencies", featureId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -81,7 +82,7 @@ func (m *FeatureResource) ListFeatureDependencies(featureId string) ([]*Feature, var feature []*Feature - resp, err := m.client.requestExecutor.Do(req, &feature) + resp, err := m.client.requestExecutor.Do(ctx, req, &feature) if err != nil { return nil, resp, err } @@ -89,7 +90,7 @@ func (m *FeatureResource) ListFeatureDependencies(featureId string) ([]*Feature, return feature, resp, nil } -func (m *FeatureResource) ListFeatureDependents(featureId string) ([]*Feature, *Response, error) { +func (m *FeatureResource) ListFeatureDependents(ctx context.Context, featureId string) ([]*Feature, *Response, error) { url := fmt.Sprintf("/api/v1/features/%v/dependents", featureId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -99,7 +100,7 @@ func (m *FeatureResource) ListFeatureDependents(featureId string) ([]*Feature, * var feature []*Feature - resp, err := m.client.requestExecutor.Do(req, &feature) + resp, err := m.client.requestExecutor.Do(ctx, req, &feature) if err != nil { return nil, resp, err } @@ -107,7 +108,7 @@ func (m *FeatureResource) ListFeatureDependents(featureId string) ([]*Feature, * return feature, resp, nil } -func (m *FeatureResource) UpdateFeatureLifecycle(featureId string, lifecycle string, qp *query.Params) (*Feature, *Response, error) { +func (m *FeatureResource) UpdateFeatureLifecycle(ctx context.Context, featureId string, lifecycle string, qp *query.Params) (*Feature, *Response, error) { url := fmt.Sprintf("/api/v1/features/%v/%v", featureId, lifecycle) if qp != nil { url = url + qp.String() @@ -120,7 +121,7 @@ func (m *FeatureResource) UpdateFeatureLifecycle(featureId string, lifecycle str var feature *Feature - resp, err := m.client.requestExecutor.Do(req, &feature) + resp, err := m.client.requestExecutor.Do(ctx, req, &feature) if err != nil { return nil, resp, err } diff --git a/okta/group.go b/okta/group.go index 6604e027a..9e07ce20c 100644 --- a/okta/group.go +++ b/okta/group.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -39,7 +40,7 @@ type Group struct { } // Updates the profile for a group with `OKTA_GROUP` type from your organization. -func (m *GroupResource) UpdateGroup(groupId string, body Group) (*Group, *Response, error) { +func (m *GroupResource) UpdateGroup(ctx context.Context, groupId string, body Group) (*Group, *Response, error) { url := fmt.Sprintf("/api/v1/groups/%v", groupId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -49,7 +50,7 @@ func (m *GroupResource) UpdateGroup(groupId string, body Group) (*Group, *Respon var group *Group - resp, err := m.client.requestExecutor.Do(req, &group) + resp, err := m.client.requestExecutor.Do(ctx, req, &group) if err != nil { return nil, resp, err } @@ -58,7 +59,7 @@ func (m *GroupResource) UpdateGroup(groupId string, body Group) (*Group, *Respon } // Removes a group with `OKTA_GROUP` type from your organization. -func (m *GroupResource) DeleteGroup(groupId string) (*Response, error) { +func (m *GroupResource) DeleteGroup(ctx context.Context, groupId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/%v", groupId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -66,7 +67,7 @@ func (m *GroupResource) DeleteGroup(groupId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -75,7 +76,7 @@ func (m *GroupResource) DeleteGroup(groupId string) (*Response, error) { } // Enumerates groups in your organization with pagination. A subset of groups can be returned that match a supported filter expression or query. -func (m *GroupResource) ListGroups(qp *query.Params) ([]*Group, *Response, error) { +func (m *GroupResource) ListGroups(ctx context.Context, qp *query.Params) ([]*Group, *Response, error) { url := fmt.Sprintf("/api/v1/groups") if qp != nil { url = url + qp.String() @@ -88,7 +89,7 @@ func (m *GroupResource) ListGroups(qp *query.Params) ([]*Group, *Response, error var group []*Group - resp, err := m.client.requestExecutor.Do(req, &group) + resp, err := m.client.requestExecutor.Do(ctx, req, &group) if err != nil { return nil, resp, err } @@ -97,7 +98,7 @@ func (m *GroupResource) ListGroups(qp *query.Params) ([]*Group, *Response, error } // Adds a new group with `OKTA_GROUP` type to your organization. -func (m *GroupResource) CreateGroup(body Group) (*Group, *Response, error) { +func (m *GroupResource) CreateGroup(ctx context.Context, body Group) (*Group, *Response, error) { url := fmt.Sprintf("/api/v1/groups") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -107,7 +108,7 @@ func (m *GroupResource) CreateGroup(body Group) (*Group, *Response, error) { var group *Group - resp, err := m.client.requestExecutor.Do(req, &group) + resp, err := m.client.requestExecutor.Do(ctx, req, &group) if err != nil { return nil, resp, err } @@ -116,7 +117,7 @@ func (m *GroupResource) CreateGroup(body Group) (*Group, *Response, error) { } // Lists all group rules for your organization. -func (m *GroupResource) ListGroupRules(qp *query.Params) ([]*GroupRule, *Response, error) { +func (m *GroupResource) ListGroupRules(ctx context.Context, qp *query.Params) ([]*GroupRule, *Response, error) { url := fmt.Sprintf("/api/v1/groups/rules") if qp != nil { url = url + qp.String() @@ -129,7 +130,7 @@ func (m *GroupResource) ListGroupRules(qp *query.Params) ([]*GroupRule, *Respons var groupRule []*GroupRule - resp, err := m.client.requestExecutor.Do(req, &groupRule) + resp, err := m.client.requestExecutor.Do(ctx, req, &groupRule) if err != nil { return nil, resp, err } @@ -138,7 +139,7 @@ func (m *GroupResource) ListGroupRules(qp *query.Params) ([]*GroupRule, *Respons } // Creates a group rule to dynamically add users to the specified group if they match the condition -func (m *GroupResource) CreateGroupRule(body GroupRule) (*GroupRule, *Response, error) { +func (m *GroupResource) CreateGroupRule(ctx context.Context, body GroupRule) (*GroupRule, *Response, error) { url := fmt.Sprintf("/api/v1/groups/rules") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -148,7 +149,7 @@ func (m *GroupResource) CreateGroupRule(body GroupRule) (*GroupRule, *Response, var groupRule *GroupRule - resp, err := m.client.requestExecutor.Do(req, &groupRule) + resp, err := m.client.requestExecutor.Do(ctx, req, &groupRule) if err != nil { return nil, resp, err } @@ -157,7 +158,7 @@ func (m *GroupResource) CreateGroupRule(body GroupRule) (*GroupRule, *Response, } // Removes a specific group rule by id from your organization -func (m *GroupResource) DeleteGroupRule(ruleId string) (*Response, error) { +func (m *GroupResource) DeleteGroupRule(ctx context.Context, ruleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/rules/%v", ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -165,7 +166,7 @@ func (m *GroupResource) DeleteGroupRule(ruleId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -174,7 +175,7 @@ func (m *GroupResource) DeleteGroupRule(ruleId string) (*Response, error) { } // Fetches a specific group rule by id from your organization -func (m *GroupResource) GetGroupRule(ruleId string, qp *query.Params) (*GroupRule, *Response, error) { +func (m *GroupResource) GetGroupRule(ctx context.Context, ruleId string, qp *query.Params) (*GroupRule, *Response, error) { url := fmt.Sprintf("/api/v1/groups/rules/%v", ruleId) if qp != nil { url = url + qp.String() @@ -187,7 +188,7 @@ func (m *GroupResource) GetGroupRule(ruleId string, qp *query.Params) (*GroupRul var groupRule *GroupRule - resp, err := m.client.requestExecutor.Do(req, &groupRule) + resp, err := m.client.requestExecutor.Do(ctx, req, &groupRule) if err != nil { return nil, resp, err } @@ -196,7 +197,7 @@ func (m *GroupResource) GetGroupRule(ruleId string, qp *query.Params) (*GroupRul } // Updates a group rule. Only `INACTIVE` rules can be updated. -func (m *GroupResource) UpdateGroupRule(ruleId string, body GroupRule) (*GroupRule, *Response, error) { +func (m *GroupResource) UpdateGroupRule(ctx context.Context, ruleId string, body GroupRule) (*GroupRule, *Response, error) { url := fmt.Sprintf("/api/v1/groups/rules/%v", ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -206,7 +207,7 @@ func (m *GroupResource) UpdateGroupRule(ruleId string, body GroupRule) (*GroupRu var groupRule *GroupRule - resp, err := m.client.requestExecutor.Do(req, &groupRule) + resp, err := m.client.requestExecutor.Do(ctx, req, &groupRule) if err != nil { return nil, resp, err } @@ -215,7 +216,7 @@ func (m *GroupResource) UpdateGroupRule(ruleId string, body GroupRule) (*GroupRu } // Activates a specific group rule by id from your organization -func (m *GroupResource) ActivateGroupRule(ruleId string) (*Response, error) { +func (m *GroupResource) ActivateGroupRule(ctx context.Context, ruleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/rules/%v/lifecycle/activate", ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -223,7 +224,7 @@ func (m *GroupResource) ActivateGroupRule(ruleId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -232,7 +233,7 @@ func (m *GroupResource) ActivateGroupRule(ruleId string) (*Response, error) { } // Deactivates a specific group rule by id from your organization -func (m *GroupResource) DeactivateGroupRule(ruleId string) (*Response, error) { +func (m *GroupResource) DeactivateGroupRule(ctx context.Context, ruleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/rules/%v/lifecycle/deactivate", ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -240,7 +241,7 @@ func (m *GroupResource) DeactivateGroupRule(ruleId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -249,7 +250,7 @@ func (m *GroupResource) DeactivateGroupRule(ruleId string) (*Response, error) { } // Lists all group rules for your organization. -func (m *GroupResource) GetGroup(groupId string) (*Group, *Response, error) { +func (m *GroupResource) GetGroup(ctx context.Context, groupId string) (*Group, *Response, error) { url := fmt.Sprintf("/api/v1/groups/%v", groupId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -259,7 +260,7 @@ func (m *GroupResource) GetGroup(groupId string) (*Group, *Response, error) { var group *Group - resp, err := m.client.requestExecutor.Do(req, &group) + resp, err := m.client.requestExecutor.Do(ctx, req, &group) if err != nil { return nil, resp, err } @@ -268,7 +269,7 @@ func (m *GroupResource) GetGroup(groupId string) (*Group, *Response, error) { } // Enumerates all applications that are assigned to a group. -func (m *GroupResource) ListAssignedApplicationsForGroup(groupId string, qp *query.Params) ([]App, *Response, error) { +func (m *GroupResource) ListAssignedApplicationsForGroup(ctx context.Context, groupId string, qp *query.Params) ([]App, *Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/apps", groupId) if qp != nil { url = url + qp.String() @@ -281,7 +282,7 @@ func (m *GroupResource) ListAssignedApplicationsForGroup(groupId string, qp *que var application []Application - resp, err := m.client.requestExecutor.Do(req, &application) + resp, err := m.client.requestExecutor.Do(ctx, req, &application) if err != nil { return nil, resp, err } @@ -294,7 +295,7 @@ func (m *GroupResource) ListAssignedApplicationsForGroup(groupId string, qp *que } -func (m *GroupResource) ListGroupAssignedRoles(groupId string, qp *query.Params) ([]*Role, *Response, error) { +func (m *GroupResource) ListGroupAssignedRoles(ctx context.Context, groupId string, qp *query.Params) ([]*Role, *Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles", groupId) if qp != nil { url = url + qp.String() @@ -307,7 +308,7 @@ func (m *GroupResource) ListGroupAssignedRoles(groupId string, qp *query.Params) var role []*Role - resp, err := m.client.requestExecutor.Do(req, &role) + resp, err := m.client.requestExecutor.Do(ctx, req, &role) if err != nil { return nil, resp, err } @@ -316,7 +317,7 @@ func (m *GroupResource) ListGroupAssignedRoles(groupId string, qp *query.Params) } // Assigns a Role to a Group -func (m *GroupResource) AssignRoleToGroup(groupId string, body AssignRoleRequest, qp *query.Params) (*Role, *Response, error) { +func (m *GroupResource) AssignRoleToGroup(ctx context.Context, groupId string, body AssignRoleRequest, qp *query.Params) (*Role, *Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles", groupId) if qp != nil { url = url + qp.String() @@ -329,7 +330,7 @@ func (m *GroupResource) AssignRoleToGroup(groupId string, body AssignRoleRequest var role *Role - resp, err := m.client.requestExecutor.Do(req, &role) + resp, err := m.client.requestExecutor.Do(ctx, req, &role) if err != nil { return nil, resp, err } @@ -338,7 +339,7 @@ func (m *GroupResource) AssignRoleToGroup(groupId string, body AssignRoleRequest } // Unassigns a Role from a Group -func (m *GroupResource) RemoveRoleFromGroup(groupId string, roleId string) (*Response, error) { +func (m *GroupResource) RemoveRoleFromGroup(ctx context.Context, groupId string, roleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles/%v", groupId, roleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -346,7 +347,7 @@ func (m *GroupResource) RemoveRoleFromGroup(groupId string, roleId string) (*Res return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -354,7 +355,7 @@ func (m *GroupResource) RemoveRoleFromGroup(groupId string, roleId string) (*Res return resp, nil } -func (m *GroupResource) GetRole(groupId string, roleId string) (*Role, *Response, error) { +func (m *GroupResource) GetRole(ctx context.Context, groupId string, roleId string) (*Role, *Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles/%v", groupId, roleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -364,7 +365,7 @@ func (m *GroupResource) GetRole(groupId string, roleId string) (*Role, *Response var role *Role - resp, err := m.client.requestExecutor.Do(req, &role) + resp, err := m.client.requestExecutor.Do(ctx, req, &role) if err != nil { return nil, resp, err } @@ -373,7 +374,7 @@ func (m *GroupResource) GetRole(groupId string, roleId string) (*Role, *Response } // Lists all App targets for an `APP_ADMIN` Role assigned to a Group. This methods return list may include full Applications or Instances. The response for an instance will have an `ID` value, while Application will not have an ID. -func (m *GroupResource) ListApplicationTargetsForApplicationAdministratorRoleForGroup(groupId string, roleId string, qp *query.Params) ([]App, *Response, error) { +func (m *GroupResource) ListApplicationTargetsForApplicationAdministratorRoleForGroup(ctx context.Context, groupId string, roleId string, qp *query.Params) ([]App, *Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles/%v/targets/catalog/apps", groupId, roleId) if qp != nil { url = url + qp.String() @@ -386,7 +387,7 @@ func (m *GroupResource) ListApplicationTargetsForApplicationAdministratorRoleFor var application []Application - resp, err := m.client.requestExecutor.Do(req, &application) + resp, err := m.client.requestExecutor.Do(ctx, req, &application) if err != nil { return nil, resp, err } @@ -399,7 +400,7 @@ func (m *GroupResource) ListApplicationTargetsForApplicationAdministratorRoleFor } -func (m *GroupResource) RemoveApplicationTargetFromApplicationAdministratorRoleGivenToGroup(groupId string, roleId string, appName string) (*Response, error) { +func (m *GroupResource) RemoveApplicationTargetFromApplicationAdministratorRoleGivenToGroup(ctx context.Context, groupId string, roleId string, appName string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles/%v/targets/catalog/apps/%v", groupId, roleId, appName) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -407,7 +408,7 @@ func (m *GroupResource) RemoveApplicationTargetFromApplicationAdministratorRoleG return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -415,7 +416,7 @@ func (m *GroupResource) RemoveApplicationTargetFromApplicationAdministratorRoleG return resp, nil } -func (m *GroupResource) AddApplicationTargetToAdminRoleGivenToGroup(groupId string, roleId string, appName string) (*Response, error) { +func (m *GroupResource) AddApplicationTargetToAdminRoleGivenToGroup(ctx context.Context, groupId string, roleId string, appName string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles/%v/targets/catalog/apps/%v", groupId, roleId, appName) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, nil) @@ -423,7 +424,7 @@ func (m *GroupResource) AddApplicationTargetToAdminRoleGivenToGroup(groupId stri return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -432,7 +433,7 @@ func (m *GroupResource) AddApplicationTargetToAdminRoleGivenToGroup(groupId stri } // Remove App Instance Target to App Administrator Role given to a Group -func (m *GroupResource) RemoveApplicationTargetFromAdministratorRoleGivenToGroup(groupId string, roleId string, appName string, applicationId string) (*Response, error) { +func (m *GroupResource) RemoveApplicationTargetFromAdministratorRoleGivenToGroup(ctx context.Context, groupId string, roleId string, appName string, applicationId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles/%v/targets/catalog/apps/%v/%v", groupId, roleId, appName, applicationId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -440,7 +441,7 @@ func (m *GroupResource) RemoveApplicationTargetFromAdministratorRoleGivenToGroup return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -449,7 +450,7 @@ func (m *GroupResource) RemoveApplicationTargetFromAdministratorRoleGivenToGroup } // Add App Instance Target to App Administrator Role given to a Group -func (m *GroupResource) AddApplicationInstanceTargetToAppAdminRoleGivenToGroup(groupId string, roleId string, appName string, applicationId string) (*Response, error) { +func (m *GroupResource) AddApplicationInstanceTargetToAppAdminRoleGivenToGroup(ctx context.Context, groupId string, roleId string, appName string, applicationId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles/%v/targets/catalog/apps/%v/%v", groupId, roleId, appName, applicationId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, nil) @@ -457,7 +458,7 @@ func (m *GroupResource) AddApplicationInstanceTargetToAppAdminRoleGivenToGroup(g return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -465,7 +466,7 @@ func (m *GroupResource) AddApplicationInstanceTargetToAppAdminRoleGivenToGroup(g return resp, nil } -func (m *GroupResource) ListGroupTargetsForGroupRole(groupId string, roleId string, qp *query.Params) ([]*Group, *Response, error) { +func (m *GroupResource) ListGroupTargetsForGroupRole(ctx context.Context, groupId string, roleId string, qp *query.Params) ([]*Group, *Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles/%v/targets/groups", groupId, roleId) if qp != nil { url = url + qp.String() @@ -478,7 +479,7 @@ func (m *GroupResource) ListGroupTargetsForGroupRole(groupId string, roleId stri var group []*Group - resp, err := m.client.requestExecutor.Do(req, &group) + resp, err := m.client.requestExecutor.Do(ctx, req, &group) if err != nil { return nil, resp, err } @@ -487,7 +488,7 @@ func (m *GroupResource) ListGroupTargetsForGroupRole(groupId string, roleId stri } // -func (m *GroupResource) RemoveGroupTargetFromGroupAdministratorRoleGivenToGroup(groupId string, roleId string, targetGroupId string) (*Response, error) { +func (m *GroupResource) RemoveGroupTargetFromGroupAdministratorRoleGivenToGroup(ctx context.Context, groupId string, roleId string, targetGroupId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles/%v/targets/groups/%v", groupId, roleId, targetGroupId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -495,7 +496,7 @@ func (m *GroupResource) RemoveGroupTargetFromGroupAdministratorRoleGivenToGroup( return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -504,7 +505,7 @@ func (m *GroupResource) RemoveGroupTargetFromGroupAdministratorRoleGivenToGroup( } // -func (m *GroupResource) AddGroupTargetToGroupAdministratorRoleForGroup(groupId string, roleId string, targetGroupId string) (*Response, error) { +func (m *GroupResource) AddGroupTargetToGroupAdministratorRoleForGroup(ctx context.Context, groupId string, roleId string, targetGroupId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/roles/%v/targets/groups/%v", groupId, roleId, targetGroupId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, nil) @@ -512,7 +513,7 @@ func (m *GroupResource) AddGroupTargetToGroupAdministratorRoleForGroup(groupId s return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -521,7 +522,7 @@ func (m *GroupResource) AddGroupTargetToGroupAdministratorRoleForGroup(groupId s } // Enumerates all users that are a member of a group. -func (m *GroupResource) ListGroupUsers(groupId string, qp *query.Params) ([]*User, *Response, error) { +func (m *GroupResource) ListGroupUsers(ctx context.Context, groupId string, qp *query.Params) ([]*User, *Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/users", groupId) if qp != nil { url = url + qp.String() @@ -534,7 +535,7 @@ func (m *GroupResource) ListGroupUsers(groupId string, qp *query.Params) ([]*Use var user []*User - resp, err := m.client.requestExecutor.Do(req, &user) + resp, err := m.client.requestExecutor.Do(ctx, req, &user) if err != nil { return nil, resp, err } @@ -543,7 +544,7 @@ func (m *GroupResource) ListGroupUsers(groupId string, qp *query.Params) ([]*Use } // Removes a user from a group with 'OKTA_GROUP' type. -func (m *GroupResource) RemoveUserFromGroup(groupId string, userId string) (*Response, error) { +func (m *GroupResource) RemoveUserFromGroup(ctx context.Context, groupId string, userId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/users/%v", groupId, userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -551,7 +552,7 @@ func (m *GroupResource) RemoveUserFromGroup(groupId string, userId string) (*Res return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -560,7 +561,7 @@ func (m *GroupResource) RemoveUserFromGroup(groupId string, userId string) (*Res } // Adds a user to a group with 'OKTA_GROUP' type. -func (m *GroupResource) AddUserToGroup(groupId string, userId string) (*Response, error) { +func (m *GroupResource) AddUserToGroup(ctx context.Context, groupId string, userId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/%v/users/%v", groupId, userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, nil) @@ -568,7 +569,7 @@ func (m *GroupResource) AddUserToGroup(groupId string, userId string) (*Response return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } diff --git a/okta/groupRule.go b/okta/groupRule.go index baafdc4e1..9e20a8e50 100644 --- a/okta/groupRule.go +++ b/okta/groupRule.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "time" ) @@ -37,7 +38,7 @@ type GroupRule struct { } // Updates a group rule. Only `INACTIVE` rules can be updated. -func (m *GroupRuleResource) UpdateGroupRule(ruleId string, body GroupRule) (*GroupRule, *Response, error) { +func (m *GroupRuleResource) UpdateGroupRule(ctx context.Context, ruleId string, body GroupRule) (*GroupRule, *Response, error) { url := fmt.Sprintf("/api/v1/groups/rules/%v", ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -47,7 +48,7 @@ func (m *GroupRuleResource) UpdateGroupRule(ruleId string, body GroupRule) (*Gro var groupRule *GroupRule - resp, err := m.client.requestExecutor.Do(req, &groupRule) + resp, err := m.client.requestExecutor.Do(ctx, req, &groupRule) if err != nil { return nil, resp, err } @@ -56,7 +57,7 @@ func (m *GroupRuleResource) UpdateGroupRule(ruleId string, body GroupRule) (*Gro } // Removes a specific group rule by id from your organization -func (m *GroupRuleResource) DeleteGroupRule(ruleId string) (*Response, error) { +func (m *GroupRuleResource) DeleteGroupRule(ctx context.Context, ruleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/groups/rules/%v", ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -64,7 +65,7 @@ func (m *GroupRuleResource) DeleteGroupRule(ruleId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } diff --git a/okta/identityProvider.go b/okta/identityProvider.go index 6f8324254..172729620 100644 --- a/okta/identityProvider.go +++ b/okta/identityProvider.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -40,7 +41,7 @@ type IdentityProvider struct { } // Adds a new IdP to your organization. -func (m *IdentityProviderResource) CreateIdentityProvider(body IdentityProvider) (*IdentityProvider, *Response, error) { +func (m *IdentityProviderResource) CreateIdentityProvider(ctx context.Context, body IdentityProvider) (*IdentityProvider, *Response, error) { url := fmt.Sprintf("/api/v1/idps") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -50,7 +51,7 @@ func (m *IdentityProviderResource) CreateIdentityProvider(body IdentityProvider) var identityProvider *IdentityProvider - resp, err := m.client.requestExecutor.Do(req, &identityProvider) + resp, err := m.client.requestExecutor.Do(ctx, req, &identityProvider) if err != nil { return nil, resp, err } @@ -59,7 +60,7 @@ func (m *IdentityProviderResource) CreateIdentityProvider(body IdentityProvider) } // Fetches an IdP by `id`. -func (m *IdentityProviderResource) GetIdentityProvider(idpId string) (*IdentityProvider, *Response, error) { +func (m *IdentityProviderResource) GetIdentityProvider(ctx context.Context, idpId string) (*IdentityProvider, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v", idpId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -69,7 +70,7 @@ func (m *IdentityProviderResource) GetIdentityProvider(idpId string) (*IdentityP var identityProvider *IdentityProvider - resp, err := m.client.requestExecutor.Do(req, &identityProvider) + resp, err := m.client.requestExecutor.Do(ctx, req, &identityProvider) if err != nil { return nil, resp, err } @@ -78,7 +79,7 @@ func (m *IdentityProviderResource) GetIdentityProvider(idpId string) (*IdentityP } // Updates the configuration for an IdP. -func (m *IdentityProviderResource) UpdateIdentityProvider(idpId string, body IdentityProvider) (*IdentityProvider, *Response, error) { +func (m *IdentityProviderResource) UpdateIdentityProvider(ctx context.Context, idpId string, body IdentityProvider) (*IdentityProvider, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v", idpId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -88,7 +89,7 @@ func (m *IdentityProviderResource) UpdateIdentityProvider(idpId string, body Ide var identityProvider *IdentityProvider - resp, err := m.client.requestExecutor.Do(req, &identityProvider) + resp, err := m.client.requestExecutor.Do(ctx, req, &identityProvider) if err != nil { return nil, resp, err } @@ -97,7 +98,7 @@ func (m *IdentityProviderResource) UpdateIdentityProvider(idpId string, body Ide } // Removes an IdP from your organization. -func (m *IdentityProviderResource) DeleteIdentityProvider(idpId string) (*Response, error) { +func (m *IdentityProviderResource) DeleteIdentityProvider(ctx context.Context, idpId string) (*Response, error) { url := fmt.Sprintf("/api/v1/idps/%v", idpId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -105,7 +106,7 @@ func (m *IdentityProviderResource) DeleteIdentityProvider(idpId string) (*Respon return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -114,7 +115,7 @@ func (m *IdentityProviderResource) DeleteIdentityProvider(idpId string) (*Respon } // Enumerates IdPs in your organization with pagination. A subset of IdPs can be returned that match a supported filter expression or query. -func (m *IdentityProviderResource) ListIdentityProviders(qp *query.Params) ([]*IdentityProvider, *Response, error) { +func (m *IdentityProviderResource) ListIdentityProviders(ctx context.Context, qp *query.Params) ([]*IdentityProvider, *Response, error) { url := fmt.Sprintf("/api/v1/idps") if qp != nil { url = url + qp.String() @@ -127,7 +128,7 @@ func (m *IdentityProviderResource) ListIdentityProviders(qp *query.Params) ([]*I var identityProvider []*IdentityProvider - resp, err := m.client.requestExecutor.Do(req, &identityProvider) + resp, err := m.client.requestExecutor.Do(ctx, req, &identityProvider) if err != nil { return nil, resp, err } @@ -136,7 +137,7 @@ func (m *IdentityProviderResource) ListIdentityProviders(qp *query.Params) ([]*I } // Enumerates IdP key credentials. -func (m *IdentityProviderResource) ListIdentityProviderKeys(qp *query.Params) ([]*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) ListIdentityProviderKeys(ctx context.Context, qp *query.Params) ([]*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/credentials/keys") if qp != nil { url = url + qp.String() @@ -149,7 +150,7 @@ func (m *IdentityProviderResource) ListIdentityProviderKeys(qp *query.Params) ([ var jsonWebKey []*JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -158,7 +159,7 @@ func (m *IdentityProviderResource) ListIdentityProviderKeys(qp *query.Params) ([ } // Adds a new X.509 certificate credential to the IdP key store. -func (m *IdentityProviderResource) CreateIdentityProviderKey(body JsonWebKey) (*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) CreateIdentityProviderKey(ctx context.Context, body JsonWebKey) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/credentials/keys") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -168,7 +169,7 @@ func (m *IdentityProviderResource) CreateIdentityProviderKey(body JsonWebKey) (* var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -177,7 +178,7 @@ func (m *IdentityProviderResource) CreateIdentityProviderKey(body JsonWebKey) (* } // Deletes a specific IdP Key Credential by `kid` if it is not currently being used by an Active or Inactive IdP. -func (m *IdentityProviderResource) DeleteIdentityProviderKey(keyId string) (*Response, error) { +func (m *IdentityProviderResource) DeleteIdentityProviderKey(ctx context.Context, keyId string) (*Response, error) { url := fmt.Sprintf("/api/v1/idps/credentials/keys/%v", keyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -185,7 +186,7 @@ func (m *IdentityProviderResource) DeleteIdentityProviderKey(keyId string) (*Res return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -194,7 +195,7 @@ func (m *IdentityProviderResource) DeleteIdentityProviderKey(keyId string) (*Res } // Gets a specific IdP Key Credential by `kid` -func (m *IdentityProviderResource) GetIdentityProviderKey(keyId string) (*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) GetIdentityProviderKey(ctx context.Context, keyId string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/credentials/keys/%v", keyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -204,7 +205,7 @@ func (m *IdentityProviderResource) GetIdentityProviderKey(keyId string) (*JsonWe var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -213,7 +214,7 @@ func (m *IdentityProviderResource) GetIdentityProviderKey(keyId string) (*JsonWe } // Enumerates signing CSRs for an IdP -func (m *IdentityProviderResource) ListCsrsForIdentityProvider(idpId string) ([]*CSR, *Response, error) { +func (m *IdentityProviderResource) ListCsrsForIdentityProvider(ctx context.Context, idpId string) ([]*CSR, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs", idpId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -223,7 +224,7 @@ func (m *IdentityProviderResource) ListCsrsForIdentityProvider(idpId string) ([] var csr []*CSR - resp, err := m.client.requestExecutor.Do(req, &csr) + resp, err := m.client.requestExecutor.Do(ctx, req, &csr) if err != nil { return nil, resp, err } @@ -232,7 +233,7 @@ func (m *IdentityProviderResource) ListCsrsForIdentityProvider(idpId string) ([] } // Generates a new key pair and returns a Certificate Signing Request for it. -func (m *IdentityProviderResource) GenerateCsrForIdentityProvider(idpId string, body CSRMetadata) (*CSR, *Response, error) { +func (m *IdentityProviderResource) GenerateCsrForIdentityProvider(ctx context.Context, idpId string, body CSRMetadata) (*CSR, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs", idpId) req, err := m.client.requestExecutor.WithAccept("application/pkcs10").WithContentType("application/json").NewRequest("POST", url, body) @@ -242,7 +243,7 @@ func (m *IdentityProviderResource) GenerateCsrForIdentityProvider(idpId string, var csr *CSR - resp, err := m.client.requestExecutor.Do(req, &csr) + resp, err := m.client.requestExecutor.Do(ctx, req, &csr) if err != nil { return nil, resp, err } @@ -251,7 +252,7 @@ func (m *IdentityProviderResource) GenerateCsrForIdentityProvider(idpId string, } // Revoke a CSR and delete the key pair from the IdP -func (m *IdentityProviderResource) RevokeCsrForIdentityProvider(idpId string, csrId string) (*Response, error) { +func (m *IdentityProviderResource) RevokeCsrForIdentityProvider(ctx context.Context, idpId string, csrId string) (*Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v", idpId, csrId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -259,7 +260,7 @@ func (m *IdentityProviderResource) RevokeCsrForIdentityProvider(idpId string, cs return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -268,7 +269,7 @@ func (m *IdentityProviderResource) RevokeCsrForIdentityProvider(idpId string, cs } // Gets a specific CSR model by id -func (m *IdentityProviderResource) GetCsrForIdentityProvider(idpId string, csrId string) (*CSR, *Response, error) { +func (m *IdentityProviderResource) GetCsrForIdentityProvider(ctx context.Context, idpId string, csrId string) (*CSR, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v", idpId, csrId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -278,7 +279,7 @@ func (m *IdentityProviderResource) GetCsrForIdentityProvider(idpId string, csrId var csr *CSR - resp, err := m.client.requestExecutor.Do(req, &csr) + resp, err := m.client.requestExecutor.Do(ctx, req, &csr) if err != nil { return nil, resp, err } @@ -287,7 +288,7 @@ func (m *IdentityProviderResource) GetCsrForIdentityProvider(idpId string, csrId } // Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP. -func (m *IdentityProviderResource) PublishCerCertForIdentityProvider(idpId string, csrId string, body string) (*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) PublishCerCertForIdentityProvider(ctx context.Context, idpId string, csrId string, body string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v/lifecycle/publish", idpId, csrId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/x-x509-ca-cert").NewRequest("POST", url, body) @@ -297,7 +298,7 @@ func (m *IdentityProviderResource) PublishCerCertForIdentityProvider(idpId strin var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -306,7 +307,7 @@ func (m *IdentityProviderResource) PublishCerCertForIdentityProvider(idpId strin } // Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP. -func (m *IdentityProviderResource) PublishBinaryCerCertForIdentityProvider(idpId string, csrId string, body string) (*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) PublishBinaryCerCertForIdentityProvider(ctx context.Context, idpId string, csrId string, body string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v/lifecycle/publish", idpId, csrId) req, err := m.client.requestExecutor.AsBinary().WithAccept("application/json").WithContentType("application/x-x509-ca-cert").NewRequest("POST", url, body) @@ -316,7 +317,7 @@ func (m *IdentityProviderResource) PublishBinaryCerCertForIdentityProvider(idpId var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -325,7 +326,7 @@ func (m *IdentityProviderResource) PublishBinaryCerCertForIdentityProvider(idpId } // Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP. -func (m *IdentityProviderResource) PublishDerCertForIdentityProvider(idpId string, csrId string, body string) (*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) PublishDerCertForIdentityProvider(ctx context.Context, idpId string, csrId string, body string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v/lifecycle/publish", idpId, csrId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/pkix-cert").NewRequest("POST", url, body) @@ -335,7 +336,7 @@ func (m *IdentityProviderResource) PublishDerCertForIdentityProvider(idpId strin var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -344,7 +345,7 @@ func (m *IdentityProviderResource) PublishDerCertForIdentityProvider(idpId strin } // Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP. -func (m *IdentityProviderResource) PublishBinaryDerCertForIdentityProvider(idpId string, csrId string, body string) (*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) PublishBinaryDerCertForIdentityProvider(ctx context.Context, idpId string, csrId string, body string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v/lifecycle/publish", idpId, csrId) req, err := m.client.requestExecutor.AsBinary().WithAccept("application/json").WithContentType("application/pkix-cert").NewRequest("POST", url, body) @@ -354,7 +355,7 @@ func (m *IdentityProviderResource) PublishBinaryDerCertForIdentityProvider(idpId var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -363,7 +364,7 @@ func (m *IdentityProviderResource) PublishBinaryDerCertForIdentityProvider(idpId } // Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP. -func (m *IdentityProviderResource) PublishBinaryPemCertForIdentityProvider(idpId string, csrId string, body string) (*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) PublishBinaryPemCertForIdentityProvider(ctx context.Context, idpId string, csrId string, body string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v/lifecycle/publish", idpId, csrId) req, err := m.client.requestExecutor.AsBinary().WithAccept("application/json").WithContentType("application/x-pem-file").NewRequest("POST", url, body) @@ -373,7 +374,7 @@ func (m *IdentityProviderResource) PublishBinaryPemCertForIdentityProvider(idpId var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -382,7 +383,7 @@ func (m *IdentityProviderResource) PublishBinaryPemCertForIdentityProvider(idpId } // Enumerates signing key credentials for an IdP -func (m *IdentityProviderResource) ListIdentityProviderSigningKeys(idpId string) ([]*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) ListIdentityProviderSigningKeys(ctx context.Context, idpId string) ([]*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/keys", idpId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -392,7 +393,7 @@ func (m *IdentityProviderResource) ListIdentityProviderSigningKeys(idpId string) var jsonWebKey []*JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -401,7 +402,7 @@ func (m *IdentityProviderResource) ListIdentityProviderSigningKeys(idpId string) } // Generates a new X.509 certificate for an IdP signing key credential to be used for signing assertions sent to the IdP -func (m *IdentityProviderResource) GenerateIdentityProviderSigningKey(idpId string, qp *query.Params) (*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) GenerateIdentityProviderSigningKey(ctx context.Context, idpId string, qp *query.Params) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/keys/generate", idpId) if qp != nil { url = url + qp.String() @@ -414,7 +415,7 @@ func (m *IdentityProviderResource) GenerateIdentityProviderSigningKey(idpId stri var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -423,7 +424,7 @@ func (m *IdentityProviderResource) GenerateIdentityProviderSigningKey(idpId stri } // Gets a specific IdP Key Credential by `kid` -func (m *IdentityProviderResource) GetIdentityProviderSigningKey(idpId string, keyId string) (*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) GetIdentityProviderSigningKey(ctx context.Context, idpId string, keyId string) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/keys/%v", idpId, keyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -433,7 +434,7 @@ func (m *IdentityProviderResource) GetIdentityProviderSigningKey(idpId string, k var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -442,7 +443,7 @@ func (m *IdentityProviderResource) GetIdentityProviderSigningKey(idpId string, k } // Clones a X.509 certificate for an IdP signing key credential from a source IdP to target IdP -func (m *IdentityProviderResource) CloneIdentityProviderKey(idpId string, keyId string, qp *query.Params) (*JsonWebKey, *Response, error) { +func (m *IdentityProviderResource) CloneIdentityProviderKey(ctx context.Context, idpId string, keyId string, qp *query.Params) (*JsonWebKey, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/credentials/keys/%v/clone", idpId, keyId) if qp != nil { url = url + qp.String() @@ -455,7 +456,7 @@ func (m *IdentityProviderResource) CloneIdentityProviderKey(idpId string, keyId var jsonWebKey *JsonWebKey - resp, err := m.client.requestExecutor.Do(req, &jsonWebKey) + resp, err := m.client.requestExecutor.Do(ctx, req, &jsonWebKey) if err != nil { return nil, resp, err } @@ -464,7 +465,7 @@ func (m *IdentityProviderResource) CloneIdentityProviderKey(idpId string, keyId } // Activates an inactive IdP. -func (m *IdentityProviderResource) ActivateIdentityProvider(idpId string) (*IdentityProvider, *Response, error) { +func (m *IdentityProviderResource) ActivateIdentityProvider(ctx context.Context, idpId string) (*IdentityProvider, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/lifecycle/activate", idpId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -474,7 +475,7 @@ func (m *IdentityProviderResource) ActivateIdentityProvider(idpId string) (*Iden var identityProvider *IdentityProvider - resp, err := m.client.requestExecutor.Do(req, &identityProvider) + resp, err := m.client.requestExecutor.Do(ctx, req, &identityProvider) if err != nil { return nil, resp, err } @@ -483,7 +484,7 @@ func (m *IdentityProviderResource) ActivateIdentityProvider(idpId string) (*Iden } // Deactivates an active IdP. -func (m *IdentityProviderResource) DeactivateIdentityProvider(idpId string) (*IdentityProvider, *Response, error) { +func (m *IdentityProviderResource) DeactivateIdentityProvider(ctx context.Context, idpId string) (*IdentityProvider, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/lifecycle/deactivate", idpId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -493,7 +494,7 @@ func (m *IdentityProviderResource) DeactivateIdentityProvider(idpId string) (*Id var identityProvider *IdentityProvider - resp, err := m.client.requestExecutor.Do(req, &identityProvider) + resp, err := m.client.requestExecutor.Do(ctx, req, &identityProvider) if err != nil { return nil, resp, err } @@ -502,7 +503,7 @@ func (m *IdentityProviderResource) DeactivateIdentityProvider(idpId string) (*Id } // Find all the users linked to an identity provider -func (m *IdentityProviderResource) ListIdentityProviderApplicationUsers(idpId string) ([]*IdentityProviderApplicationUser, *Response, error) { +func (m *IdentityProviderResource) ListIdentityProviderApplicationUsers(ctx context.Context, idpId string) ([]*IdentityProviderApplicationUser, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/users", idpId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -512,7 +513,7 @@ func (m *IdentityProviderResource) ListIdentityProviderApplicationUsers(idpId st var identityProviderApplicationUser []*IdentityProviderApplicationUser - resp, err := m.client.requestExecutor.Do(req, &identityProviderApplicationUser) + resp, err := m.client.requestExecutor.Do(ctx, req, &identityProviderApplicationUser) if err != nil { return nil, resp, err } @@ -521,7 +522,7 @@ func (m *IdentityProviderResource) ListIdentityProviderApplicationUsers(idpId st } // Removes the link between the Okta user and the IdP user. -func (m *IdentityProviderResource) UnlinkUserFromIdentityProvider(idpId string, userId string) (*Response, error) { +func (m *IdentityProviderResource) UnlinkUserFromIdentityProvider(ctx context.Context, idpId string, userId string) (*Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/users/%v", idpId, userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -529,7 +530,7 @@ func (m *IdentityProviderResource) UnlinkUserFromIdentityProvider(idpId string, return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -538,7 +539,7 @@ func (m *IdentityProviderResource) UnlinkUserFromIdentityProvider(idpId string, } // Fetches a linked IdP user by ID -func (m *IdentityProviderResource) GetIdentityProviderApplicationUser(idpId string, userId string) (*IdentityProviderApplicationUser, *Response, error) { +func (m *IdentityProviderResource) GetIdentityProviderApplicationUser(ctx context.Context, idpId string, userId string) (*IdentityProviderApplicationUser, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/users/%v", idpId, userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -548,7 +549,7 @@ func (m *IdentityProviderResource) GetIdentityProviderApplicationUser(idpId stri var identityProviderApplicationUser *IdentityProviderApplicationUser - resp, err := m.client.requestExecutor.Do(req, &identityProviderApplicationUser) + resp, err := m.client.requestExecutor.Do(ctx, req, &identityProviderApplicationUser) if err != nil { return nil, resp, err } @@ -557,7 +558,7 @@ func (m *IdentityProviderResource) GetIdentityProviderApplicationUser(idpId stri } // Links an Okta user to an existing Social Identity Provider. This does not support the SAML2 Identity Provider Type -func (m *IdentityProviderResource) LinkUserToIdentityProvider(idpId string, userId string, body UserIdentityProviderLinkRequest) (*IdentityProviderApplicationUser, *Response, error) { +func (m *IdentityProviderResource) LinkUserToIdentityProvider(ctx context.Context, idpId string, userId string, body UserIdentityProviderLinkRequest) (*IdentityProviderApplicationUser, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/users/%v", idpId, userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -567,7 +568,7 @@ func (m *IdentityProviderResource) LinkUserToIdentityProvider(idpId string, user var identityProviderApplicationUser *IdentityProviderApplicationUser - resp, err := m.client.requestExecutor.Do(req, &identityProviderApplicationUser) + resp, err := m.client.requestExecutor.Do(ctx, req, &identityProviderApplicationUser) if err != nil { return nil, resp, err } @@ -576,7 +577,7 @@ func (m *IdentityProviderResource) LinkUserToIdentityProvider(idpId string, user } // Fetches the tokens minted by the Social Authentication Provider when the user authenticates with Okta via Social Auth. -func (m *IdentityProviderResource) ListSocialAuthTokens(idpId string, userId string) ([]*SocialAuthToken, *Response, error) { +func (m *IdentityProviderResource) ListSocialAuthTokens(ctx context.Context, idpId string, userId string) ([]*SocialAuthToken, *Response, error) { url := fmt.Sprintf("/api/v1/idps/%v/users/%v/credentials/tokens", idpId, userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -586,7 +587,7 @@ func (m *IdentityProviderResource) ListSocialAuthTokens(idpId string, userId str var socialAuthToken []*SocialAuthToken - resp, err := m.client.requestExecutor.Do(req, &socialAuthToken) + resp, err := m.client.requestExecutor.Do(ctx, req, &socialAuthToken) if err != nil { return nil, resp, err } diff --git a/okta/inlineHook.go b/okta/inlineHook.go index 599f2f6a9..1984322c0 100644 --- a/okta/inlineHook.go +++ b/okta/inlineHook.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -38,7 +39,7 @@ type InlineHook struct { Version string `json:"version,omitempty"` } -func (m *InlineHookResource) CreateInlineHook(body InlineHook) (*InlineHook, *Response, error) { +func (m *InlineHookResource) CreateInlineHook(ctx context.Context, body InlineHook) (*InlineHook, *Response, error) { url := fmt.Sprintf("/api/v1/inlineHooks") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -48,7 +49,7 @@ func (m *InlineHookResource) CreateInlineHook(body InlineHook) (*InlineHook, *Re var inlineHook *InlineHook - resp, err := m.client.requestExecutor.Do(req, &inlineHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &inlineHook) if err != nil { return nil, resp, err } @@ -57,7 +58,7 @@ func (m *InlineHookResource) CreateInlineHook(body InlineHook) (*InlineHook, *Re } // Gets an inline hook by ID -func (m *InlineHookResource) GetInlineHook(inlineHookId string) (*InlineHook, *Response, error) { +func (m *InlineHookResource) GetInlineHook(ctx context.Context, inlineHookId string) (*InlineHook, *Response, error) { url := fmt.Sprintf("/api/v1/inlineHooks/%v", inlineHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -67,7 +68,7 @@ func (m *InlineHookResource) GetInlineHook(inlineHookId string) (*InlineHook, *R var inlineHook *InlineHook - resp, err := m.client.requestExecutor.Do(req, &inlineHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &inlineHook) if err != nil { return nil, resp, err } @@ -76,7 +77,7 @@ func (m *InlineHookResource) GetInlineHook(inlineHookId string) (*InlineHook, *R } // Updates an inline hook by ID -func (m *InlineHookResource) UpdateInlineHook(inlineHookId string, body InlineHook) (*InlineHook, *Response, error) { +func (m *InlineHookResource) UpdateInlineHook(ctx context.Context, inlineHookId string, body InlineHook) (*InlineHook, *Response, error) { url := fmt.Sprintf("/api/v1/inlineHooks/%v", inlineHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -86,7 +87,7 @@ func (m *InlineHookResource) UpdateInlineHook(inlineHookId string, body InlineHo var inlineHook *InlineHook - resp, err := m.client.requestExecutor.Do(req, &inlineHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &inlineHook) if err != nil { return nil, resp, err } @@ -95,7 +96,7 @@ func (m *InlineHookResource) UpdateInlineHook(inlineHookId string, body InlineHo } // Deletes the Inline Hook matching the provided id. Once deleted, the Inline Hook is unrecoverable. As a safety precaution, only Inline Hooks with a status of INACTIVE are eligible for deletion. -func (m *InlineHookResource) DeleteInlineHook(inlineHookId string) (*Response, error) { +func (m *InlineHookResource) DeleteInlineHook(ctx context.Context, inlineHookId string) (*Response, error) { url := fmt.Sprintf("/api/v1/inlineHooks/%v", inlineHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -103,7 +104,7 @@ func (m *InlineHookResource) DeleteInlineHook(inlineHookId string) (*Response, e return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -111,7 +112,7 @@ func (m *InlineHookResource) DeleteInlineHook(inlineHookId string) (*Response, e return resp, nil } -func (m *InlineHookResource) ListInlineHooks(qp *query.Params) ([]*InlineHook, *Response, error) { +func (m *InlineHookResource) ListInlineHooks(ctx context.Context, qp *query.Params) ([]*InlineHook, *Response, error) { url := fmt.Sprintf("/api/v1/inlineHooks") if qp != nil { url = url + qp.String() @@ -124,7 +125,7 @@ func (m *InlineHookResource) ListInlineHooks(qp *query.Params) ([]*InlineHook, * var inlineHook []*InlineHook - resp, err := m.client.requestExecutor.Do(req, &inlineHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &inlineHook) if err != nil { return nil, resp, err } @@ -133,7 +134,7 @@ func (m *InlineHookResource) ListInlineHooks(qp *query.Params) ([]*InlineHook, * } // Executes the Inline Hook matching the provided inlineHookId using the request body as the input. This will send the provided data through the Channel and return a response if it matches the correct data contract. This execution endpoint should only be used for testing purposes. -func (m *InlineHookResource) ExecuteInlineHook(inlineHookId string, body InlineHookPayload) (*InlineHookResponse, *Response, error) { +func (m *InlineHookResource) ExecuteInlineHook(ctx context.Context, inlineHookId string, body InlineHookPayload) (*InlineHookResponse, *Response, error) { url := fmt.Sprintf("/api/v1/inlineHooks/%v/execute", inlineHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -143,7 +144,7 @@ func (m *InlineHookResource) ExecuteInlineHook(inlineHookId string, body InlineH var inlineHookResponse *InlineHookResponse - resp, err := m.client.requestExecutor.Do(req, &inlineHookResponse) + resp, err := m.client.requestExecutor.Do(ctx, req, &inlineHookResponse) if err != nil { return nil, resp, err } @@ -152,7 +153,7 @@ func (m *InlineHookResource) ExecuteInlineHook(inlineHookId string, body InlineH } // Activates the Inline Hook matching the provided id -func (m *InlineHookResource) ActivateInlineHook(inlineHookId string) (*InlineHook, *Response, error) { +func (m *InlineHookResource) ActivateInlineHook(ctx context.Context, inlineHookId string) (*InlineHook, *Response, error) { url := fmt.Sprintf("/api/v1/inlineHooks/%v/lifecycle/activate", inlineHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -162,7 +163,7 @@ func (m *InlineHookResource) ActivateInlineHook(inlineHookId string) (*InlineHoo var inlineHook *InlineHook - resp, err := m.client.requestExecutor.Do(req, &inlineHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &inlineHook) if err != nil { return nil, resp, err } @@ -171,7 +172,7 @@ func (m *InlineHookResource) ActivateInlineHook(inlineHookId string) (*InlineHoo } // Deactivates the Inline Hook matching the provided id -func (m *InlineHookResource) DeactivateInlineHook(inlineHookId string) (*InlineHook, *Response, error) { +func (m *InlineHookResource) DeactivateInlineHook(ctx context.Context, inlineHookId string) (*InlineHook, *Response, error) { url := fmt.Sprintf("/api/v1/inlineHooks/%v/lifecycle/deactivate", inlineHookId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -181,7 +182,7 @@ func (m *InlineHookResource) DeactivateInlineHook(inlineHookId string) (*InlineH var inlineHook *InlineHook - resp, err := m.client.requestExecutor.Do(req, &inlineHook) + resp, err := m.client.requestExecutor.Do(ctx, req, &inlineHook) if err != nil { return nil, resp, err } diff --git a/okta/linkedObject.go b/okta/linkedObject.go index 5297bc392..7bded5e5c 100644 --- a/okta/linkedObject.go +++ b/okta/linkedObject.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" ) @@ -30,7 +31,7 @@ type LinkedObject struct { Primary *LinkedObjectDetails `json:"primary,omitempty"` } -func (m *LinkedObjectResource) AddLinkedObjectDefinition(body LinkedObject) (*LinkedObject, *Response, error) { +func (m *LinkedObjectResource) AddLinkedObjectDefinition(ctx context.Context, body LinkedObject) (*LinkedObject, *Response, error) { url := fmt.Sprintf("/api/v1/meta/schemas/user/linkedObjects") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -40,7 +41,7 @@ func (m *LinkedObjectResource) AddLinkedObjectDefinition(body LinkedObject) (*Li var linkedObject *LinkedObject - resp, err := m.client.requestExecutor.Do(req, &linkedObject) + resp, err := m.client.requestExecutor.Do(ctx, req, &linkedObject) if err != nil { return nil, resp, err } @@ -48,7 +49,7 @@ func (m *LinkedObjectResource) AddLinkedObjectDefinition(body LinkedObject) (*Li return linkedObject, resp, nil } -func (m *LinkedObjectResource) GetLinkedObjectDefinition(linkedObjectName string) (*LinkedObject, *Response, error) { +func (m *LinkedObjectResource) GetLinkedObjectDefinition(ctx context.Context, linkedObjectName string) (*LinkedObject, *Response, error) { url := fmt.Sprintf("/api/v1/meta/schemas/user/linkedObjects/%v", linkedObjectName) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -58,7 +59,7 @@ func (m *LinkedObjectResource) GetLinkedObjectDefinition(linkedObjectName string var linkedObject *LinkedObject - resp, err := m.client.requestExecutor.Do(req, &linkedObject) + resp, err := m.client.requestExecutor.Do(ctx, req, &linkedObject) if err != nil { return nil, resp, err } @@ -66,7 +67,7 @@ func (m *LinkedObjectResource) GetLinkedObjectDefinition(linkedObjectName string return linkedObject, resp, nil } -func (m *LinkedObjectResource) DeleteLinkedObjectDefinition(linkedObjectName string) (*Response, error) { +func (m *LinkedObjectResource) DeleteLinkedObjectDefinition(ctx context.Context, linkedObjectName string) (*Response, error) { url := fmt.Sprintf("/api/v1/meta/schemas/user/linkedObjects/%v", linkedObjectName) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -74,7 +75,7 @@ func (m *LinkedObjectResource) DeleteLinkedObjectDefinition(linkedObjectName str return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -82,7 +83,7 @@ func (m *LinkedObjectResource) DeleteLinkedObjectDefinition(linkedObjectName str return resp, nil } -func (m *LinkedObjectResource) ListLinkedObjectDefinitions() ([]*LinkedObject, *Response, error) { +func (m *LinkedObjectResource) ListLinkedObjectDefinitions(ctx context.Context) ([]*LinkedObject, *Response, error) { url := fmt.Sprintf("/api/v1/meta/schemas/user/linkedObjects") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -92,7 +93,7 @@ func (m *LinkedObjectResource) ListLinkedObjectDefinitions() ([]*LinkedObject, * var linkedObject []*LinkedObject - resp, err := m.client.requestExecutor.Do(req, &linkedObject) + resp, err := m.client.requestExecutor.Do(ctx, req, &linkedObject) if err != nil { return nil, resp, err } diff --git a/okta/logEvent.go b/okta/logEvent.go index 157414c3d..bb90021c6 100644 --- a/okta/logEvent.go +++ b/okta/logEvent.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -46,7 +47,7 @@ type LogEvent struct { } // The Okta System Log API provides read access to your organization’s system log. This API provides more functionality than the Events API -func (m *LogEventResource) GetLogs(qp *query.Params) ([]*LogEvent, *Response, error) { +func (m *LogEventResource) GetLogs(ctx context.Context, qp *query.Params) ([]*LogEvent, *Response, error) { url := fmt.Sprintf("/api/v1/logs") if qp != nil { url = url + qp.String() @@ -59,7 +60,7 @@ func (m *LogEventResource) GetLogs(qp *query.Params) ([]*LogEvent, *Response, er var logEvent []*LogEvent - resp, err := m.client.requestExecutor.Do(req, &logEvent) + resp, err := m.client.requestExecutor.Do(ctx, req, &logEvent) if err != nil { return nil, resp, err } diff --git a/okta/okta.go b/okta/okta.go index 40794a195..7741e6644 100644 --- a/okta/okta.go +++ b/okta/okta.go @@ -19,7 +19,6 @@ package okta import ( - "context" "fmt" "io/ioutil" "os/user" @@ -61,7 +60,7 @@ type resource struct { client *Client } -func NewClient(ctx context.Context, conf ...ConfigSetter) (*Client, error) { +func NewClient(conf ...ConfigSetter) (*Client, error) { config := &config{} setConfigDefaults(config) diff --git a/okta/policy.go b/okta/policy.go index 0cf9a83e4..562744287 100644 --- a/okta/policy.go +++ b/okta/policy.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -42,7 +43,7 @@ type Policy struct { } // Gets a policy. -func (m *PolicyResource) GetPolicy(policyId string, qp *query.Params) (*Policy, *Response, error) { +func (m *PolicyResource) GetPolicy(ctx context.Context, policyId string, qp *query.Params) (*Policy, *Response, error) { url := fmt.Sprintf("/api/v1/policies/%v", policyId) if qp != nil { url = url + qp.String() @@ -55,7 +56,7 @@ func (m *PolicyResource) GetPolicy(policyId string, qp *query.Params) (*Policy, var policy *Policy - resp, err := m.client.requestExecutor.Do(req, &policy) + resp, err := m.client.requestExecutor.Do(ctx, req, &policy) if err != nil { return nil, resp, err } @@ -64,7 +65,7 @@ func (m *PolicyResource) GetPolicy(policyId string, qp *query.Params) (*Policy, } // Updates a policy. -func (m *PolicyResource) UpdatePolicy(policyId string, body Policy) (*Policy, *Response, error) { +func (m *PolicyResource) UpdatePolicy(ctx context.Context, policyId string, body Policy) (*Policy, *Response, error) { url := fmt.Sprintf("/api/v1/policies/%v", policyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -74,7 +75,7 @@ func (m *PolicyResource) UpdatePolicy(policyId string, body Policy) (*Policy, *R var policy *Policy - resp, err := m.client.requestExecutor.Do(req, &policy) + resp, err := m.client.requestExecutor.Do(ctx, req, &policy) if err != nil { return nil, resp, err } @@ -83,7 +84,7 @@ func (m *PolicyResource) UpdatePolicy(policyId string, body Policy) (*Policy, *R } // Removes a policy. -func (m *PolicyResource) DeletePolicy(policyId string) (*Response, error) { +func (m *PolicyResource) DeletePolicy(ctx context.Context, policyId string) (*Response, error) { url := fmt.Sprintf("/api/v1/policies/%v", policyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -91,7 +92,7 @@ func (m *PolicyResource) DeletePolicy(policyId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -100,7 +101,7 @@ func (m *PolicyResource) DeletePolicy(policyId string) (*Response, error) { } // Gets all policies with the specified type. -func (m *PolicyResource) ListPolicies(qp *query.Params) ([]*Policy, *Response, error) { +func (m *PolicyResource) ListPolicies(ctx context.Context, qp *query.Params) ([]*Policy, *Response, error) { url := fmt.Sprintf("/api/v1/policies") if qp != nil { url = url + qp.String() @@ -113,7 +114,7 @@ func (m *PolicyResource) ListPolicies(qp *query.Params) ([]*Policy, *Response, e var policy []*Policy - resp, err := m.client.requestExecutor.Do(req, &policy) + resp, err := m.client.requestExecutor.Do(ctx, req, &policy) if err != nil { return nil, resp, err } @@ -122,7 +123,7 @@ func (m *PolicyResource) ListPolicies(qp *query.Params) ([]*Policy, *Response, e } // Creates a policy. -func (m *PolicyResource) CreatePolicy(body Policy, qp *query.Params) (*Policy, *Response, error) { +func (m *PolicyResource) CreatePolicy(ctx context.Context, body Policy, qp *query.Params) (*Policy, *Response, error) { url := fmt.Sprintf("/api/v1/policies") if qp != nil { url = url + qp.String() @@ -135,7 +136,7 @@ func (m *PolicyResource) CreatePolicy(body Policy, qp *query.Params) (*Policy, * var policy *Policy - resp, err := m.client.requestExecutor.Do(req, &policy) + resp, err := m.client.requestExecutor.Do(ctx, req, &policy) if err != nil { return nil, resp, err } @@ -144,7 +145,7 @@ func (m *PolicyResource) CreatePolicy(body Policy, qp *query.Params) (*Policy, * } // Activates a policy. -func (m *PolicyResource) ActivatePolicy(policyId string) (*Response, error) { +func (m *PolicyResource) ActivatePolicy(ctx context.Context, policyId string) (*Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/lifecycle/activate", policyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -152,7 +153,7 @@ func (m *PolicyResource) ActivatePolicy(policyId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -161,7 +162,7 @@ func (m *PolicyResource) ActivatePolicy(policyId string) (*Response, error) { } // Deactivates a policy. -func (m *PolicyResource) DeactivatePolicy(policyId string) (*Response, error) { +func (m *PolicyResource) DeactivatePolicy(ctx context.Context, policyId string) (*Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/lifecycle/deactivate", policyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -169,7 +170,7 @@ func (m *PolicyResource) DeactivatePolicy(policyId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -178,7 +179,7 @@ func (m *PolicyResource) DeactivatePolicy(policyId string) (*Response, error) { } // Enumerates all policy rules. -func (m *PolicyResource) ListPolicyRules(policyId string) ([]*PolicyRule, *Response, error) { +func (m *PolicyResource) ListPolicyRules(ctx context.Context, policyId string) ([]*PolicyRule, *Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/rules", policyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -188,7 +189,7 @@ func (m *PolicyResource) ListPolicyRules(policyId string) ([]*PolicyRule, *Respo var policyRule []*PolicyRule - resp, err := m.client.requestExecutor.Do(req, &policyRule) + resp, err := m.client.requestExecutor.Do(ctx, req, &policyRule) if err != nil { return nil, resp, err } @@ -197,7 +198,7 @@ func (m *PolicyResource) ListPolicyRules(policyId string) ([]*PolicyRule, *Respo } // Creates a policy rule. -func (m *PolicyResource) CreatePolicyRule(policyId string, body PolicyRule) (*PolicyRule, *Response, error) { +func (m *PolicyResource) CreatePolicyRule(ctx context.Context, policyId string, body PolicyRule) (*PolicyRule, *Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/rules", policyId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -207,7 +208,7 @@ func (m *PolicyResource) CreatePolicyRule(policyId string, body PolicyRule) (*Po var policyRule *PolicyRule - resp, err := m.client.requestExecutor.Do(req, &policyRule) + resp, err := m.client.requestExecutor.Do(ctx, req, &policyRule) if err != nil { return nil, resp, err } @@ -216,7 +217,7 @@ func (m *PolicyResource) CreatePolicyRule(policyId string, body PolicyRule) (*Po } // Removes a policy rule. -func (m *PolicyResource) DeletePolicyRule(policyId string, ruleId string) (*Response, error) { +func (m *PolicyResource) DeletePolicyRule(ctx context.Context, policyId string, ruleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/rules/%v", policyId, ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -224,7 +225,7 @@ func (m *PolicyResource) DeletePolicyRule(policyId string, ruleId string) (*Resp return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -233,7 +234,7 @@ func (m *PolicyResource) DeletePolicyRule(policyId string, ruleId string) (*Resp } // Gets a policy rule. -func (m *PolicyResource) GetPolicyRule(policyId string, ruleId string) (*PolicyRule, *Response, error) { +func (m *PolicyResource) GetPolicyRule(ctx context.Context, policyId string, ruleId string) (*PolicyRule, *Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/rules/%v", policyId, ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -243,7 +244,7 @@ func (m *PolicyResource) GetPolicyRule(policyId string, ruleId string) (*PolicyR var policyRule *PolicyRule - resp, err := m.client.requestExecutor.Do(req, &policyRule) + resp, err := m.client.requestExecutor.Do(ctx, req, &policyRule) if err != nil { return nil, resp, err } @@ -252,7 +253,7 @@ func (m *PolicyResource) GetPolicyRule(policyId string, ruleId string) (*PolicyR } // Updates a policy rule. -func (m *PolicyResource) UpdatePolicyRule(policyId string, ruleId string, body PolicyRule) (*PolicyRule, *Response, error) { +func (m *PolicyResource) UpdatePolicyRule(ctx context.Context, policyId string, ruleId string, body PolicyRule) (*PolicyRule, *Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/rules/%v", policyId, ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -262,7 +263,7 @@ func (m *PolicyResource) UpdatePolicyRule(policyId string, ruleId string, body P var policyRule *PolicyRule - resp, err := m.client.requestExecutor.Do(req, &policyRule) + resp, err := m.client.requestExecutor.Do(ctx, req, &policyRule) if err != nil { return nil, resp, err } @@ -271,7 +272,7 @@ func (m *PolicyResource) UpdatePolicyRule(policyId string, ruleId string, body P } // Activates a policy rule. -func (m *PolicyResource) ActivatePolicyRule(policyId string, ruleId string) (*Response, error) { +func (m *PolicyResource) ActivatePolicyRule(ctx context.Context, policyId string, ruleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/rules/%v/lifecycle/activate", policyId, ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -279,7 +280,7 @@ func (m *PolicyResource) ActivatePolicyRule(policyId string, ruleId string) (*Re return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -288,7 +289,7 @@ func (m *PolicyResource) ActivatePolicyRule(policyId string, ruleId string) (*Re } // Deactivates a policy rule. -func (m *PolicyResource) DeactivatePolicyRule(policyId string, ruleId string) (*Response, error) { +func (m *PolicyResource) DeactivatePolicyRule(ctx context.Context, policyId string, ruleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/rules/%v/lifecycle/deactivate", policyId, ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -296,7 +297,7 @@ func (m *PolicyResource) DeactivatePolicyRule(policyId string, ruleId string) (* return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } diff --git a/okta/policyRule.go b/okta/policyRule.go index f7fce18da..8c7e26e43 100644 --- a/okta/policyRule.go +++ b/okta/policyRule.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "time" ) @@ -36,7 +37,7 @@ type PolicyRule struct { } // Updates a policy rule. -func (m *PolicyRuleResource) UpdatePolicyRule(policyId string, ruleId string, body PolicyRule) (*PolicyRule, *Response, error) { +func (m *PolicyRuleResource) UpdatePolicyRule(ctx context.Context, policyId string, ruleId string, body PolicyRule) (*PolicyRule, *Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/rules/%v", policyId, ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -46,7 +47,7 @@ func (m *PolicyRuleResource) UpdatePolicyRule(policyId string, ruleId string, bo var policyRule *PolicyRule - resp, err := m.client.requestExecutor.Do(req, &policyRule) + resp, err := m.client.requestExecutor.Do(ctx, req, &policyRule) if err != nil { return nil, resp, err } @@ -55,7 +56,7 @@ func (m *PolicyRuleResource) UpdatePolicyRule(policyId string, ruleId string, bo } // Removes a policy rule. -func (m *PolicyRuleResource) DeletePolicyRule(policyId string, ruleId string) (*Response, error) { +func (m *PolicyRuleResource) DeletePolicyRule(ctx context.Context, policyId string, ruleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/policies/%v/rules/%v", policyId, ruleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -63,7 +64,7 @@ func (m *PolicyRuleResource) DeletePolicyRule(policyId string, ruleId string) (* return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } diff --git a/okta/requestExecutor.go b/okta/requestExecutor.go index 419f5b723..6eb47caac 100644 --- a/okta/requestExecutor.go +++ b/okta/requestExecutor.go @@ -18,6 +18,7 @@ package okta import ( "bytes" + "context" "crypto/x509" "encoding/json" "encoding/pem" @@ -212,7 +213,7 @@ func (re *RequestExecutor) WithContentType(contentTypeHeader string) *RequestExe return re } -func (re *RequestExecutor) Do(req *http.Request, v interface{}) (*Response, error) { +func (re *RequestExecutor) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) { requestStarted := time.Now().Unix() cacheKey := cache.CreateCacheKey(req) if req.Method != http.MethodGet { @@ -222,7 +223,7 @@ func (re *RequestExecutor) Do(req *http.Request, v interface{}) (*Response, erro if !inCache { - resp, err := re.doWithRetries(req, 0, requestStarted, nil) + resp, err := re.doWithRetries(ctx, req, 0, requestStarted, nil) if err != nil { return nil, err @@ -245,7 +246,7 @@ func (re *RequestExecutor) Do(req *http.Request, v interface{}) (*Response, erro } -func (re *RequestExecutor) doWithRetries(req *http.Request, retryCount int32, requestStarted int64, lastResponse *http.Response) (*http.Response, error) { +func (re *RequestExecutor) doWithRetries(ctx context.Context, req *http.Request, retryCount int32, requestStarted int64, lastResponse *http.Response) (*http.Response, error) { iterationStart := time.Now().Unix() maxRetries := re.config.Okta.Client.RateLimit.MaxRetries requestTimeout := int64(re.config.Okta.Client.RequestTimeout) @@ -259,6 +260,7 @@ func (re *RequestExecutor) doWithRetries(req *http.Request, retryCount int32, re return lastResponse, errors.New("reached the max request time") } + req = req.WithContext(ctx) resp, err := re.httpClient.Do(req) if (err != nil || tooManyRequests(resp)) && retryCount < maxRetries { @@ -276,7 +278,7 @@ func (re *RequestExecutor) doWithRetries(req *http.Request, retryCount int32, re } if tooManyRequests(resp) { - err := backoffPause(retryCount, resp) + err := backoffPause(ctx, retryCount, resp) if err != nil { return nil, err } @@ -286,7 +288,7 @@ func (re *RequestExecutor) doWithRetries(req *http.Request, retryCount int32, re req.Header.Add("X-Okta-Retry-For", resp.Header.Get("X-Okta-Request-Id")) req.Header.Add("X-Okta-Retry-Count", fmt.Sprint(retryCount)) - resp, err = re.doWithRetries(req, retryCount, requestStarted, resp) + resp, err = re.doWithRetries(ctx, req, retryCount, requestStarted, resp) } return resp, err @@ -305,9 +307,9 @@ func tryDrainBody(body io.ReadCloser) error { return nil } -func backoffPause(retryCount int32, response *http.Response) error { +func backoffPause(ctx context.Context, retryCount int32, response *http.Response) error { if response.StatusCode == http.StatusTooManyRequests { - backoffSeconds := Get429BackoffTime(response) + backoffSeconds := Get429BackoffTime(ctx, response) time.Sleep(time.Duration(backoffSeconds) * time.Second) return nil @@ -316,7 +318,7 @@ func backoffPause(retryCount int32, response *http.Response) error { return nil } -func Get429BackoffTime(response *http.Response) int64 { +func Get429BackoffTime(ctx context.Context, response *http.Response) int64 { var limitResetMap []int for _, time := range response.Header["X-Rate-Limit-Reset"] { diff --git a/okta/session.go b/okta/session.go index e5393b843..68e9ef694 100644 --- a/okta/session.go +++ b/okta/session.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "time" ) @@ -40,7 +41,7 @@ type Session struct { } // Get details about a session. -func (m *SessionResource) GetSession(sessionId string) (*Session, *Response, error) { +func (m *SessionResource) GetSession(ctx context.Context, sessionId string) (*Session, *Response, error) { url := fmt.Sprintf("/api/v1/sessions/%v", sessionId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -50,7 +51,7 @@ func (m *SessionResource) GetSession(sessionId string) (*Session, *Response, err var session *Session - resp, err := m.client.requestExecutor.Do(req, &session) + resp, err := m.client.requestExecutor.Do(ctx, req, &session) if err != nil { return nil, resp, err } @@ -59,7 +60,7 @@ func (m *SessionResource) GetSession(sessionId string) (*Session, *Response, err } // -func (m *SessionResource) EndSession(sessionId string) (*Response, error) { +func (m *SessionResource) EndSession(ctx context.Context, sessionId string) (*Response, error) { url := fmt.Sprintf("/api/v1/sessions/%v", sessionId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -67,7 +68,7 @@ func (m *SessionResource) EndSession(sessionId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -76,7 +77,7 @@ func (m *SessionResource) EndSession(sessionId string) (*Response, error) { } // Creates a new session for a user with a valid session token. Use this API if, for example, you want to set the session cookie yourself instead of allowing Okta to set it, or want to hold the session ID in order to delete a session via the API instead of visiting the logout URL. -func (m *SessionResource) CreateSession(body CreateSessionRequest) (*Session, *Response, error) { +func (m *SessionResource) CreateSession(ctx context.Context, body CreateSessionRequest) (*Session, *Response, error) { url := fmt.Sprintf("/api/v1/sessions") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -86,7 +87,7 @@ func (m *SessionResource) CreateSession(body CreateSessionRequest) (*Session, *R var session *Session - resp, err := m.client.requestExecutor.Do(req, &session) + resp, err := m.client.requestExecutor.Do(ctx, req, &session) if err != nil { return nil, resp, err } @@ -95,7 +96,7 @@ func (m *SessionResource) CreateSession(body CreateSessionRequest) (*Session, *R } // -func (m *SessionResource) RefreshSession(sessionId string) (*Session, *Response, error) { +func (m *SessionResource) RefreshSession(ctx context.Context, sessionId string) (*Session, *Response, error) { url := fmt.Sprintf("/api/v1/sessions/%v/lifecycle/refresh", sessionId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -105,7 +106,7 @@ func (m *SessionResource) RefreshSession(sessionId string) (*Session, *Response, var session *Session - resp, err := m.client.requestExecutor.Do(req, &session) + resp, err := m.client.requestExecutor.Do(ctx, req, &session) if err != nil { return nil, resp, err } diff --git a/okta/smsTemplate.go b/okta/smsTemplate.go index a2435d911..9ae649f99 100644 --- a/okta/smsTemplate.go +++ b/okta/smsTemplate.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -37,7 +38,7 @@ type SmsTemplate struct { } // Adds a new custom SMS template to your organization. -func (m *SmsTemplateResource) CreateSmsTemplate(body SmsTemplate) (*SmsTemplate, *Response, error) { +func (m *SmsTemplateResource) CreateSmsTemplate(ctx context.Context, body SmsTemplate) (*SmsTemplate, *Response, error) { url := fmt.Sprintf("/api/v1/templates/sms") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -47,7 +48,7 @@ func (m *SmsTemplateResource) CreateSmsTemplate(body SmsTemplate) (*SmsTemplate, var smsTemplate *SmsTemplate - resp, err := m.client.requestExecutor.Do(req, &smsTemplate) + resp, err := m.client.requestExecutor.Do(ctx, req, &smsTemplate) if err != nil { return nil, resp, err } @@ -56,7 +57,7 @@ func (m *SmsTemplateResource) CreateSmsTemplate(body SmsTemplate) (*SmsTemplate, } // Fetches a specific template by `id` -func (m *SmsTemplateResource) GetSmsTemplate(templateId string) (*SmsTemplate, *Response, error) { +func (m *SmsTemplateResource) GetSmsTemplate(ctx context.Context, templateId string) (*SmsTemplate, *Response, error) { url := fmt.Sprintf("/api/v1/templates/sms/%v", templateId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -66,7 +67,7 @@ func (m *SmsTemplateResource) GetSmsTemplate(templateId string) (*SmsTemplate, * var smsTemplate *SmsTemplate - resp, err := m.client.requestExecutor.Do(req, &smsTemplate) + resp, err := m.client.requestExecutor.Do(ctx, req, &smsTemplate) if err != nil { return nil, resp, err } @@ -75,7 +76,7 @@ func (m *SmsTemplateResource) GetSmsTemplate(templateId string) (*SmsTemplate, * } // Updates the SMS template. -func (m *SmsTemplateResource) UpdateSmsTemplate(templateId string, body SmsTemplate) (*SmsTemplate, *Response, error) { +func (m *SmsTemplateResource) UpdateSmsTemplate(ctx context.Context, templateId string, body SmsTemplate) (*SmsTemplate, *Response, error) { url := fmt.Sprintf("/api/v1/templates/sms/%v", templateId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -85,7 +86,7 @@ func (m *SmsTemplateResource) UpdateSmsTemplate(templateId string, body SmsTempl var smsTemplate *SmsTemplate - resp, err := m.client.requestExecutor.Do(req, &smsTemplate) + resp, err := m.client.requestExecutor.Do(ctx, req, &smsTemplate) if err != nil { return nil, resp, err } @@ -94,7 +95,7 @@ func (m *SmsTemplateResource) UpdateSmsTemplate(templateId string, body SmsTempl } // Removes an SMS template. -func (m *SmsTemplateResource) DeleteSmsTemplate(templateId string) (*Response, error) { +func (m *SmsTemplateResource) DeleteSmsTemplate(ctx context.Context, templateId string) (*Response, error) { url := fmt.Sprintf("/api/v1/templates/sms/%v", templateId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -102,7 +103,7 @@ func (m *SmsTemplateResource) DeleteSmsTemplate(templateId string) (*Response, e return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -111,7 +112,7 @@ func (m *SmsTemplateResource) DeleteSmsTemplate(templateId string) (*Response, e } // Enumerates custom SMS templates in your organization. A subset of templates can be returned that match a template type. -func (m *SmsTemplateResource) ListSmsTemplates(qp *query.Params) ([]*SmsTemplate, *Response, error) { +func (m *SmsTemplateResource) ListSmsTemplates(ctx context.Context, qp *query.Params) ([]*SmsTemplate, *Response, error) { url := fmt.Sprintf("/api/v1/templates/sms") if qp != nil { url = url + qp.String() @@ -124,7 +125,7 @@ func (m *SmsTemplateResource) ListSmsTemplates(qp *query.Params) ([]*SmsTemplate var smsTemplate []*SmsTemplate - resp, err := m.client.requestExecutor.Do(req, &smsTemplate) + resp, err := m.client.requestExecutor.Do(ctx, req, &smsTemplate) if err != nil { return nil, resp, err } @@ -133,7 +134,7 @@ func (m *SmsTemplateResource) ListSmsTemplates(qp *query.Params) ([]*SmsTemplate } // Updates only some of the SMS template properties: -func (m *SmsTemplateResource) PartialUpdateSmsTemplate(templateId string, body SmsTemplate) (*SmsTemplate, *Response, error) { +func (m *SmsTemplateResource) PartialUpdateSmsTemplate(ctx context.Context, templateId string, body SmsTemplate) (*SmsTemplate, *Response, error) { url := fmt.Sprintf("/api/v1/templates/sms/%v", templateId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -143,7 +144,7 @@ func (m *SmsTemplateResource) PartialUpdateSmsTemplate(templateId string, body S var smsTemplate *SmsTemplate - resp, err := m.client.requestExecutor.Do(req, &smsTemplate) + resp, err := m.client.requestExecutor.Do(ctx, req, &smsTemplate) if err != nil { return nil, resp, err } diff --git a/okta/trustedOrigin.go b/okta/trustedOrigin.go index 67181737e..518820f72 100644 --- a/okta/trustedOrigin.go +++ b/okta/trustedOrigin.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -39,7 +40,7 @@ type TrustedOrigin struct { Status string `json:"status,omitempty"` } -func (m *TrustedOriginResource) CreateOrigin(body TrustedOrigin) (*TrustedOrigin, *Response, error) { +func (m *TrustedOriginResource) CreateOrigin(ctx context.Context, body TrustedOrigin) (*TrustedOrigin, *Response, error) { url := fmt.Sprintf("/api/v1/trustedOrigins") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -49,7 +50,7 @@ func (m *TrustedOriginResource) CreateOrigin(body TrustedOrigin) (*TrustedOrigin var trustedOrigin *TrustedOrigin - resp, err := m.client.requestExecutor.Do(req, &trustedOrigin) + resp, err := m.client.requestExecutor.Do(ctx, req, &trustedOrigin) if err != nil { return nil, resp, err } @@ -57,7 +58,7 @@ func (m *TrustedOriginResource) CreateOrigin(body TrustedOrigin) (*TrustedOrigin return trustedOrigin, resp, nil } -func (m *TrustedOriginResource) GetOrigin(trustedOriginId string) (*TrustedOrigin, *Response, error) { +func (m *TrustedOriginResource) GetOrigin(ctx context.Context, trustedOriginId string) (*TrustedOrigin, *Response, error) { url := fmt.Sprintf("/api/v1/trustedOrigins/%v", trustedOriginId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -67,7 +68,7 @@ func (m *TrustedOriginResource) GetOrigin(trustedOriginId string) (*TrustedOrigi var trustedOrigin *TrustedOrigin - resp, err := m.client.requestExecutor.Do(req, &trustedOrigin) + resp, err := m.client.requestExecutor.Do(ctx, req, &trustedOrigin) if err != nil { return nil, resp, err } @@ -75,7 +76,7 @@ func (m *TrustedOriginResource) GetOrigin(trustedOriginId string) (*TrustedOrigi return trustedOrigin, resp, nil } -func (m *TrustedOriginResource) UpdateOrigin(trustedOriginId string, body TrustedOrigin) (*TrustedOrigin, *Response, error) { +func (m *TrustedOriginResource) UpdateOrigin(ctx context.Context, trustedOriginId string, body TrustedOrigin) (*TrustedOrigin, *Response, error) { url := fmt.Sprintf("/api/v1/trustedOrigins/%v", trustedOriginId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -85,7 +86,7 @@ func (m *TrustedOriginResource) UpdateOrigin(trustedOriginId string, body Truste var trustedOrigin *TrustedOrigin - resp, err := m.client.requestExecutor.Do(req, &trustedOrigin) + resp, err := m.client.requestExecutor.Do(ctx, req, &trustedOrigin) if err != nil { return nil, resp, err } @@ -93,7 +94,7 @@ func (m *TrustedOriginResource) UpdateOrigin(trustedOriginId string, body Truste return trustedOrigin, resp, nil } -func (m *TrustedOriginResource) DeleteOrigin(trustedOriginId string) (*Response, error) { +func (m *TrustedOriginResource) DeleteOrigin(ctx context.Context, trustedOriginId string) (*Response, error) { url := fmt.Sprintf("/api/v1/trustedOrigins/%v", trustedOriginId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -101,7 +102,7 @@ func (m *TrustedOriginResource) DeleteOrigin(trustedOriginId string) (*Response, return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -109,7 +110,7 @@ func (m *TrustedOriginResource) DeleteOrigin(trustedOriginId string) (*Response, return resp, nil } -func (m *TrustedOriginResource) ListOrigins(qp *query.Params) ([]*TrustedOrigin, *Response, error) { +func (m *TrustedOriginResource) ListOrigins(ctx context.Context, qp *query.Params) ([]*TrustedOrigin, *Response, error) { url := fmt.Sprintf("/api/v1/trustedOrigins") if qp != nil { url = url + qp.String() @@ -122,7 +123,7 @@ func (m *TrustedOriginResource) ListOrigins(qp *query.Params) ([]*TrustedOrigin, var trustedOrigin []*TrustedOrigin - resp, err := m.client.requestExecutor.Do(req, &trustedOrigin) + resp, err := m.client.requestExecutor.Do(ctx, req, &trustedOrigin) if err != nil { return nil, resp, err } @@ -130,7 +131,7 @@ func (m *TrustedOriginResource) ListOrigins(qp *query.Params) ([]*TrustedOrigin, return trustedOrigin, resp, nil } -func (m *TrustedOriginResource) ActivateOrigin(trustedOriginId string) (*TrustedOrigin, *Response, error) { +func (m *TrustedOriginResource) ActivateOrigin(ctx context.Context, trustedOriginId string) (*TrustedOrigin, *Response, error) { url := fmt.Sprintf("/api/v1/trustedOrigins/%v/lifecycle/activate", trustedOriginId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -140,7 +141,7 @@ func (m *TrustedOriginResource) ActivateOrigin(trustedOriginId string) (*Trusted var trustedOrigin *TrustedOrigin - resp, err := m.client.requestExecutor.Do(req, &trustedOrigin) + resp, err := m.client.requestExecutor.Do(ctx, req, &trustedOrigin) if err != nil { return nil, resp, err } @@ -148,7 +149,7 @@ func (m *TrustedOriginResource) ActivateOrigin(trustedOriginId string) (*Trusted return trustedOrigin, resp, nil } -func (m *TrustedOriginResource) DeactivateOrigin(trustedOriginId string) (*TrustedOrigin, *Response, error) { +func (m *TrustedOriginResource) DeactivateOrigin(ctx context.Context, trustedOriginId string) (*TrustedOrigin, *Response, error) { url := fmt.Sprintf("/api/v1/trustedOrigins/%v/lifecycle/deactivate", trustedOriginId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -158,7 +159,7 @@ func (m *TrustedOriginResource) DeactivateOrigin(trustedOriginId string) (*Trust var trustedOrigin *TrustedOrigin - resp, err := m.client.requestExecutor.Do(req, &trustedOrigin) + resp, err := m.client.requestExecutor.Do(ctx, req, &trustedOrigin) if err != nil { return nil, resp, err } diff --git a/okta/user.go b/okta/user.go index 6aa9075a5..7e625a753 100644 --- a/okta/user.go +++ b/okta/user.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -44,7 +45,7 @@ type User struct { } // Creates a new user in your Okta organization with or without credentials. -func (m *UserResource) CreateUser(body CreateUserRequest, qp *query.Params) (*User, *Response, error) { +func (m *UserResource) CreateUser(ctx context.Context, body CreateUserRequest, qp *query.Params) (*User, *Response, error) { url := fmt.Sprintf("/api/v1/users") if qp != nil { url = url + qp.String() @@ -57,7 +58,7 @@ func (m *UserResource) CreateUser(body CreateUserRequest, qp *query.Params) (*Us var user *User - resp, err := m.client.requestExecutor.Do(req, &user) + resp, err := m.client.requestExecutor.Do(ctx, req, &user) if err != nil { return nil, resp, err } @@ -66,7 +67,7 @@ func (m *UserResource) CreateUser(body CreateUserRequest, qp *query.Params) (*Us } // Fetches a user from your Okta organization. -func (m *UserResource) GetUser(userId string) (*User, *Response, error) { +func (m *UserResource) GetUser(ctx context.Context, userId string) (*User, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -76,7 +77,7 @@ func (m *UserResource) GetUser(userId string) (*User, *Response, error) { var user *User - resp, err := m.client.requestExecutor.Do(req, &user) + resp, err := m.client.requestExecutor.Do(ctx, req, &user) if err != nil { return nil, resp, err } @@ -85,7 +86,7 @@ func (m *UserResource) GetUser(userId string) (*User, *Response, error) { } // Update a user's profile and/or credentials using strict-update semantics. -func (m *UserResource) UpdateUser(userId string, body User, qp *query.Params) (*User, *Response, error) { +func (m *UserResource) UpdateUser(ctx context.Context, userId string, body User, qp *query.Params) (*User, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v", userId) if qp != nil { url = url + qp.String() @@ -98,7 +99,7 @@ func (m *UserResource) UpdateUser(userId string, body User, qp *query.Params) (* var user *User - resp, err := m.client.requestExecutor.Do(req, &user) + resp, err := m.client.requestExecutor.Do(ctx, req, &user) if err != nil { return nil, resp, err } @@ -107,7 +108,7 @@ func (m *UserResource) UpdateUser(userId string, body User, qp *query.Params) (* } // Deletes a user permanently. This operation can only be performed on users that have a `DEPROVISIONED` status. **This action cannot be recovered!** -func (m *UserResource) DeactivateOrDeleteUser(userId string, qp *query.Params) (*Response, error) { +func (m *UserResource) DeactivateOrDeleteUser(ctx context.Context, userId string, qp *query.Params) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v", userId) if qp != nil { url = url + qp.String() @@ -118,7 +119,7 @@ func (m *UserResource) DeactivateOrDeleteUser(userId string, qp *query.Params) ( return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -127,7 +128,7 @@ func (m *UserResource) DeactivateOrDeleteUser(userId string, qp *query.Params) ( } // Lists users in your organization with pagination in most cases. A subset of users can be returned that match a supported filter expression or search criteria. -func (m *UserResource) ListUsers(qp *query.Params) ([]*User, *Response, error) { +func (m *UserResource) ListUsers(ctx context.Context, qp *query.Params) ([]*User, *Response, error) { url := fmt.Sprintf("/api/v1/users") if qp != nil { url = url + qp.String() @@ -140,7 +141,7 @@ func (m *UserResource) ListUsers(qp *query.Params) ([]*User, *Response, error) { var user []*User - resp, err := m.client.requestExecutor.Do(req, &user) + resp, err := m.client.requestExecutor.Do(ctx, req, &user) if err != nil { return nil, resp, err } @@ -149,7 +150,7 @@ func (m *UserResource) ListUsers(qp *query.Params) ([]*User, *Response, error) { } // Clears Okta sessions for the currently logged in user. By default, the current session remains active. Use this method in a browser-based application. -func (m *UserResource) ClearCurrentUserSessions(qp *query.Params) (*Response, error) { +func (m *UserResource) ClearCurrentUserSessions(ctx context.Context, qp *query.Params) (*Response, error) { url := fmt.Sprintf("/api/v1/users/me/lifecycle/delete_sessions") if qp != nil { url = url + qp.String() @@ -160,7 +161,7 @@ func (m *UserResource) ClearCurrentUserSessions(qp *query.Params) (*Response, er return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -168,7 +169,7 @@ func (m *UserResource) ClearCurrentUserSessions(qp *query.Params) (*Response, er return resp, nil } -func (m *UserResource) SetLinkedObjectForUser(associatedUserId string, primaryRelationshipName string, primaryUserId string) (*Response, error) { +func (m *UserResource) SetLinkedObjectForUser(ctx context.Context, associatedUserId string, primaryRelationshipName string, primaryUserId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/linkedObjects/%v/%v", associatedUserId, primaryRelationshipName, primaryUserId) req, err := m.client.requestExecutor.WithAccept("").WithContentType("application/json").NewRequest("PUT", url, nil) @@ -176,7 +177,7 @@ func (m *UserResource) SetLinkedObjectForUser(associatedUserId string, primaryRe return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -185,7 +186,7 @@ func (m *UserResource) SetLinkedObjectForUser(associatedUserId string, primaryRe } // Fetch a user by `id`, `login`, or `login shortname` if the short name is unambiguous. -func (m *UserResource) PartialUpdateUser(userId string, body User, qp *query.Params) (*User, *Response, error) { +func (m *UserResource) PartialUpdateUser(ctx context.Context, userId string, body User, qp *query.Params) (*User, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v", userId) if qp != nil { url = url + qp.String() @@ -198,7 +199,7 @@ func (m *UserResource) PartialUpdateUser(userId string, body User, qp *query.Par var user *User - resp, err := m.client.requestExecutor.Do(req, &user) + resp, err := m.client.requestExecutor.Do(ctx, req, &user) if err != nil { return nil, resp, err } @@ -207,7 +208,7 @@ func (m *UserResource) PartialUpdateUser(userId string, body User, qp *query.Par } // Fetches appLinks for all direct or indirect (via group membership) assigned applications. -func (m *UserResource) ListAppLinks(userId string) ([]*AppLink, *Response, error) { +func (m *UserResource) ListAppLinks(ctx context.Context, userId string) ([]*AppLink, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/appLinks", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -217,7 +218,7 @@ func (m *UserResource) ListAppLinks(userId string) ([]*AppLink, *Response, error var appLink []*AppLink - resp, err := m.client.requestExecutor.Do(req, &appLink) + resp, err := m.client.requestExecutor.Do(ctx, req, &appLink) if err != nil { return nil, resp, err } @@ -226,7 +227,7 @@ func (m *UserResource) ListAppLinks(userId string) ([]*AppLink, *Response, error } // Lists all client resources for which the specified user has grants or tokens. -func (m *UserResource) ListUserClients(userId string) ([]*OAuth2Client, *Response, error) { +func (m *UserResource) ListUserClients(ctx context.Context, userId string) ([]*OAuth2Client, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/clients", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -236,7 +237,7 @@ func (m *UserResource) ListUserClients(userId string) ([]*OAuth2Client, *Respons var oAuth2Client []*OAuth2Client - resp, err := m.client.requestExecutor.Do(req, &oAuth2Client) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2Client) if err != nil { return nil, resp, err } @@ -245,7 +246,7 @@ func (m *UserResource) ListUserClients(userId string) ([]*OAuth2Client, *Respons } // Revokes all grants for the specified user and client -func (m *UserResource) RevokeGrantsForUserAndClient(userId string, clientId string) (*Response, error) { +func (m *UserResource) RevokeGrantsForUserAndClient(ctx context.Context, userId string, clientId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/clients/%v/grants", userId, clientId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -253,7 +254,7 @@ func (m *UserResource) RevokeGrantsForUserAndClient(userId string, clientId stri return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -262,7 +263,7 @@ func (m *UserResource) RevokeGrantsForUserAndClient(userId string, clientId stri } // Lists all grants for a specified user and client -func (m *UserResource) ListGrantsForUserAndClient(userId string, clientId string, qp *query.Params) ([]*OAuth2ScopeConsentGrant, *Response, error) { +func (m *UserResource) ListGrantsForUserAndClient(ctx context.Context, userId string, clientId string, qp *query.Params) ([]*OAuth2ScopeConsentGrant, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/clients/%v/grants", userId, clientId) if qp != nil { url = url + qp.String() @@ -275,7 +276,7 @@ func (m *UserResource) ListGrantsForUserAndClient(userId string, clientId string var oAuth2ScopeConsentGrant []*OAuth2ScopeConsentGrant - resp, err := m.client.requestExecutor.Do(req, &oAuth2ScopeConsentGrant) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2ScopeConsentGrant) if err != nil { return nil, resp, err } @@ -284,7 +285,7 @@ func (m *UserResource) ListGrantsForUserAndClient(userId string, clientId string } // Revokes all refresh tokens issued for the specified User and Client. -func (m *UserResource) RevokeTokensForUserAndClient(userId string, clientId string) (*Response, error) { +func (m *UserResource) RevokeTokensForUserAndClient(ctx context.Context, userId string, clientId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/clients/%v/tokens", userId, clientId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -292,7 +293,7 @@ func (m *UserResource) RevokeTokensForUserAndClient(userId string, clientId stri return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -301,7 +302,7 @@ func (m *UserResource) RevokeTokensForUserAndClient(userId string, clientId stri } // Lists all refresh tokens issued for the specified User and Client. -func (m *UserResource) ListRefreshTokensForUserAndClient(userId string, clientId string, qp *query.Params) ([]*OAuth2RefreshToken, *Response, error) { +func (m *UserResource) ListRefreshTokensForUserAndClient(ctx context.Context, userId string, clientId string, qp *query.Params) ([]*OAuth2RefreshToken, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/clients/%v/tokens", userId, clientId) if qp != nil { url = url + qp.String() @@ -314,7 +315,7 @@ func (m *UserResource) ListRefreshTokensForUserAndClient(userId string, clientId var oAuth2RefreshToken []*OAuth2RefreshToken - resp, err := m.client.requestExecutor.Do(req, &oAuth2RefreshToken) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2RefreshToken) if err != nil { return nil, resp, err } @@ -323,7 +324,7 @@ func (m *UserResource) ListRefreshTokensForUserAndClient(userId string, clientId } // Revokes the specified refresh token. -func (m *UserResource) RevokeTokenForUserAndClient(userId string, clientId string, tokenId string) (*Response, error) { +func (m *UserResource) RevokeTokenForUserAndClient(ctx context.Context, userId string, clientId string, tokenId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/clients/%v/tokens/%v", userId, clientId, tokenId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -331,7 +332,7 @@ func (m *UserResource) RevokeTokenForUserAndClient(userId string, clientId strin return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -340,7 +341,7 @@ func (m *UserResource) RevokeTokenForUserAndClient(userId string, clientId strin } // Gets a refresh token issued for the specified User and Client. -func (m *UserResource) GetRefreshTokenForUserAndClient(userId string, clientId string, tokenId string, qp *query.Params) (*OAuth2RefreshToken, *Response, error) { +func (m *UserResource) GetRefreshTokenForUserAndClient(ctx context.Context, userId string, clientId string, tokenId string, qp *query.Params) (*OAuth2RefreshToken, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/clients/%v/tokens/%v", userId, clientId, tokenId) if qp != nil { url = url + qp.String() @@ -353,7 +354,7 @@ func (m *UserResource) GetRefreshTokenForUserAndClient(userId string, clientId s var oAuth2RefreshToken *OAuth2RefreshToken - resp, err := m.client.requestExecutor.Do(req, &oAuth2RefreshToken) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2RefreshToken) if err != nil { return nil, resp, err } @@ -362,7 +363,7 @@ func (m *UserResource) GetRefreshTokenForUserAndClient(userId string, clientId s } // Changes a user's password by validating the user's current password. This operation can only be performed on users in `STAGED`, `ACTIVE`, `PASSWORD_EXPIRED`, or `RECOVERY` status that have a valid password credential -func (m *UserResource) ChangePassword(userId string, body ChangePasswordRequest, qp *query.Params) (*UserCredentials, *Response, error) { +func (m *UserResource) ChangePassword(ctx context.Context, userId string, body ChangePasswordRequest, qp *query.Params) (*UserCredentials, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/credentials/change_password", userId) if qp != nil { url = url + qp.String() @@ -375,7 +376,7 @@ func (m *UserResource) ChangePassword(userId string, body ChangePasswordRequest, var userCredentials *UserCredentials - resp, err := m.client.requestExecutor.Do(req, &userCredentials) + resp, err := m.client.requestExecutor.Do(ctx, req, &userCredentials) if err != nil { return nil, resp, err } @@ -384,7 +385,7 @@ func (m *UserResource) ChangePassword(userId string, body ChangePasswordRequest, } // Changes a user's recovery question & answer credential by validating the user's current password. This operation can only be performed on users in **STAGED**, **ACTIVE** or **RECOVERY** `status` that have a valid password credential -func (m *UserResource) ChangeRecoveryQuestion(userId string, body UserCredentials) (*UserCredentials, *Response, error) { +func (m *UserResource) ChangeRecoveryQuestion(ctx context.Context, userId string, body UserCredentials) (*UserCredentials, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/credentials/change_recovery_question", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -394,7 +395,7 @@ func (m *UserResource) ChangeRecoveryQuestion(userId string, body UserCredential var userCredentials *UserCredentials - resp, err := m.client.requestExecutor.Do(req, &userCredentials) + resp, err := m.client.requestExecutor.Do(ctx, req, &userCredentials) if err != nil { return nil, resp, err } @@ -403,7 +404,7 @@ func (m *UserResource) ChangeRecoveryQuestion(userId string, body UserCredential } // Generates a one-time token (OTT) that can be used to reset a user's password -func (m *UserResource) ForgotPasswordGenerateOneTimeToken(userId string, qp *query.Params) (*ForgotPasswordResponse, *Response, error) { +func (m *UserResource) ForgotPasswordGenerateOneTimeToken(ctx context.Context, userId string, qp *query.Params) (*ForgotPasswordResponse, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/credentials/forgot_password", userId) if qp != nil { url = url + qp.String() @@ -416,7 +417,7 @@ func (m *UserResource) ForgotPasswordGenerateOneTimeToken(userId string, qp *que var forgotPasswordResponse *ForgotPasswordResponse - resp, err := m.client.requestExecutor.Do(req, &forgotPasswordResponse) + resp, err := m.client.requestExecutor.Do(ctx, req, &forgotPasswordResponse) if err != nil { return nil, resp, err } @@ -425,7 +426,7 @@ func (m *UserResource) ForgotPasswordGenerateOneTimeToken(userId string, qp *que } // Sets a new password for a user by validating the user's answer to their current recovery question -func (m *UserResource) ForgotPasswordSetNewPassword(userId string, body UserCredentials, qp *query.Params) (*ForgotPasswordResponse, *Response, error) { +func (m *UserResource) ForgotPasswordSetNewPassword(ctx context.Context, userId string, body UserCredentials, qp *query.Params) (*ForgotPasswordResponse, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/credentials/forgot_password", userId) if qp != nil { url = url + qp.String() @@ -438,7 +439,7 @@ func (m *UserResource) ForgotPasswordSetNewPassword(userId string, body UserCred var forgotPasswordResponse *ForgotPasswordResponse - resp, err := m.client.requestExecutor.Do(req, &forgotPasswordResponse) + resp, err := m.client.requestExecutor.Do(ctx, req, &forgotPasswordResponse) if err != nil { return nil, resp, err } @@ -447,7 +448,7 @@ func (m *UserResource) ForgotPasswordSetNewPassword(userId string, body UserCred } // Revokes all grants for a specified user -func (m *UserResource) RevokeUserGrants(userId string) (*Response, error) { +func (m *UserResource) RevokeUserGrants(ctx context.Context, userId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/grants", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -455,7 +456,7 @@ func (m *UserResource) RevokeUserGrants(userId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -464,7 +465,7 @@ func (m *UserResource) RevokeUserGrants(userId string) (*Response, error) { } // Lists all grants for the specified user -func (m *UserResource) ListUserGrants(userId string, qp *query.Params) ([]*OAuth2ScopeConsentGrant, *Response, error) { +func (m *UserResource) ListUserGrants(ctx context.Context, userId string, qp *query.Params) ([]*OAuth2ScopeConsentGrant, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/grants", userId) if qp != nil { url = url + qp.String() @@ -477,7 +478,7 @@ func (m *UserResource) ListUserGrants(userId string, qp *query.Params) ([]*OAuth var oAuth2ScopeConsentGrant []*OAuth2ScopeConsentGrant - resp, err := m.client.requestExecutor.Do(req, &oAuth2ScopeConsentGrant) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2ScopeConsentGrant) if err != nil { return nil, resp, err } @@ -486,7 +487,7 @@ func (m *UserResource) ListUserGrants(userId string, qp *query.Params) ([]*OAuth } // Revokes one grant for a specified user -func (m *UserResource) RevokeUserGrant(userId string, grantId string) (*Response, error) { +func (m *UserResource) RevokeUserGrant(ctx context.Context, userId string, grantId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/grants/%v", userId, grantId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -494,7 +495,7 @@ func (m *UserResource) RevokeUserGrant(userId string, grantId string) (*Response return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -503,7 +504,7 @@ func (m *UserResource) RevokeUserGrant(userId string, grantId string) (*Response } // Gets a grant for the specified user -func (m *UserResource) GetUserGrant(userId string, grantId string, qp *query.Params) (*OAuth2ScopeConsentGrant, *Response, error) { +func (m *UserResource) GetUserGrant(ctx context.Context, userId string, grantId string, qp *query.Params) (*OAuth2ScopeConsentGrant, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/grants/%v", userId, grantId) if qp != nil { url = url + qp.String() @@ -516,7 +517,7 @@ func (m *UserResource) GetUserGrant(userId string, grantId string, qp *query.Par var oAuth2ScopeConsentGrant *OAuth2ScopeConsentGrant - resp, err := m.client.requestExecutor.Do(req, &oAuth2ScopeConsentGrant) + resp, err := m.client.requestExecutor.Do(ctx, req, &oAuth2ScopeConsentGrant) if err != nil { return nil, resp, err } @@ -525,7 +526,7 @@ func (m *UserResource) GetUserGrant(userId string, grantId string, qp *query.Par } // Fetches the groups of which the user is a member. -func (m *UserResource) ListUserGroups(userId string) ([]*Group, *Response, error) { +func (m *UserResource) ListUserGroups(ctx context.Context, userId string) ([]*Group, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/groups", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -535,7 +536,7 @@ func (m *UserResource) ListUserGroups(userId string) ([]*Group, *Response, error var group []*Group - resp, err := m.client.requestExecutor.Do(req, &group) + resp, err := m.client.requestExecutor.Do(ctx, req, &group) if err != nil { return nil, resp, err } @@ -544,7 +545,7 @@ func (m *UserResource) ListUserGroups(userId string) ([]*Group, *Response, error } // Lists the IdPs associated with the user. -func (m *UserResource) ListUserIdentityProviders(userId string) ([]*IdentityProvider, *Response, error) { +func (m *UserResource) ListUserIdentityProviders(ctx context.Context, userId string) ([]*IdentityProvider, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/idps", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -554,7 +555,7 @@ func (m *UserResource) ListUserIdentityProviders(userId string) ([]*IdentityProv var identityProvider []*IdentityProvider - resp, err := m.client.requestExecutor.Do(req, &identityProvider) + resp, err := m.client.requestExecutor.Do(ctx, req, &identityProvider) if err != nil { return nil, resp, err } @@ -563,7 +564,7 @@ func (m *UserResource) ListUserIdentityProviders(userId string) ([]*IdentityProv } // Activates a user. This operation can only be performed on users with a `STAGED` status. Activation of a user is an asynchronous operation. The user will have the `transitioningToStatus` property with a value of `ACTIVE` during activation to indicate that the user hasn't completed the asynchronous operation. The user will have a status of `ACTIVE` when the activation process is complete. -func (m *UserResource) ActivateUser(userId string, qp *query.Params) (*UserActivationToken, *Response, error) { +func (m *UserResource) ActivateUser(ctx context.Context, userId string, qp *query.Params) (*UserActivationToken, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/lifecycle/activate", userId) if qp != nil { url = url + qp.String() @@ -576,7 +577,7 @@ func (m *UserResource) ActivateUser(userId string, qp *query.Params) (*UserActiv var userActivationToken *UserActivationToken - resp, err := m.client.requestExecutor.Do(req, &userActivationToken) + resp, err := m.client.requestExecutor.Do(ctx, req, &userActivationToken) if err != nil { return nil, resp, err } @@ -585,7 +586,7 @@ func (m *UserResource) ActivateUser(userId string, qp *query.Params) (*UserActiv } // Deactivates a user. This operation can only be performed on users that do not have a `DEPROVISIONED` status. Deactivation of a user is an asynchronous operation. The user will have the `transitioningToStatus` property with a value of `DEPROVISIONED` during deactivation to indicate that the user hasn't completed the asynchronous operation. The user will have a status of `DEPROVISIONED` when the deactivation process is complete. -func (m *UserResource) DeactivateUser(userId string, qp *query.Params) (*Response, error) { +func (m *UserResource) DeactivateUser(ctx context.Context, userId string, qp *query.Params) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/lifecycle/deactivate", userId) if qp != nil { url = url + qp.String() @@ -596,7 +597,7 @@ func (m *UserResource) DeactivateUser(userId string, qp *query.Params) (*Respons return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -605,7 +606,7 @@ func (m *UserResource) DeactivateUser(userId string, qp *query.Params) (*Respons } // This operation transitions the user to the status of `PASSWORD_EXPIRED` so that the user is required to change their password at their next login. -func (m *UserResource) ExpirePassword(userId string) (*User, *Response, error) { +func (m *UserResource) ExpirePassword(ctx context.Context, userId string) (*User, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/lifecycle/expire_password?tempPassword=false", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -615,7 +616,7 @@ func (m *UserResource) ExpirePassword(userId string) (*User, *Response, error) { var user *User - resp, err := m.client.requestExecutor.Do(req, &user) + resp, err := m.client.requestExecutor.Do(ctx, req, &user) if err != nil { return nil, resp, err } @@ -624,7 +625,7 @@ func (m *UserResource) ExpirePassword(userId string) (*User, *Response, error) { } // This operation transitions the user to the status of `PASSWORD_EXPIRED` and the user's password is reset to a temporary password that is returned. -func (m *UserResource) ExpirePasswordAndGetTemporaryPassword(userId string) (*TempPassword, *Response, error) { +func (m *UserResource) ExpirePasswordAndGetTemporaryPassword(ctx context.Context, userId string) (*TempPassword, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/lifecycle/expire_password?tempPassword=true", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -634,7 +635,7 @@ func (m *UserResource) ExpirePasswordAndGetTemporaryPassword(userId string) (*Te var tempPassword *TempPassword - resp, err := m.client.requestExecutor.Do(req, &tempPassword) + resp, err := m.client.requestExecutor.Do(ctx, req, &tempPassword) if err != nil { return nil, resp, err } @@ -643,7 +644,7 @@ func (m *UserResource) ExpirePasswordAndGetTemporaryPassword(userId string) (*Te } // Reactivates a user. This operation can only be performed on users with a `PROVISIONED` status. This operation restarts the activation workflow if for some reason the user activation was not completed when using the activationToken from [Activate User](#activate-user). -func (m *UserResource) ReactivateUser(userId string, qp *query.Params) (*UserActivationToken, *Response, error) { +func (m *UserResource) ReactivateUser(ctx context.Context, userId string, qp *query.Params) (*UserActivationToken, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/lifecycle/reactivate", userId) if qp != nil { url = url + qp.String() @@ -656,7 +657,7 @@ func (m *UserResource) ReactivateUser(userId string, qp *query.Params) (*UserAct var userActivationToken *UserActivationToken - resp, err := m.client.requestExecutor.Do(req, &userActivationToken) + resp, err := m.client.requestExecutor.Do(ctx, req, &userActivationToken) if err != nil { return nil, resp, err } @@ -665,7 +666,7 @@ func (m *UserResource) ReactivateUser(userId string, qp *query.Params) (*UserAct } // This operation resets all factors for the specified user. All MFA factor enrollments returned to the unenrolled state. The user's status remains ACTIVE. This link is present only if the user is currently enrolled in one or more MFA factors. -func (m *UserResource) ResetFactors(userId string) (*Response, error) { +func (m *UserResource) ResetFactors(ctx context.Context, userId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/lifecycle/reset_factors", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -673,7 +674,7 @@ func (m *UserResource) ResetFactors(userId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -682,7 +683,7 @@ func (m *UserResource) ResetFactors(userId string) (*Response, error) { } // Generates a one-time token (OTT) that can be used to reset a user's password. The OTT link can be automatically emailed to the user or returned to the API caller and distributed using a custom flow. -func (m *UserResource) ResetPassword(userId string, qp *query.Params) (*ResetPasswordToken, *Response, error) { +func (m *UserResource) ResetPassword(ctx context.Context, userId string, qp *query.Params) (*ResetPasswordToken, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/lifecycle/reset_password", userId) if qp != nil { url = url + qp.String() @@ -695,7 +696,7 @@ func (m *UserResource) ResetPassword(userId string, qp *query.Params) (*ResetPas var resetPasswordToken *ResetPasswordToken - resp, err := m.client.requestExecutor.Do(req, &resetPasswordToken) + resp, err := m.client.requestExecutor.Do(ctx, req, &resetPasswordToken) if err != nil { return nil, resp, err } @@ -704,7 +705,7 @@ func (m *UserResource) ResetPassword(userId string, qp *query.Params) (*ResetPas } // Suspends a user. This operation can only be performed on users with an `ACTIVE` status. The user will have a status of `SUSPENDED` when the process is complete. -func (m *UserResource) SuspendUser(userId string) (*Response, error) { +func (m *UserResource) SuspendUser(ctx context.Context, userId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/lifecycle/suspend", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -712,7 +713,7 @@ func (m *UserResource) SuspendUser(userId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -721,7 +722,7 @@ func (m *UserResource) SuspendUser(userId string) (*Response, error) { } // Unlocks a user with a `LOCKED_OUT` status and returns them to `ACTIVE` status. Users will be able to login with their current password. -func (m *UserResource) UnlockUser(userId string) (*Response, error) { +func (m *UserResource) UnlockUser(ctx context.Context, userId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/lifecycle/unlock", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -729,7 +730,7 @@ func (m *UserResource) UnlockUser(userId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -738,7 +739,7 @@ func (m *UserResource) UnlockUser(userId string) (*Response, error) { } // Unsuspends a user and returns them to the `ACTIVE` state. This operation can only be performed on users that have a `SUSPENDED` status. -func (m *UserResource) UnsuspendUser(userId string) (*Response, error) { +func (m *UserResource) UnsuspendUser(ctx context.Context, userId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/lifecycle/unsuspend", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, nil) @@ -746,7 +747,7 @@ func (m *UserResource) UnsuspendUser(userId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -755,7 +756,7 @@ func (m *UserResource) UnsuspendUser(userId string) (*Response, error) { } // Delete linked objects for a user, relationshipName can be ONLY a primary relationship name -func (m *UserResource) RemoveLinkedObjectForUser(userId string, relationshipName string) (*Response, error) { +func (m *UserResource) RemoveLinkedObjectForUser(ctx context.Context, userId string, relationshipName string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/linkedObjects/%v", userId, relationshipName) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -763,7 +764,7 @@ func (m *UserResource) RemoveLinkedObjectForUser(userId string, relationshipName return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -772,7 +773,7 @@ func (m *UserResource) RemoveLinkedObjectForUser(userId string, relationshipName } // Get linked objects for a user, relationshipName can be a primary or associated relationship name -func (m *UserResource) GetLinkedObjectsForUser(userId string, relationshipName string, qp *query.Params) ([]*ResponseLinks, *Response, error) { +func (m *UserResource) GetLinkedObjectsForUser(ctx context.Context, userId string, relationshipName string, qp *query.Params) ([]*ResponseLinks, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/linkedObjects/%v", userId, relationshipName) if qp != nil { url = url + qp.String() @@ -785,7 +786,7 @@ func (m *UserResource) GetLinkedObjectsForUser(userId string, relationshipName s var responseLinks []*ResponseLinks - resp, err := m.client.requestExecutor.Do(req, &responseLinks) + resp, err := m.client.requestExecutor.Do(ctx, req, &responseLinks) if err != nil { return nil, resp, err } @@ -794,7 +795,7 @@ func (m *UserResource) GetLinkedObjectsForUser(userId string, relationshipName s } // Lists all roles assigned to a user. -func (m *UserResource) ListAssignedRolesForUser(userId string, qp *query.Params) ([]*Role, *Response, error) { +func (m *UserResource) ListAssignedRolesForUser(ctx context.Context, userId string, qp *query.Params) ([]*Role, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles", userId) if qp != nil { url = url + qp.String() @@ -807,7 +808,7 @@ func (m *UserResource) ListAssignedRolesForUser(userId string, qp *query.Params) var role []*Role - resp, err := m.client.requestExecutor.Do(req, &role) + resp, err := m.client.requestExecutor.Do(ctx, req, &role) if err != nil { return nil, resp, err } @@ -816,7 +817,7 @@ func (m *UserResource) ListAssignedRolesForUser(userId string, qp *query.Params) } // Assigns a role to a user. -func (m *UserResource) AssignRoleToUser(userId string, body AssignRoleRequest, qp *query.Params) (*Role, *Response, error) { +func (m *UserResource) AssignRoleToUser(ctx context.Context, userId string, body AssignRoleRequest, qp *query.Params) (*Role, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles", userId) if qp != nil { url = url + qp.String() @@ -829,7 +830,7 @@ func (m *UserResource) AssignRoleToUser(userId string, body AssignRoleRequest, q var role *Role - resp, err := m.client.requestExecutor.Do(req, &role) + resp, err := m.client.requestExecutor.Do(ctx, req, &role) if err != nil { return nil, resp, err } @@ -838,7 +839,7 @@ func (m *UserResource) AssignRoleToUser(userId string, body AssignRoleRequest, q } // Unassigns a role from a user. -func (m *UserResource) RemoveRoleFromUser(userId string, roleId string) (*Response, error) { +func (m *UserResource) RemoveRoleFromUser(ctx context.Context, userId string, roleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles/%v", userId, roleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -846,7 +847,7 @@ func (m *UserResource) RemoveRoleFromUser(userId string, roleId string) (*Respon return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -855,7 +856,7 @@ func (m *UserResource) RemoveRoleFromUser(userId string, roleId string) (*Respon } // Lists all App targets for an `APP_ADMIN` Role assigned to a User. This methods return list may include full Applications or Instances. The response for an instance will have an `ID` value, while Application will not have an ID. -func (m *UserResource) ListApplicationTargetsForApplicationAdministratorRoleForUser(userId string, roleId string, qp *query.Params) ([]App, *Response, error) { +func (m *UserResource) ListApplicationTargetsForApplicationAdministratorRoleForUser(ctx context.Context, userId string, roleId string, qp *query.Params) ([]App, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles/%v/targets/catalog/apps", userId, roleId) if qp != nil { url = url + qp.String() @@ -868,7 +869,7 @@ func (m *UserResource) ListApplicationTargetsForApplicationAdministratorRoleForU var application []Application - resp, err := m.client.requestExecutor.Do(req, &application) + resp, err := m.client.requestExecutor.Do(ctx, req, &application) if err != nil { return nil, resp, err } @@ -881,7 +882,7 @@ func (m *UserResource) ListApplicationTargetsForApplicationAdministratorRoleForU } -func (m *UserResource) AddAllAppsAsTargetToRole(userId string, roleId string) (*Response, error) { +func (m *UserResource) AddAllAppsAsTargetToRole(ctx context.Context, userId string, roleId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles/%v/targets/catalog/apps", userId, roleId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, nil) @@ -889,7 +890,7 @@ func (m *UserResource) AddAllAppsAsTargetToRole(userId string, roleId string) (* return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -897,7 +898,7 @@ func (m *UserResource) AddAllAppsAsTargetToRole(userId string, roleId string) (* return resp, nil } -func (m *UserResource) RemoveApplicationTargetFromApplicationAdministratorRoleForUser(userId string, roleId string, appName string) (*Response, error) { +func (m *UserResource) RemoveApplicationTargetFromApplicationAdministratorRoleForUser(ctx context.Context, userId string, roleId string, appName string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles/%v/targets/catalog/apps/%v", userId, roleId, appName) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -905,7 +906,7 @@ func (m *UserResource) RemoveApplicationTargetFromApplicationAdministratorRoleFo return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -913,7 +914,7 @@ func (m *UserResource) RemoveApplicationTargetFromApplicationAdministratorRoleFo return resp, nil } -func (m *UserResource) AddApplicationTargetToAdminRoleForUser(userId string, roleId string, appName string) (*Response, error) { +func (m *UserResource) AddApplicationTargetToAdminRoleForUser(ctx context.Context, userId string, roleId string, appName string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles/%v/targets/catalog/apps/%v", userId, roleId, appName) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, nil) @@ -921,7 +922,7 @@ func (m *UserResource) AddApplicationTargetToAdminRoleForUser(userId string, rol return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -930,7 +931,7 @@ func (m *UserResource) AddApplicationTargetToAdminRoleForUser(userId string, rol } // Remove App Instance Target to App Administrator Role given to a User -func (m *UserResource) RemoveApplicationTargetFromAdministratorRoleForUser(userId string, roleId string, appName string, applicationId string) (*Response, error) { +func (m *UserResource) RemoveApplicationTargetFromAdministratorRoleForUser(ctx context.Context, userId string, roleId string, appName string, applicationId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles/%v/targets/catalog/apps/%v/%v", userId, roleId, appName, applicationId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -938,7 +939,7 @@ func (m *UserResource) RemoveApplicationTargetFromAdministratorRoleForUser(userI return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -947,7 +948,7 @@ func (m *UserResource) RemoveApplicationTargetFromAdministratorRoleForUser(userI } // Add App Instance Target to App Administrator Role given to a User -func (m *UserResource) AddApplicationTargetToAppAdminRoleForUser(userId string, roleId string, appName string, applicationId string) (*Response, error) { +func (m *UserResource) AddApplicationTargetToAppAdminRoleForUser(ctx context.Context, userId string, roleId string, appName string, applicationId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles/%v/targets/catalog/apps/%v/%v", userId, roleId, appName, applicationId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, nil) @@ -955,7 +956,7 @@ func (m *UserResource) AddApplicationTargetToAppAdminRoleForUser(userId string, return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -963,7 +964,7 @@ func (m *UserResource) AddApplicationTargetToAppAdminRoleForUser(userId string, return resp, nil } -func (m *UserResource) ListGroupTargetsForRole(userId string, roleId string, qp *query.Params) ([]*Group, *Response, error) { +func (m *UserResource) ListGroupTargetsForRole(ctx context.Context, userId string, roleId string, qp *query.Params) ([]*Group, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles/%v/targets/groups", userId, roleId) if qp != nil { url = url + qp.String() @@ -976,7 +977,7 @@ func (m *UserResource) ListGroupTargetsForRole(userId string, roleId string, qp var group []*Group - resp, err := m.client.requestExecutor.Do(req, &group) + resp, err := m.client.requestExecutor.Do(ctx, req, &group) if err != nil { return nil, resp, err } @@ -984,7 +985,7 @@ func (m *UserResource) ListGroupTargetsForRole(userId string, roleId string, qp return group, resp, nil } -func (m *UserResource) RemoveGroupTargetFromRole(userId string, roleId string, groupId string) (*Response, error) { +func (m *UserResource) RemoveGroupTargetFromRole(ctx context.Context, userId string, roleId string, groupId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles/%v/targets/groups/%v", userId, roleId, groupId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -992,7 +993,7 @@ func (m *UserResource) RemoveGroupTargetFromRole(userId string, roleId string, g return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -1000,7 +1001,7 @@ func (m *UserResource) RemoveGroupTargetFromRole(userId string, roleId string, g return resp, nil } -func (m *UserResource) AddGroupTargetToRole(userId string, roleId string, groupId string) (*Response, error) { +func (m *UserResource) AddGroupTargetToRole(ctx context.Context, userId string, roleId string, groupId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/roles/%v/targets/groups/%v", userId, roleId, groupId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, nil) @@ -1008,7 +1009,7 @@ func (m *UserResource) AddGroupTargetToRole(userId string, roleId string, groupI return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -1017,7 +1018,7 @@ func (m *UserResource) AddGroupTargetToRole(userId string, roleId string, groupI } // Removes all active identity provider sessions. This forces the user to authenticate on the next operation. Optionally revokes OpenID Connect and OAuth refresh and access tokens issued to the user. -func (m *UserResource) ClearUserSessions(userId string, qp *query.Params) (*Response, error) { +func (m *UserResource) ClearUserSessions(ctx context.Context, userId string, qp *query.Params) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/sessions", userId) if qp != nil { url = url + qp.String() @@ -1028,7 +1029,7 @@ func (m *UserResource) ClearUserSessions(userId string, qp *query.Params) (*Resp return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } diff --git a/okta/userFactor.go b/okta/userFactor.go index 2b2bba0fd..072902dff 100644 --- a/okta/userFactor.go +++ b/okta/userFactor.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "github.com/okta/okta-sdk-golang/v2/okta/query" "time" @@ -51,7 +52,7 @@ func (a *UserFactor) IsUserFactorInstance() bool { } // Unenrolls an existing factor for the specified user, allowing the user to enroll a new factor. -func (m *UserFactorResource) DeleteFactor(userId string, factorId string) (*Response, error) { +func (m *UserFactorResource) DeleteFactor(ctx context.Context, userId string, factorId string) (*Response, error) { url := fmt.Sprintf("/api/v1/users/%v/factors/%v", userId, factorId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -59,7 +60,7 @@ func (m *UserFactorResource) DeleteFactor(userId string, factorId string) (*Resp return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -68,7 +69,7 @@ func (m *UserFactorResource) DeleteFactor(userId string, factorId string) (*Resp } // Enumerates all the enrolled factors for the specified user -func (m *UserFactorResource) ListFactors(userId string) ([]Factor, *Response, error) { +func (m *UserFactorResource) ListFactors(ctx context.Context, userId string) ([]Factor, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/factors", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -78,7 +79,7 @@ func (m *UserFactorResource) ListFactors(userId string) ([]Factor, *Response, er var userFactor []UserFactor - resp, err := m.client.requestExecutor.Do(req, &userFactor) + resp, err := m.client.requestExecutor.Do(ctx, req, &userFactor) if err != nil { return nil, resp, err } @@ -92,7 +93,7 @@ func (m *UserFactorResource) ListFactors(userId string) ([]Factor, *Response, er } // Enrolls a user with a supported factor. -func (m *UserFactorResource) EnrollFactor(userId string, body Factor, qp *query.Params) (Factor, *Response, error) { +func (m *UserFactorResource) EnrollFactor(ctx context.Context, userId string, body Factor, qp *query.Params) (Factor, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/factors", userId) if qp != nil { url = url + qp.String() @@ -105,7 +106,7 @@ func (m *UserFactorResource) EnrollFactor(userId string, body Factor, qp *query. var userFactor *UserFactor - resp, err := m.client.requestExecutor.Do(req, &userFactor) + resp, err := m.client.requestExecutor.Do(ctx, req, &userFactor) if err != nil { return nil, resp, err } @@ -114,7 +115,7 @@ func (m *UserFactorResource) EnrollFactor(userId string, body Factor, qp *query. } // Enumerates all the supported factors that can be enrolled for the specified user -func (m *UserFactorResource) ListSupportedFactors(userId string) ([]Factor, *Response, error) { +func (m *UserFactorResource) ListSupportedFactors(ctx context.Context, userId string) ([]Factor, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/factors/catalog", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -124,7 +125,7 @@ func (m *UserFactorResource) ListSupportedFactors(userId string) ([]Factor, *Res var userFactor []UserFactor - resp, err := m.client.requestExecutor.Do(req, &userFactor) + resp, err := m.client.requestExecutor.Do(ctx, req, &userFactor) if err != nil { return nil, resp, err } @@ -138,7 +139,7 @@ func (m *UserFactorResource) ListSupportedFactors(userId string) ([]Factor, *Res } // Enumerates all available security questions for a user's `question` factor -func (m *UserFactorResource) ListSupportedSecurityQuestions(userId string) ([]*SecurityQuestion, *Response, error) { +func (m *UserFactorResource) ListSupportedSecurityQuestions(ctx context.Context, userId string) ([]*SecurityQuestion, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/factors/questions", userId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -148,7 +149,7 @@ func (m *UserFactorResource) ListSupportedSecurityQuestions(userId string) ([]*S var securityQuestion []*SecurityQuestion - resp, err := m.client.requestExecutor.Do(req, &securityQuestion) + resp, err := m.client.requestExecutor.Do(ctx, req, &securityQuestion) if err != nil { return nil, resp, err } @@ -157,7 +158,7 @@ func (m *UserFactorResource) ListSupportedSecurityQuestions(userId string) ([]*S } // Fetches a factor for the specified user -func (m *UserFactorResource) GetFactor(userId string, factorId string, factorInstance Factor) (Factor, *Response, error) { +func (m *UserFactorResource) GetFactor(ctx context.Context, userId string, factorId string, factorInstance Factor) (Factor, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/factors/%v", userId, factorId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -167,7 +168,7 @@ func (m *UserFactorResource) GetFactor(userId string, factorId string, factorIns var userFactor *UserFactor - resp, err := m.client.requestExecutor.Do(req, &userFactor) + resp, err := m.client.requestExecutor.Do(ctx, req, &userFactor) if err != nil { return nil, resp, err } @@ -176,7 +177,7 @@ func (m *UserFactorResource) GetFactor(userId string, factorId string, factorIns } // The `sms` and `token:software:totp` factor types require activation to complete the enrollment process. -func (m *UserFactorResource) ActivateFactor(userId string, factorId string, body VerifyFactorRequest, factorInstance Factor) (Factor, *Response, error) { +func (m *UserFactorResource) ActivateFactor(ctx context.Context, userId string, factorId string, body VerifyFactorRequest, factorInstance Factor) (Factor, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/factors/%v/lifecycle/activate", userId, factorId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -186,7 +187,7 @@ func (m *UserFactorResource) ActivateFactor(userId string, factorId string, body var userFactor *UserFactor - resp, err := m.client.requestExecutor.Do(req, &userFactor) + resp, err := m.client.requestExecutor.Do(ctx, req, &userFactor) if err != nil { return nil, resp, err } @@ -195,7 +196,7 @@ func (m *UserFactorResource) ActivateFactor(userId string, factorId string, body } // Polls factors verification transaction for status. -func (m *UserFactorResource) GetFactorTransactionStatus(userId string, factorId string, transactionId string) (*VerifyUserFactorResponse, *Response, error) { +func (m *UserFactorResource) GetFactorTransactionStatus(ctx context.Context, userId string, factorId string, transactionId string) (*VerifyUserFactorResponse, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/factors/%v/transactions/%v", userId, factorId, transactionId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -205,7 +206,7 @@ func (m *UserFactorResource) GetFactorTransactionStatus(userId string, factorId var verifyUserFactorResponse *VerifyUserFactorResponse - resp, err := m.client.requestExecutor.Do(req, &verifyUserFactorResponse) + resp, err := m.client.requestExecutor.Do(ctx, req, &verifyUserFactorResponse) if err != nil { return nil, resp, err } @@ -214,7 +215,7 @@ func (m *UserFactorResource) GetFactorTransactionStatus(userId string, factorId } // Verifies an OTP for a `token` or `token:hardware` factor -func (m *UserFactorResource) VerifyFactor(userId string, factorId string, body VerifyFactorRequest, factorInstance Factor, qp *query.Params) (*VerifyUserFactorResponse, *Response, error) { +func (m *UserFactorResource) VerifyFactor(ctx context.Context, userId string, factorId string, body VerifyFactorRequest, factorInstance Factor, qp *query.Params) (*VerifyUserFactorResponse, *Response, error) { url := fmt.Sprintf("/api/v1/users/%v/factors/%v/verify", userId, factorId) if qp != nil { url = url + qp.String() @@ -227,7 +228,7 @@ func (m *UserFactorResource) VerifyFactor(userId string, factorId string, body V var verifyUserFactorResponse *VerifyUserFactorResponse - resp, err := m.client.requestExecutor.Do(req, &verifyUserFactorResponse) + resp, err := m.client.requestExecutor.Do(ctx, req, &verifyUserFactorResponse) if err != nil { return nil, resp, err } diff --git a/okta/userType.go b/okta/userType.go index 1fc57a0ff..53e77add2 100644 --- a/okta/userType.go +++ b/okta/userType.go @@ -19,6 +19,7 @@ package okta import ( + "context" "fmt" "time" ) @@ -39,7 +40,7 @@ type UserType struct { } // Updates an existing User Type -func (m *UserTypeResource) UpdateUserType(typeId string, body UserType) (*UserType, *Response, error) { +func (m *UserTypeResource) UpdateUserType(ctx context.Context, typeId string, body UserType) (*UserType, *Response, error) { url := fmt.Sprintf("/api/v1/meta/types/user/%v", typeId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -49,7 +50,7 @@ func (m *UserTypeResource) UpdateUserType(typeId string, body UserType) (*UserTy var userType *UserType - resp, err := m.client.requestExecutor.Do(req, &userType) + resp, err := m.client.requestExecutor.Do(ctx, req, &userType) if err != nil { return nil, resp, err } @@ -58,7 +59,7 @@ func (m *UserTypeResource) UpdateUserType(typeId string, body UserType) (*UserTy } // Fetches a User Type by ID. The special identifier `default` may be used to fetch the default User Type. -func (m *UserTypeResource) GetUserType(typeId string) (*UserType, *Response, error) { +func (m *UserTypeResource) GetUserType(ctx context.Context, typeId string) (*UserType, *Response, error) { url := fmt.Sprintf("/api/v1/meta/types/user/%v", typeId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -68,7 +69,7 @@ func (m *UserTypeResource) GetUserType(typeId string) (*UserType, *Response, err var userType *UserType - resp, err := m.client.requestExecutor.Do(req, &userType) + resp, err := m.client.requestExecutor.Do(ctx, req, &userType) if err != nil { return nil, resp, err } @@ -77,7 +78,7 @@ func (m *UserTypeResource) GetUserType(typeId string) (*UserType, *Response, err } // Deletes a User Type permanently. This operation is not permitted for the default type, nor for any User Type that has existing users -func (m *UserTypeResource) DeleteUserType(typeId string) (*Response, error) { +func (m *UserTypeResource) DeleteUserType(ctx context.Context, typeId string) (*Response, error) { url := fmt.Sprintf("/api/v1/meta/types/user/%v", typeId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil) @@ -85,7 +86,7 @@ func (m *UserTypeResource) DeleteUserType(typeId string) (*Response, error) { return nil, err } - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } @@ -94,7 +95,7 @@ func (m *UserTypeResource) DeleteUserType(typeId string) (*Response, error) { } // Fetches all User Types in your org -func (m *UserTypeResource) ListUserTypes() ([]*UserType, *Response, error) { +func (m *UserTypeResource) ListUserTypes(ctx context.Context) ([]*UserType, *Response, error) { url := fmt.Sprintf("/api/v1/meta/types/user") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil) @@ -104,7 +105,7 @@ func (m *UserTypeResource) ListUserTypes() ([]*UserType, *Response, error) { var userType []*UserType - resp, err := m.client.requestExecutor.Do(req, &userType) + resp, err := m.client.requestExecutor.Do(ctx, req, &userType) if err != nil { return nil, resp, err } @@ -113,7 +114,7 @@ func (m *UserTypeResource) ListUserTypes() ([]*UserType, *Response, error) { } // Creates a new User Type. A default User Type is automatically created along with your org, and you may add another 9 User Types for a maximum of 10. -func (m *UserTypeResource) CreateUserType(body UserType) (*UserType, *Response, error) { +func (m *UserTypeResource) CreateUserType(ctx context.Context, body UserType) (*UserType, *Response, error) { url := fmt.Sprintf("/api/v1/meta/types/user") req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body) @@ -123,7 +124,7 @@ func (m *UserTypeResource) CreateUserType(body UserType) (*UserType, *Response, var userType *UserType - resp, err := m.client.requestExecutor.Do(req, &userType) + resp, err := m.client.requestExecutor.Do(ctx, req, &userType) if err != nil { return nil, resp, err } @@ -132,7 +133,7 @@ func (m *UserTypeResource) CreateUserType(body UserType) (*UserType, *Response, } // Replace an existing User Type -func (m *UserTypeResource) ReplaceUserType(typeId string, body UserType) (*UserType, *Response, error) { +func (m *UserTypeResource) ReplaceUserType(ctx context.Context, typeId string, body UserType) (*UserType, *Response, error) { url := fmt.Sprintf("/api/v1/meta/types/user/%v", typeId) req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("PUT", url, body) @@ -142,7 +143,7 @@ func (m *UserTypeResource) ReplaceUserType(typeId string, body UserType) (*UserT var userType *UserType - resp, err := m.client.requestExecutor.Do(req, &userType) + resp, err := m.client.requestExecutor.Do(ctx, req, &userType) if err != nil { return nil, resp, err } diff --git a/openapi/generator/index.js b/openapi/generator/index.js index 1be64f4d5..5e0fe9bf6 100644 --- a/openapi/generator/index.js +++ b/openapi/generator/index.js @@ -138,6 +138,7 @@ function getImports(object) { for (let operation in object.operations) { if(object.operations[operation].queryParams.length) { imports.push("github.com/okta/okta-sdk-golang/v2/okta/query") + imports.push("context"); } } } @@ -149,6 +150,7 @@ function getImports(object) { imports.push("github.com/okta/okta-sdk-golang/v2/okta/query") } imports.push("fmt"); + imports.push("context"); if (method.operation.responseModel !== undefined) { imports.push("fmt"); } @@ -165,6 +167,7 @@ function getImports(object) { imports.push("github.com/okta/okta-sdk-golang/v2/okta/query") } imports.push("fmt"); + imports.push("context"); if (method.operation.responseModel !== undefined) { imports.push("fmt"); } @@ -187,6 +190,8 @@ function getImports(object) { function operationArgumentBuilder(operation) { const args = []; + args.push("ctx context.Context"); + operation.pathParams.map((arg) => args.push(arg.name + " " + arg.type)); if ((operation.method === 'post' || operation.method === 'put') && operation.bodyModel) { diff --git a/openapi/generator/templates/model/defaultMethod.go.hbs b/openapi/generator/templates/model/defaultMethod.go.hbs index 7e4d4e165..24c9f99d8 100644 --- a/openapi/generator/templates/model/defaultMethod.go.hbs +++ b/openapi/generator/templates/model/defaultMethod.go.hbs @@ -54,7 +54,7 @@ func (m *{{modelName}}Resource) {{ucFirst operation.operationId}}({{operationArg {{/if}} {{/if}} - resp, err := m.client.requestExecutor.Do(req, &{{lowercaseFirstLetter operation.responseModel}}) + resp, err := m.client.requestExecutor.Do(ctx, req, &{{lowercaseFirstLetter operation.responseModel}}) if err != nil { {{#if (ne operation.responseModel undefined)}} return nil, resp, err @@ -81,7 +81,7 @@ func (m *{{modelName}}Resource) {{ucFirst operation.operationId}}({{operationArg {{/if}} {{else}} - resp, err := m.client.requestExecutor.Do(req, nil) + resp, err := m.client.requestExecutor.Do(ctx, req, nil) if err != nil { {{#if (ne operation.responseModel undefined)}} return nil, resp, err diff --git a/openapi/generator/templates/model/defaultOperation.go.hbs b/openapi/generator/templates/model/defaultOperation.go.hbs index 55b992199..3ce37370a 100644 --- a/openapi/generator/templates/model/defaultOperation.go.hbs +++ b/openapi/generator/templates/model/defaultOperation.go.hbs @@ -25,13 +25,13 @@ func (c *Client) {{ucFirst operation.operationId}}({{operationArgumentBuilder op {{else}} var {{lowercaseFirstLetter operation.responseModel}} *{{operation.responseModel}} {{/if}} - resp, err := c.requestExecutor.Do(req, &{{lowercaseFirstLetter operation.responseModel}}) + resp, err := c.requestExecutor.Do(ctx, req, &{{lowercaseFirstLetter operation.responseModel}}) if err != nil { return nil, resp, err } return {{lowercaseFirstLetter operation.responseModel}}, resp, nil {{else}} - resp, err := c.requestExecutor.Do(req, nil) + resp, err := c.requestExecutor.Do(ctx, req, nil) if err != nil { return resp, err } diff --git a/tests/integration/admin_roles_test.go b/tests/integration/admin_roles_test.go index 53f953df3..56a20db89 100644 --- a/tests/integration/admin_roles_test.go +++ b/tests/integration/admin_roles_test.go @@ -17,6 +17,7 @@ package integration import ( + "context" "testing" "github.com/okta/okta-sdk-golang/v2/okta" @@ -44,12 +45,12 @@ func Test_can_add_an_admin_role_to_user(t *testing.T) { Profile: &profile, } - user, _, err := client.User.CreateUser(*u, nil) + user, _, err := client.User.CreateUser(context.TODO(), *u, nil) require.NoError(t, err, "Creating an user should not error") role := okta.AssignRoleRequest{ Type: "SUPER_ADMIN", } - createdRole, response, err := client.User.AssignRoleToUser(user.Id, role, nil) + createdRole, response, err := client.User.AssignRoleToUser(context.TODO(), user.Id, role, nil) require.NoError(t, err, "adding role to user must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") require.IsType(t, &okta.Role{}, createdRole, "did not return `*okta.Role` as first variable") @@ -63,10 +64,10 @@ func Test_can_add_an_admin_role_to_user(t *testing.T) { assert.NotEmpty(t, createdRole.Created, "created should not be empty") assert.NotEmpty(t, createdRole.LastUpdated, "lastUpdated should not be empty") - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") } @@ -78,12 +79,12 @@ func Test_can_add_an_admin_role_to_group(t *testing.T) { g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") role := okta.AssignRoleRequest{ Type: "ORG_ADMIN", } - createdRole, response, err := client.Group.AssignRoleToGroup(group.Id, role, nil) + createdRole, response, err := client.Group.AssignRoleToGroup(context.TODO(), group.Id, role, nil) require.NoError(t, err, "adding role to user must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") require.IsType(t, &okta.Role{}, createdRole, "did not return `*okta.Role` as first variable") @@ -97,7 +98,7 @@ func Test_can_add_an_admin_role_to_group(t *testing.T) { assert.NotEmpty(t, createdRole.Created, "created should not be empty") assert.NotEmpty(t, createdRole.LastUpdated, "lastUpdated should not be empty") - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } @@ -119,27 +120,27 @@ func Test_can_remove_an_admin_role_to_user(t *testing.T) { Profile: &profile, } - user, _, err := client.User.CreateUser(*u, nil) + user, _, err := client.User.CreateUser(context.TODO(), *u, nil) require.NoError(t, err, "Creating an user should not error") role := okta.AssignRoleRequest{ Type: "SUPER_ADMIN", } - createdRole, response, err := client.User.AssignRoleToUser(user.Id, role, nil) + createdRole, response, err := client.User.AssignRoleToUser(context.TODO(), user.Id, role, nil) require.NoError(t, err, "adding role to user must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") require.IsType(t, &okta.Role{}, createdRole, "did not return `*okta.Role` as first variable") assert.Equal(t, "POST", response.Response.Request.Method, "did not make a get request") assert.Equal(t, "/api/v1/users/"+user.Id+"/roles", response.Response.Request.URL.Path, "path for request was incorrect") - response, err = client.User.RemoveRoleFromUser(user.Id, createdRole.Id) + response, err = client.User.RemoveRoleFromUser(context.TODO(), user.Id, createdRole.Id) require.NoError(t, err, "removing role from user must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") assert.Equal(t, 204, response.StatusCode, "did not return a 204") - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") } @@ -151,24 +152,24 @@ func Test_can_remove_an_admin_role_to_group(t *testing.T) { g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") role := okta.AssignRoleRequest{ Type: "ORG_ADMIN", } - createdRole, response, err := client.Group.AssignRoleToGroup(group.Id, role, nil) + createdRole, response, err := client.Group.AssignRoleToGroup(context.TODO(), group.Id, role, nil) require.NoError(t, err, "adding role to user must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") require.IsType(t, &okta.Role{}, createdRole, "did not return `*okta.Role` as first variable") assert.Equal(t, "POST", response.Response.Request.Method, "did not make a get request") assert.Equal(t, "/api/v1/groups/"+group.Id+"/roles", response.Response.Request.URL.Path, "path for request was incorrect") - response, err = client.Group.RemoveRoleFromGroup(group.Id, createdRole.Id) + response, err = client.Group.RemoveRoleFromGroup(context.TODO(), group.Id, createdRole.Id) require.NoError(t, err, "removing role from group must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") assert.Equal(t, 204, response.StatusCode, "did not return a 204") - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } @@ -190,17 +191,17 @@ func Test_can_list_roles_assigned_to_a_user(t *testing.T) { Profile: &profile, } - user, _, err := client.User.CreateUser(*u, nil) + user, _, err := client.User.CreateUser(context.TODO(), *u, nil) require.NoError(t, err, "Creating an user should not error") role := okta.AssignRoleRequest{ Type: "SUPER_ADMIN", } - _, response, err := client.User.AssignRoleToUser(user.Id, role, nil) + _, response, err := client.User.AssignRoleToUser(context.TODO(), user.Id, role, nil) require.NoError(t, err, "adding role to user must not error") - roles, response, err := client.User.ListAssignedRolesForUser(user.Id, nil) + roles, response, err := client.User.ListAssignedRolesForUser(context.TODO(), user.Id, nil) require.NoError(t, err, "listing adnimistrator roles must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") @@ -218,10 +219,10 @@ func Test_can_list_roles_assigned_to_a_user(t *testing.T) { assert.NotEmpty(t, roles[0].LastUpdated, "lastUpdated should not be empty") assert.NotEmpty(t, roles[0].AssignmentType, "assignmentType should not be empty") - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") } @@ -234,15 +235,15 @@ func Test_can_list_roles_assigned_to_a_group(t *testing.T) { g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") role := okta.AssignRoleRequest{ Type: "ORG_ADMIN", } - _, response, err := client.Group.AssignRoleToGroup(group.Id, role, nil) + _, response, err := client.Group.AssignRoleToGroup(context.TODO(), group.Id, role, nil) require.NoError(t, err, "adding role to user must not error") - roles, response, err := client.Group.ListGroupAssignedRoles(group.Id, nil) + roles, response, err := client.Group.ListGroupAssignedRoles(context.TODO(), group.Id, nil) require.NoError(t, err, "listing adnimistrator roles must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") @@ -260,7 +261,7 @@ func Test_can_list_roles_assigned_to_a_group(t *testing.T) { assert.NotEmpty(t, roles[0].LastUpdated, "lastUpdated should not be empty") assert.NotEmpty(t, roles[0].AssignmentType, "assignmentType should not be empty") - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } @@ -283,7 +284,7 @@ func Test_can_add_group_targets_for_the_group_administrator_role_given_to_a_user Profile: &profile, } - user, _, err := client.User.CreateUser(*u, nil) + user, _, err := client.User.CreateUser(context.TODO(), *u, nil) require.NoError(t, err, "Creating an user should not error") role := okta.AssignRoleRequest{ @@ -296,25 +297,25 @@ func Test_can_add_group_targets_for_the_group_administrator_role_given_to_a_user g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") - addedRole, response, err := client.User.AssignRoleToUser(user.Id, role, nil) + addedRole, response, err := client.User.AssignRoleToUser(context.TODO(), user.Id, role, nil) require.NoError(t, err, "adding role to user must not error") - response, err = client.User.AddGroupTargetToRole(user.Id, addedRole.Id, group.Id) + response, err = client.User.AddGroupTargetToRole(context.TODO(), user.Id, addedRole.Id, group.Id) require.NoError(t, err, "list group assignments must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") assert.Equal(t, "PUT", response.Response.Request.Method, "did not make a get request") assert.Equal(t, "/api/v1/users/"+user.Id+"/roles/"+addedRole.Id+"/targets/groups/"+group.Id, response.Response.Request.URL.Path, "path for request was incorrect") - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } @@ -331,19 +332,19 @@ func Test_can_add_group_targets_for_the_group_administrator_role_given_to_a_grou g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") - addedRole, response, err := client.Group.AssignRoleToGroup(group.Id, role, nil) + addedRole, response, err := client.Group.AssignRoleToGroup(context.TODO(), group.Id, role, nil) require.NoError(t, err, "adding role to user must not error") - response, err = client.Group.AddGroupTargetToGroupAdministratorRoleForGroup(group.Id, addedRole.Id, group.Id) + response, err = client.Group.AddGroupTargetToGroupAdministratorRoleForGroup(context.TODO(), group.Id, addedRole.Id, group.Id) require.NoError(t, err, "list group assignments must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") assert.Equal(t, "PUT", response.Response.Request.Method, "did not make a get request") assert.Equal(t, "/api/v1/groups/"+group.Id+"/roles/"+addedRole.Id+"/targets/groups/"+group.Id, response.Response.Request.URL.Path, "path for request was incorrect") - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } @@ -365,7 +366,7 @@ func Test_can_list_group_targets_for_the_group_administrator_role_given_to_a_use Profile: &profile, } - user, _, err := client.User.CreateUser(*u, nil) + user, _, err := client.User.CreateUser(context.TODO(), *u, nil) require.NoError(t, err, "Creating an user should not error") role := okta.AssignRoleRequest{ @@ -378,19 +379,19 @@ func Test_can_list_group_targets_for_the_group_administrator_role_given_to_a_use g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") - addedRole, response, err := client.User.AssignRoleToUser(user.Id, role, nil) + addedRole, response, err := client.User.AssignRoleToUser(context.TODO(), user.Id, role, nil) require.NoError(t, err, "adding role to user must not error") - response, err = client.User.AddGroupTargetToRole(user.Id, addedRole.Id, group.Id) + response, err = client.User.AddGroupTargetToRole(context.TODO(), user.Id, addedRole.Id, group.Id) require.NoError(t, err, "list group assignments must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") assert.Equal(t, "PUT", response.Response.Request.Method, "did not make a get request") assert.Equal(t, "/api/v1/users/"+user.Id+"/roles/"+addedRole.Id+"/targets/groups/"+group.Id, response.Response.Request.URL.Path, "path for request was incorrect") - listRoles, response, err := client.User.ListGroupTargetsForRole(user.Id, addedRole.Id, nil) + listRoles, response, err := client.User.ListGroupTargetsForRole(context.TODO(), user.Id, addedRole.Id, nil) require.NoError(t, err, "list group assignments must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") require.IsType(t, []*okta.Group{}, listRoles, "did not return `[]*okta.Group` type as first variable") @@ -402,13 +403,13 @@ func Test_can_list_group_targets_for_the_group_administrator_role_given_to_a_use assert.NotEmpty(t, listRoles[0].Profile, "profile should not be empty") assert.IsType(t, &okta.GroupProfile{}, listRoles[0].Profile, "profile should be instance of *okta.GroupProfile") - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } @@ -425,19 +426,19 @@ func Test_can_list_group_targets_for_the_group_administrator_role_given_to_a_gro g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") - addedRole, response, err := client.Group.AssignRoleToGroup(group.Id, role, nil) + addedRole, response, err := client.Group.AssignRoleToGroup(context.TODO(), group.Id, role, nil) require.NoError(t, err, "adding role to user must not error") - response, err = client.Group.AddGroupTargetToGroupAdministratorRoleForGroup(group.Id, addedRole.Id, group.Id) + response, err = client.Group.AddGroupTargetToGroupAdministratorRoleForGroup(context.TODO(), group.Id, addedRole.Id, group.Id) require.NoError(t, err, "list group assignments must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") assert.Equal(t, "PUT", response.Response.Request.Method, "did not make a get request") assert.Equal(t, "/api/v1/groups/"+group.Id+"/roles/"+addedRole.Id+"/targets/groups/"+group.Id, response.Response.Request.URL.Path, "path for request was incorrect") - listRoles, response, err := client.Group.ListGroupTargetsForGroupRole(group.Id, addedRole.Id, nil) + listRoles, response, err := client.Group.ListGroupTargetsForGroupRole(context.TODO(), group.Id, addedRole.Id, nil) require.NoError(t, err, "list group assignments must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") require.IsType(t, []*okta.Group{}, listRoles, "did not return `[]*okta.Group` type as first variable") @@ -449,6 +450,6 @@ func Test_can_list_group_targets_for_the_group_administrator_role_given_to_a_gro assert.NotEmpty(t, listRoles[0].Profile, "profile should not be empty") assert.IsType(t, &okta.GroupProfile{}, listRoles[0].Profile, "profile should be instance of *okta.GroupProfile") - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } diff --git a/tests/integration/application_test.go b/tests/integration/application_test.go index 02097c071..81ddcb621 100644 --- a/tests/integration/application_test.go +++ b/tests/integration/application_test.go @@ -17,6 +17,7 @@ package integration import ( + "context" "fmt" "strings" "testing" @@ -44,18 +45,18 @@ func Test_can_get_applicaiton_by_id(t *testing.T) { basicApplication := okta.NewBasicAuthApplication() basicApplication.Settings = basicApplicationSettings - application, _, err := client.Application.CreateApplication(basicApplication, nil) + application, _, err := client.Application.CreateApplication(context.TODO(), basicApplication, nil) require.NoError(t, err, "Creating an application should not error") appId := application.(*okta.BasicAuthApplication).Id - foundApplication, _, err := client.Application.GetApplication(appId, okta.NewBasicAuthApplication(), nil) + foundApplication, _, err := client.Application.GetApplication(context.TODO(), appId, okta.NewBasicAuthApplication(), nil) require.NoError(t, err, "Should not error when getting an applicaiton by id") assert.Equal(t, appId, foundApplication.(*okta.BasicAuthApplication).Id, "Application found was not correct") - client.Application.DeactivateApplication(appId) - _, err = client.Application.DeleteApplication(appId) + client.Application.DeactivateApplication(context.TODO(), appId) + _, err = client.Application.DeleteApplication(context.TODO(), appId) require.NoError(t, err, "Deleting an application should not error") } @@ -73,7 +74,7 @@ func Test_can_update_application(t *testing.T) { basicApplication := okta.NewBasicAuthApplication() basicApplication.Settings = basicApplicationSettings - application, _, err := client.Application.CreateApplication(basicApplication, nil) + application, _, err := client.Application.CreateApplication(context.TODO(), basicApplication, nil) require.NoError(t, err, "Creating an application should not error") appId := application.(*okta.BasicAuthApplication).Id @@ -88,13 +89,13 @@ func Test_can_update_application(t *testing.T) { newBasicApplication := okta.NewBasicAuthApplication() newBasicApplication.Settings = newBasicApplicationSettings - newApp, _, err := client.Application.UpdateApplication(appId, newBasicApplication) + newApp, _, err := client.Application.UpdateApplication(context.TODO(), appId, newBasicApplication) require.NoError(t, err, "Updating an application caused an error") assert.Equal(t, "https://example.org/auth.html", newApp.(*okta.BasicAuthApplication).Settings.App.Url, "The application did not update") - client.Application.DeactivateApplication(appId) - _, err = client.Application.DeleteApplication(appId) + client.Application.DeactivateApplication(context.TODO(), appId) + _, err = client.Application.DeleteApplication(context.TODO(), appId) require.NoError(t, err, "Deleting an application should not error") } @@ -112,14 +113,14 @@ func Test_can_create_a_bookmark_application(t *testing.T) { bookmarkApplication := okta.NewBookmarkApplication() bookmarkApplication.Settings = bookmarkApplicationSettings assert.Empty(t, bookmarkApplication.Id) - application, _, err := client.Application.CreateApplication(bookmarkApplication, nil) + application, _, err := client.Application.CreateApplication(context.TODO(), bookmarkApplication, nil) require.NoError(t, err, "Creating an application should not error") assert.IsType(t, &okta.BookmarkApplication{}, application, "Application type returned was incorrect") assert.NotEmpty(t, application.(*okta.BookmarkApplication).Id) - client.Application.DeactivateApplication(application.(*okta.BookmarkApplication).Id) - _, err = client.Application.DeleteApplication(application.(*okta.BookmarkApplication).Id) + client.Application.DeactivateApplication(context.TODO(), application.(*okta.BookmarkApplication).Id) + _, err = client.Application.DeleteApplication(context.TODO(), application.(*okta.BookmarkApplication).Id) require.NoError(t, err, "Deleting an application should not error") } @@ -138,15 +139,15 @@ func Test_can_create_a_basic_authentication_application(t *testing.T) { basicApplication.Settings = basicApplicationSettings assert.Empty(t, basicApplication.Id) - application, _, err := client.Application.CreateApplication(basicApplication, nil) + application, _, err := client.Application.CreateApplication(context.TODO(), basicApplication, nil) require.NoError(t, err, "Creating an application should not error") assert.IsType(t, &okta.BasicAuthApplication{}, application, "Application type returned was incorrect") assert.NotEmpty(t, application.(*okta.BasicAuthApplication).Id) assert.NotEmpty(t, basicApplication.Id) - client.Application.DeactivateApplication(application.(*okta.BasicAuthApplication).Id) - _, err = client.Application.DeleteApplication(application.(*okta.BasicAuthApplication).Id) + client.Application.DeactivateApplication(context.TODO(), application.(*okta.BasicAuthApplication).Id) + _, err = client.Application.DeleteApplication(context.TODO(), application.(*okta.BasicAuthApplication).Id) require.NoError(t, err, "Deleting an application should not error") } @@ -164,7 +165,7 @@ func Test_list_application_allows_casting_to_correct_type(t *testing.T) { basicApplication := okta.NewBasicAuthApplication() basicApplication.Settings = basicApplicationSettings - app1, _, err := client.Application.CreateApplication(basicApplication, nil) + app1, _, err := client.Application.CreateApplication(context.TODO(), basicApplication, nil) require.NoError(t, err, "Creating an application should not error") bookmarkApplicationSettingsApplication := okta.NewBookmarkApplicationSettingsApplication() @@ -177,30 +178,30 @@ func Test_list_application_allows_casting_to_correct_type(t *testing.T) { bookmarkApplication := okta.NewBookmarkApplication() bookmarkApplication.Settings = bookmarkApplicationSettings - app2, _, err := client.Application.CreateApplication(bookmarkApplication, nil) + app2, _, err := client.Application.CreateApplication(context.TODO(), bookmarkApplication, nil) require.NoError(t, err, "Creating an application should not error") - applist, _, err := client.Application.ListApplications(nil) + applist, _, err := client.Application.ListApplications(context.TODO(), nil) require.NoError(t, err, "List applicaitons should not error") for _, a := range applist { if a.(*okta.Application).Name == "bookmark" { if a.(*okta.Application).Id == app2.(*okta.BookmarkApplication).Id { - ba, _, _ := client.Application.GetApplication(a.(*okta.Application).Id, okta.NewBookmarkApplication(), nil) + ba, _, _ := client.Application.GetApplication(context.TODO(), a.(*okta.Application).Id, okta.NewBookmarkApplication(), nil) requestIntegration := ba.(*okta.BookmarkApplication).Settings.App.RequestIntegration assert.False(t, *requestIntegration) } } } - client.Application.DeactivateApplication(app1.(*okta.BasicAuthApplication).Id) - _, err = client.Application.DeleteApplication(app1.(*okta.BasicAuthApplication).Id) + client.Application.DeactivateApplication(context.TODO(), app1.(*okta.BasicAuthApplication).Id) + _, err = client.Application.DeleteApplication(context.TODO(), app1.(*okta.BasicAuthApplication).Id) require.NoError(t, err, "Deleting an application should not error") - client.Application.DeactivateApplication(app2.(*okta.BookmarkApplication).Id) - _, err = client.Application.DeleteApplication(app2.(*okta.BookmarkApplication).Id) + client.Application.DeactivateApplication(context.TODO(), app2.(*okta.BookmarkApplication).Id) + _, err = client.Application.DeleteApplication(context.TODO(), app2.(*okta.BookmarkApplication).Id) require.NoError(t, err, "Deleting an application should not error") } @@ -218,20 +219,20 @@ func Test_can_activate_application(t *testing.T) { basicApplication := okta.NewBasicAuthApplication() basicApplication.Settings = basicApplicationSettings - application, _, err := client.Application.CreateApplication(basicApplication, query.NewQueryParams(query.WithActivate(false))) + application, _, err := client.Application.CreateApplication(context.TODO(), basicApplication, query.NewQueryParams(query.WithActivate(false))) require.NoError(t, err, "Creating an application should not error") appId := application.(*okta.BasicAuthApplication).Id assert.Equal(t, "INACTIVE", application.(*okta.BasicAuthApplication).Status, "Application is not inactive") - _, err = client.Application.ActivateApplication(appId) + _, err = client.Application.ActivateApplication(context.TODO(), appId) require.NoError(t, err, "Activationg an application should not error") - application, _, _ = client.Application.GetApplication(appId, okta.NewBasicAuthApplication(), nil) + application, _, _ = client.Application.GetApplication(context.TODO(), appId, okta.NewBasicAuthApplication(), nil) assert.Equal(t, "ACTIVE", application.(*okta.BasicAuthApplication).Status, "Application is not inactive") - client.Application.DeactivateApplication(appId) - _, err = client.Application.DeleteApplication(appId) + client.Application.DeactivateApplication(context.TODO(), appId) + _, err = client.Application.DeleteApplication(context.TODO(), appId) require.NoError(t, err, "Deleting an application should not error") } @@ -249,19 +250,19 @@ func Test_can_deactivate_application(t *testing.T) { basicApplication := okta.NewBasicAuthApplication() basicApplication.Settings = basicApplicationSettings - application, _, err := client.Application.CreateApplication(basicApplication, query.NewQueryParams(query.WithActivate(true))) + application, _, err := client.Application.CreateApplication(context.TODO(), basicApplication, query.NewQueryParams(query.WithActivate(true))) require.NoError(t, err, "Creating an application should not error") appId := application.(*okta.BasicAuthApplication).Id assert.Equal(t, "ACTIVE", application.(*okta.BasicAuthApplication).Status, "Application is not inactive") - _, err = client.Application.DeactivateApplication(appId) + _, err = client.Application.DeactivateApplication(context.TODO(), appId) require.NoError(t, err, "Deactivating an application should not error") - application, _, err = client.Application.GetApplication(appId, okta.NewBasicAuthApplication(), nil) + application, _, err = client.Application.GetApplication(context.TODO(), appId, okta.NewBasicAuthApplication(), nil) assert.Equal(t, "INACTIVE", application.(*okta.BasicAuthApplication).Status, "Application is not inactive") - _, err = client.Application.DeleteApplication(appId) + _, err = client.Application.DeleteApplication(context.TODO(), appId) require.NoError(t, err, "Deleting an application should not error") } @@ -279,12 +280,12 @@ func Test_can_add_and_remove_application_users(t *testing.T) { basicApplication := okta.NewBasicAuthApplication() basicApplication.Settings = basicApplicationSettings - application, _, err := client.Application.CreateApplication(basicApplication, nil) + application, _, err := client.Application.CreateApplication(context.TODO(), basicApplication, nil) require.NoError(t, err, "Creating an application should not error") appId := application.(*okta.BasicAuthApplication).Id - appUserList, _, _ := client.Application.ListApplicationUsers(appId, nil) + appUserList, _, _ := client.Application.ListApplicationUsers(context.TODO(), appId, nil) assert.Empty(t, appUserList, "App Users should be empty") p := &okta.PasswordCredential{ @@ -304,7 +305,7 @@ func Test_can_add_and_remove_application_users(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(false)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") appUserPasswordCredentials := okta.NewAppUserPasswordCredential() @@ -318,25 +319,25 @@ func Test_can_add_and_remove_application_users(t *testing.T) { appUser.Credentials = appUserCredentials appUser.Id = user.Id - appUser, _, err = client.Application.AssignUserToApplication(appId, *appUser) + appUser, _, err = client.Application.AssignUserToApplication(context.TODO(), appId, *appUser) require.NoError(t, err, "Assigning user to application show not error") assert.IsType(t, okta.AppUser{}, *appUser, "Type returned from assigning user to application was incorrect") - appUserList, _, _ = client.Application.ListApplicationUsers(appId, nil) + appUserList, _, _ = client.Application.ListApplicationUsers(context.TODO(), appId, nil) assert.NotEmpty(t, appUserList, "App Users should not be empty") - client.Application.DeleteApplicationUser(appId, appUser.Id, nil) - appUserList, _, _ = client.Application.ListApplicationUsers(appId, nil) + client.Application.DeleteApplicationUser(context.TODO(), appId, appUser.Id, nil) + appUserList, _, _ = client.Application.ListApplicationUsers(context.TODO(), appId, nil) assert.Empty(t, appUserList, "App Users should be empty after deleting") - client.Application.DeactivateApplication(appId) - _, err = client.Application.DeleteApplication(appId) + client.Application.DeactivateApplication(context.TODO(), appId) + _, err = client.Application.DeleteApplication(context.TODO(), appId) require.NoError(t, err, "Deleting an application should not error") - client.User.DeactivateUser(user.Id, nil) - client.User.DeactivateOrDeleteUser(user.Id, nil) + client.User.DeactivateUser(context.TODO(), user.Id, nil) + client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) } func Test_can_set_application_settings_during_creation(t *testing.T) { @@ -353,15 +354,15 @@ func Test_can_set_application_settings_during_creation(t *testing.T) { basicApplication.Settings = basicApplicationSettings assert.Empty(t, basicApplication.Id) - application, _, err := client.Application.CreateApplication(basicApplication, nil) + application, _, err := client.Application.CreateApplication(context.TODO(), basicApplication, nil) require.NoError(t, err, "Creating an application should not error") assert.IsType(t, okta.BasicApplicationSettingsApplication{}, *application.(*okta.BasicAuthApplication).Settings.App, "The returned type of application settings application was not correct type") assert.Equal(t, "https://example.com/auth.html", application.(*okta.BasicAuthApplication).Settings.App.Url) appId := application.(*okta.BasicAuthApplication).Id - client.Application.DeactivateApplication(appId) - _, err = client.Application.DeleteApplication(appId) + client.Application.DeactivateApplication(context.TODO(), appId) + _, err = client.Application.DeleteApplication(context.TODO(), appId) require.NoError(t, err, "Deleting an application should not error") } @@ -380,25 +381,25 @@ func Test_can_set_application_settings_during_update(t *testing.T) { basicApplication.Settings = basicApplicationSettings assert.Empty(t, basicApplication.Id) - application, _, err := client.Application.CreateApplication(basicApplication, nil) + application, _, err := client.Application.CreateApplication(context.TODO(), basicApplication, nil) require.NoError(t, err, "Creating an application should not error") appId := application.(*okta.BasicAuthApplication).Id - myApp, _, err := client.Application.GetApplication(appId, okta.NewBasicAuthApplication(), nil) + myApp, _, err := client.Application.GetApplication(context.TODO(), appId, okta.NewBasicAuthApplication(), nil) app := myApp.(*okta.BasicAuthApplication) myAppId := app.Id myAppSettingsApp := app.Settings.App myAppSettingsApp.Url = "https://okta.com/auth" - _, _, _ = client.Application.UpdateApplication(myAppId, app) + _, _, _ = client.Application.UpdateApplication(context.TODO(), myAppId, app) - updatedApp, _, err := client.Application.GetApplication(appId, okta.NewBasicAuthApplication(), nil) + updatedApp, _, err := client.Application.GetApplication(context.TODO(), appId, okta.NewBasicAuthApplication(), nil) assert.Equal(t, "https://okta.com/auth", updatedApp.(*okta.BasicAuthApplication).Settings.App.Url, "The URL was not updated'") - client.Application.DeactivateApplication(appId) - _, err = client.Application.DeleteApplication(appId) + client.Application.DeactivateApplication(context.TODO(), appId) + _, err = client.Application.DeleteApplication(context.TODO(), appId) require.NoError(t, err, "Deleting an application should not error") } @@ -426,13 +427,13 @@ func Test_can_create_csr_for_application(t *testing.T) { SubjectAltNames: &subjectAltNames, } - csrs, _, err := client.Application.GenerateCsrForApplication(application.Id, csr) + csrs, _, err := client.Application.GenerateCsrForApplication(context.TODO(), application.Id, csr) require.NoError(t, err, "Creating an application CSR should not error") assert.IsType(t, &okta.CSR{}, csrs, "did not return a `okta.CSR` object") - client.Application.DeactivateApplication(application.Id) - _, err = client.Application.DeleteApplication(application.Id) + client.Application.DeactivateApplication(context.TODO(), application.Id) + _, err = client.Application.DeleteApplication(context.TODO(), application.Id) require.NoError(t, err, "Deleting an application should not error") } @@ -449,7 +450,7 @@ func create_application(t *testing.T) *okta.BasicAuthApplication { basicApplication := okta.NewBasicAuthApplication() basicApplication.Settings = basicApplicationSettings - application, _, err := client.Application.CreateApplication(basicApplication, nil) + application, _, err := client.Application.CreateApplication(context.TODO(), basicApplication, nil) require.NoError(t, err, "Creating an application should not error") return application.(*okta.BasicAuthApplication) @@ -458,7 +459,7 @@ func create_application(t *testing.T) *okta.BasicAuthApplication { func delete_all_apps(t *testing.T) { client, _ := tests.NewClient() - applicationList, _, err := client.Application.ListApplications(nil) + applicationList, _, err := client.Application.ListApplications(context.TODO(), nil) if err != nil { fmt.Printf("%+v\n", err) } @@ -466,8 +467,8 @@ func delete_all_apps(t *testing.T) { for _, a := range applicationList { if strings.HasPrefix(a.(*okta.Application).Label, "Template Basic Auth App") || strings.HasPrefix(a.(*okta.Application).Label, "Bookmark App") { - client.Application.DeactivateApplication(a.(*okta.Application).Id) - client.Application.DeleteApplication(a.(*okta.Application).Id) + client.Application.DeactivateApplication(context.TODO(), a.(*okta.Application).Id) + client.Application.DeleteApplication(context.TODO(), a.(*okta.Application).Id) } } } diff --git a/tests/integration/authorization_server_test.go b/tests/integration/authorization_server_test.go index 1d9a5fac1..a6b12d417 100644 --- a/tests/integration/authorization_server_test.go +++ b/tests/integration/authorization_server_test.go @@ -17,6 +17,7 @@ package integration import ( + "context" "net/http" "testing" "time" @@ -36,13 +37,13 @@ func Test_can_create_an_authorizaiton_server(t *testing.T) { Audiences: []string{"api://default"}, } - authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as) + authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(context.TODO(), as) require.NoError(t, err, "creating an authorizaiton server should not error") tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers") assert_authorization_server_model(t, authorizationServer) - _, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id) + _, err = client.AuthorizationServer.DeleteAuthorizationServer(context.TODO(), authorizationServer.Id) } func Test_can_get_an_authorizaiton_server(t *testing.T) { @@ -54,11 +55,11 @@ func Test_can_get_an_authorizaiton_server(t *testing.T) { Audiences: []string{"api://default"}, } - authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as) + authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(context.TODO(), as) require.NoError(t, err, "creating an authorizaiton server should not error") tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers") - authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id) + authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(context.TODO(), authorizationServer.Id) require.NoError(t, err, "getting an authorizaiton server should not error") tests.Assert_response(t, response, "GET", "/api/v1/authorizationServers/"+authorizationServer.Id) @@ -67,7 +68,7 @@ func Test_can_get_an_authorizaiton_server(t *testing.T) { assert.Equal(t, as.Name, authorizationServer.Name, "did not return the same authorization server name") assert.Equal(t, as.Description, authorizationServer.Description, "did not return the same authorization server description") - _, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id) + _, err = client.AuthorizationServer.DeleteAuthorizationServer(context.TODO(), authorizationServer.Id) } func Test_can_update_an_authorizaiton_server(t *testing.T) { @@ -79,11 +80,11 @@ func Test_can_update_an_authorizaiton_server(t *testing.T) { Audiences: []string{"api://default"}, } - authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as) + authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(context.TODO(), as) require.NoError(t, err, "creating an authorizaiton server should not error") tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers") - authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id) + authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(context.TODO(), authorizationServer.Id) require.NoError(t, err, "getting an authorizaiton server should not error") tests.Assert_response(t, response, "GET", "/api/v1/authorizationServers/"+authorizationServer.Id) @@ -97,7 +98,7 @@ func Test_can_update_an_authorizaiton_server(t *testing.T) { authorizationServer.Name = updatedName authorizationServer.Description = updatedDescription - authorizationServer, response, err = client.AuthorizationServer.UpdateAuthorizationServer(authorizationServer.Id, *authorizationServer) + authorizationServer, response, err = client.AuthorizationServer.UpdateAuthorizationServer(context.TODO(), authorizationServer.Id, *authorizationServer) require.NoError(t, err, "getting an authorizaiton server should not error") tests.Assert_response(t, response, "PUT", "/api/v1/authorizationServers/"+authorizationServer.Id) @@ -106,7 +107,7 @@ func Test_can_update_an_authorizaiton_server(t *testing.T) { assert.Equal(t, updatedName, authorizationServer.Name, "did not return the same authorization server name") assert.Equal(t, updatedDescription, authorizationServer.Description, "did not return the same authorization server description") - _, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id) + _, err = client.AuthorizationServer.DeleteAuthorizationServer(context.TODO(), authorizationServer.Id) } func Test_can_delete_an_authorizaiton_server(t *testing.T) { @@ -118,11 +119,11 @@ func Test_can_delete_an_authorizaiton_server(t *testing.T) { Audiences: []string{"api://default"}, } - authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as) + authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(context.TODO(), as) require.NoError(t, err, "creating an authorizaiton server should not error") tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers") - authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id) + authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(context.TODO(), authorizationServer.Id) require.NoError(t, err, "getting an authorizaiton server should not error") tests.Assert_response(t, response, "GET", "/api/v1/authorizationServers/"+authorizationServer.Id) @@ -131,10 +132,10 @@ func Test_can_delete_an_authorizaiton_server(t *testing.T) { assert.Equal(t, as.Name, authorizationServer.Name, "did not return the same authorization server name") assert.Equal(t, as.Description, authorizationServer.Description, "did not return the same authorization server description") - response, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id) + response, err = client.AuthorizationServer.DeleteAuthorizationServer(context.TODO(), authorizationServer.Id) assert.Equal(t, http.StatusNoContent, response.StatusCode, "did not return a 204 status code during delete") - authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id) + authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(context.TODO(), authorizationServer.Id) assert.Error(t, err, "Finding an authorization server by id should have reported an error") assert.Equal(t, http.StatusNotFound, response.StatusCode, "Should have resulted in a 404 when finding a deleted authorization server") } @@ -148,11 +149,11 @@ func Test_can_list_authorizaiton_servers(t *testing.T) { Audiences: []string{"api://default"}, } - authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as) + authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(context.TODO(), as) require.NoError(t, err, "creating an authorizaiton server should not error") tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers") - authorizationServerList, response, err := client.AuthorizationServer.ListAuthorizationServers(nil) + authorizationServerList, response, err := client.AuthorizationServer.ListAuthorizationServers(context.TODO(), nil) require.NoError(t, err, "list authorizaiton servers should not error") tests.Assert_response(t, response, "GET", "/api/v1/authorizationServers") @@ -165,7 +166,7 @@ func Test_can_list_authorizaiton_servers(t *testing.T) { } assert.True(t, found, "Could not find authorization from list") - _, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id) + _, err = client.AuthorizationServer.DeleteAuthorizationServer(context.TODO(), authorizationServer.Id) } func Test_can_activate_an_authorizaiton_server(t *testing.T) { @@ -177,26 +178,26 @@ func Test_can_activate_an_authorizaiton_server(t *testing.T) { Audiences: []string{"api://default"}, } - authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as) + authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(context.TODO(), as) require.NoError(t, err, "creating an authorizaiton server should not error") tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers") assert.Equal(t, "ACTIVE", authorizationServer.Status, "should have active status after creating") - response, err = client.AuthorizationServer.DeactivateAuthorizationServer(authorizationServer.Id) + response, err = client.AuthorizationServer.DeactivateAuthorizationServer(context.TODO(), authorizationServer.Id) require.NoError(t, err, "deactivating an authorizaiton server should not error") tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers/"+authorizationServer.Id+"/lifecycle/deactivate") - authorizationServer, _, _ = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id) + authorizationServer, _, _ = client.AuthorizationServer.GetAuthorizationServer(context.TODO(), authorizationServer.Id) assert.Equal(t, "INACTIVE", authorizationServer.Status, "should have inactive status after deactivating") - response, err = client.AuthorizationServer.ActivateAuthorizationServer(authorizationServer.Id) + response, err = client.AuthorizationServer.ActivateAuthorizationServer(context.TODO(), authorizationServer.Id) require.NoError(t, err, "activating an authorizaiton server should not error") tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers/"+authorizationServer.Id+"/lifecycle/activate") // authorizationServer, response, _ = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id) // assert.Equal(t, "ACTIVE", authorizationServer.Status, "should have active status after activating") - _, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id) + _, err = client.AuthorizationServer.DeleteAuthorizationServer(context.TODO(), authorizationServer.Id) } func assert_authorization_server_model(t *testing.T, authorizationServer *okta.AuthorizationServer) { diff --git a/tests/integration/event_hooks_test.go b/tests/integration/event_hooks_test.go index 24b7ad569..279e27ed0 100644 --- a/tests/integration/event_hooks_test.go +++ b/tests/integration/event_hooks_test.go @@ -17,6 +17,7 @@ package integration import ( + "context" "testing" "time" @@ -32,16 +33,16 @@ func Test_create_an_event_hook(t *testing.T) { eventHookRequest := createEventHookRequestObject("Create an event hook") - eventHook, response, err := client.EventHook.CreateEventHook(eventHookRequest) + eventHook, response, err := client.EventHook.CreateEventHook(context.TODO(), eventHookRequest) require.NoError(t, err, "creating an event hook should not error") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks") assert_event_hook_model(t, eventHook) - _, _, err = client.EventHook.DeactivateEventHook(eventHook.Id) + _, _, err = client.EventHook.DeactivateEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deactivating an event hook should not error") - _, err = client.EventHook.DeleteEventHook(eventHook.Id) + _, err = client.EventHook.DeleteEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deleting an event hook should not error") } @@ -51,12 +52,12 @@ func Test_get_an_event_hook(t *testing.T) { eventHookRequest := createEventHookRequestObject("get an event hook") - eventHook, response, err := client.EventHook.CreateEventHook(eventHookRequest) + eventHook, response, err := client.EventHook.CreateEventHook(context.TODO(), eventHookRequest) require.NoError(t, err, "creating an event hook should not error") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks") - foundEventHook, response, err := client.EventHook.GetEventHook(eventHook.Id) + foundEventHook, response, err := client.EventHook.GetEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "get an event hook should not error") tests.Assert_response(t, response, "GET", "/api/v1/eventHooks/"+eventHook.Id) @@ -64,9 +65,9 @@ func Test_get_an_event_hook(t *testing.T) { assert_event_hook_model(t, foundEventHook) require.Equal(t, eventHook.Id, foundEventHook.Id, "did not find the same event hook from id") - _, _, err = client.EventHook.DeactivateEventHook(eventHook.Id) + _, _, err = client.EventHook.DeactivateEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deactivating an event hook should not error") - _, err = client.EventHook.DeleteEventHook(eventHook.Id) + _, err = client.EventHook.DeleteEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deleting an event hook should not error") } @@ -76,20 +77,20 @@ func Test_update_an_event_hook(t *testing.T) { eventHookRequest := createEventHookRequestObject("Create an event hook") - eventHook, response, err := client.EventHook.CreateEventHook(eventHookRequest) + eventHook, response, err := client.EventHook.CreateEventHook(context.TODO(), eventHookRequest) require.NoError(t, err, "creating an event hook should not error") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks") eventHook.Name = "GO SDK: Updated Event Hook" - updatedEventHook, response, err := client.EventHook.UpdateEventHook(eventHook.Id, *eventHook) + updatedEventHook, response, err := client.EventHook.UpdateEventHook(context.TODO(), eventHook.Id, *eventHook) assert_event_hook_model(t, updatedEventHook) require.Equal(t, eventHook.Name, updatedEventHook.Name, "update of event hook did not work") - _, _, err = client.EventHook.DeactivateEventHook(eventHook.Id) + _, _, err = client.EventHook.DeactivateEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deactivating an event hook should not error") - _, err = client.EventHook.DeleteEventHook(eventHook.Id) + _, err = client.EventHook.DeleteEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deleting an event hook should not error") } @@ -99,7 +100,7 @@ func Test_deactivate_and_delete_an_event_hook(t *testing.T) { eventHookRequest := createEventHookRequestObject("deactivate and delete an event hook") - eventHook, response, err := client.EventHook.CreateEventHook(eventHookRequest) + eventHook, response, err := client.EventHook.CreateEventHook(context.TODO(), eventHookRequest) require.NoError(t, err, "creating an event hook should not error") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks") @@ -107,16 +108,16 @@ func Test_deactivate_and_delete_an_event_hook(t *testing.T) { assert_event_hook_model(t, eventHook) require.Equal(t, "ACTIVE", eventHook.Status, "event hook was not active") - _, response, err = client.EventHook.DeactivateEventHook(eventHook.Id) + _, response, err = client.EventHook.DeactivateEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deactivating an event hook should not error") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks/"+eventHook.Id+"/lifecycle/deactivate") - foundEventHook, _, err := client.EventHook.GetEventHook(eventHook.Id) + foundEventHook, _, err := client.EventHook.GetEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "get an event hook should not error") require.Equal(t, "INACTIVE", foundEventHook.Status, "event hook was not inactive after deactivate") - response, err = client.EventHook.DeleteEventHook(eventHook.Id) + response, err = client.EventHook.DeleteEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deleting an event hook should not error") tests.Assert_response(t, response, "DELETE", "/api/v1/eventHooks/"+eventHook.Id) @@ -127,7 +128,7 @@ func Test_activate_an_event_hook(t *testing.T) { eventHookRequest := createEventHookRequestObject("activate an event hook") - eventHook, response, err := client.EventHook.CreateEventHook(eventHookRequest) + eventHook, response, err := client.EventHook.CreateEventHook(context.TODO(), eventHookRequest) require.NoError(t, err, "creating an event hook should not error") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks") @@ -135,19 +136,19 @@ func Test_activate_an_event_hook(t *testing.T) { assert_event_hook_model(t, eventHook) require.Equal(t, "ACTIVE", eventHook.Status, "event hook was not active") - eventHook, response, err = client.EventHook.DeactivateEventHook(eventHook.Id) + eventHook, response, err = client.EventHook.DeactivateEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deactivating an event hook should not error") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks/"+eventHook.Id+"/lifecycle/deactivate") require.Equal(t, "INACTIVE", eventHook.Status, "event hook was not active") - eventHook, response, err = client.EventHook.ActivateEventHook(eventHook.Id) + eventHook, response, err = client.EventHook.ActivateEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "activating an event hook should not error") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks/"+eventHook.Id+"/lifecycle/activate") require.Equal(t, "ACTIVE", eventHook.Status, "event hook was not active") - _, _, err = client.EventHook.DeactivateEventHook(eventHook.Id) + _, _, err = client.EventHook.DeactivateEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deactivating an event hook should not error") - response, err = client.EventHook.DeleteEventHook(eventHook.Id) + response, err = client.EventHook.DeleteEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deleting an event hook should not error") } @@ -157,12 +158,12 @@ func Test_list_event_hooks(t *testing.T) { eventHookRequest := createEventHookRequestObject("List event hooks") - eventHook, response, err := client.EventHook.CreateEventHook(eventHookRequest) + eventHook, response, err := client.EventHook.CreateEventHook(context.TODO(), eventHookRequest) require.NoError(t, err, "creating an event hook should not error") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks") - eventHookList, response, err := client.EventHook.ListEventHooks() + eventHookList, response, err := client.EventHook.ListEventHooks(context.TODO()) assert.IsType(t, []*okta.EventHook{}, eventHookList, "did not return a list of eventHook objects") found := false @@ -174,9 +175,9 @@ func Test_list_event_hooks(t *testing.T) { assert.True(t, found, "did not find the eventHook in the list") - _, _, err = client.EventHook.DeactivateEventHook(eventHook.Id) + _, _, err = client.EventHook.DeactivateEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deactivating an event hook should not error") - _, err = client.EventHook.DeleteEventHook(eventHook.Id) + _, err = client.EventHook.DeleteEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deleting an event hook should not error") } @@ -186,12 +187,12 @@ func Test_verify_an_event_hook(t *testing.T) { eventHookRequest := createEventHookRequestObject("Verify an event hook") - eventHook, response, err := client.EventHook.CreateEventHook(eventHookRequest) + eventHook, response, err := client.EventHook.CreateEventHook(context.TODO(), eventHookRequest) require.NoError(t, err, "creating an event hook should not error") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks") - _, response, err = client.EventHook.VerifyEventHook(eventHook.Id) + _, response, err = client.EventHook.VerifyEventHook(context.TODO(), eventHook.Id) // We expect this call to error. Our test is just making sure we have the correct endpoint. // To fully test this, we have to have an acutal endpoint that will respond to event hooks. @@ -199,9 +200,9 @@ func Test_verify_an_event_hook(t *testing.T) { require.Equal(t, 400, response.StatusCode, "Should have errored with a 400 status code") tests.Assert_response(t, response, "POST", "/api/v1/eventHooks/"+eventHook.Id+"/lifecycle/verify") - _, _, err = client.EventHook.DeactivateEventHook(eventHook.Id) + _, _, err = client.EventHook.DeactivateEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deactivating an event hook should not error") - _, err = client.EventHook.DeleteEventHook(eventHook.Id) + _, err = client.EventHook.DeleteEventHook(context.TODO(), eventHook.Id) require.NoError(t, err, "deleting an event hook should not error") } @@ -209,22 +210,21 @@ func Test_verify_an_event_hook(t *testing.T) { func createEventHookRequestObject(name string) okta.EventHook { eventHookEvent := okta.EventSubscriptions{ Type: "EVENT_TYPE", - Items: []string { + Items: []string{ "user.lifecycle.create", "user.lifecycle.activate", }, } eventHookChannelConfigHeader := okta.EventHookChannelConfigHeader{ - Key: "X-Other-Header", + Key: "X-Other-Header", Value: "some-other-value", } eventHookChannelConfigAuthScheme := okta.EventHookChannelConfigAuthScheme{ - Type: "HEADER", - Key: "Authorization", + Type: "HEADER", + Key: "Authorization", Value: "MyApiKey", - } eventHookChannelConfig := okta.EventHookChannelConfig{ @@ -236,14 +236,14 @@ func createEventHookRequestObject(name string) okta.EventHook { } eventHookChannel := okta.EventHookChannel{ - Type: "HTTP", + Type: "HTTP", Version: "1.0.0", - Config: &eventHookChannelConfig, + Config: &eventHookChannelConfig, } eventHookRequest := okta.EventHook{ - Name: "GO SDK: " + name, - Events: &eventHookEvent, + Name: "GO SDK: " + name, + Events: &eventHookEvent, Channel: &eventHookChannel, } diff --git a/tests/integration/factor_test.go b/tests/integration/factor_test.go index 23857cf84..4b457fa92 100644 --- a/tests/integration/factor_test.go +++ b/tests/integration/factor_test.go @@ -17,6 +17,7 @@ package integration import ( + "context" "testing" "github.com/okta/okta-sdk-golang/v2/okta" @@ -29,10 +30,10 @@ import ( func Test_exercise_factor_lifecycle(t *testing.T) { client, _ := tests.NewClient() - user, _, err := client.User.GetUser("john-factor-lifecycle@example.com") + user, _, err := client.User.GetUser(context.TODO(), "john-factor-lifecycle@example.com") if user != nil { - client.User.DeactivateUser(user.Id, nil) - client.User.DeactivateOrDeleteUser(user.Id, nil) + client.User.DeactivateUser(context.TODO(), user.Id, nil) + client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) } p := &okta.PasswordCredential{ @@ -52,10 +53,10 @@ func Test_exercise_factor_lifecycle(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(false)) - user, _, err = client.User.CreateUser(*u, qp) + user, _, err = client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") - allowedFactors, _, _ := client.UserFactor.ListSupportedFactors(user.Id) + allowedFactors, _, _ := client.UserFactor.ListSupportedFactors(context.TODO(), user.Id) continueTesting := false for _, f := range allowedFactors { if f.(*okta.UserFactor).FactorType == "sms" { @@ -64,7 +65,7 @@ func Test_exercise_factor_lifecycle(t *testing.T) { } if continueTesting { - factors, _, listFactorsError := client.UserFactor.ListFactors(user.Id) + factors, _, listFactorsError := client.UserFactor.ListFactors(context.TODO(), user.Id) require.NoError(t, listFactorsError, "Should not error when listing factors") assert.Empty(t, factors, "Factors list should be empty") @@ -75,19 +76,19 @@ func Test_exercise_factor_lifecycle(t *testing.T) { factor := okta.NewSmsUserFactor() factor.Profile = factorProfile - addedFactor, resp, err := client.UserFactor.EnrollFactor(user.Id, factor, nil) + addedFactor, resp, err := client.UserFactor.EnrollFactor(context.TODO(), user.Id, factor, nil) require.NotEmpty(t, resp, "Response should not be empty") require.NoError(t, err, "Adding factor should not error") assert.IsType(t, okta.NewUserFactor(), addedFactor) - foundFactor, _, err := client.UserFactor.GetFactor(user.Id, addedFactor.(*okta.UserFactor).Id, okta.NewSmsUserFactor()) + foundFactor, _, err := client.UserFactor.GetFactor(context.TODO(), user.Id, addedFactor.(*okta.UserFactor).Id, okta.NewSmsUserFactor()) require.NoError(t, err, "Getting the factor should not error") - client.UserFactor.DeleteFactor(user.Id, foundFactor.(*okta.UserFactor).Id) + client.UserFactor.DeleteFactor(context.TODO(), user.Id, foundFactor.(*okta.UserFactor).Id) } else { t.Skip("Skipping exercise factor lifecycle testing. SMS factor was not enabled") } - client.User.DeactivateUser(user.Id, nil) - client.User.DeactivateOrDeleteUser(user.Id, nil) + client.User.DeactivateUser(context.TODO(), user.Id, nil) + client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) } diff --git a/tests/integration/feature_test.go b/tests/integration/feature_test.go index 956f2f742..cc0c21449 100644 --- a/tests/integration/feature_test.go +++ b/tests/integration/feature_test.go @@ -17,6 +17,7 @@ package integration import ( + "context" "testing" "github.com/okta/okta-sdk-golang/v2/okta" @@ -29,7 +30,7 @@ import ( func Test_can_list_all_features_for_organization(t *testing.T) { client, _ := tests.NewClient() - features, response, err := client.Feature.ListFeatures() + features, response, err := client.Feature.ListFeatures(context.TODO()) require.NoError(t, err, "listing features must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") @@ -51,11 +52,11 @@ func Test_can_list_all_features_for_organization(t *testing.T) { func Test_can_get_a_feature(t *testing.T) { client, _ := tests.NewClient() - features, _, err := client.Feature.ListFeatures() + features, _, err := client.Feature.ListFeatures(context.TODO()) require.NoError(t, err, "listing features must not error") firstFeatureId := features[0].Id - feature, response, err := client.Feature.GetFeature(firstFeatureId) + feature, response, err := client.Feature.GetFeature(context.TODO(), firstFeatureId) require.NoError(t, err, "getting a feature must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") @@ -77,11 +78,11 @@ func Test_can_get_a_feature(t *testing.T) { func Test_can_get_feature_dependencies(t *testing.T) { client, _ := tests.NewClient() - features, _, err := client.Feature.ListFeatures() + features, _, err := client.Feature.ListFeatures(context.TODO()) require.NoError(t, err, "listing features must not error") firstFeatureId := features[0].Id - featureDependencies, response, err := client.Feature.ListFeatureDependencies(firstFeatureId) + featureDependencies, response, err := client.Feature.ListFeatureDependencies(context.TODO(), firstFeatureId) require.NoError(t, err, "getting a features dependencies must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") @@ -94,11 +95,11 @@ func Test_can_get_feature_dependencies(t *testing.T) { func Test_can_get_feature_dependants(t *testing.T) { client, _ := tests.NewClient() - features, _, err := client.Feature.ListFeatures() + features, _, err := client.Feature.ListFeatures(context.TODO()) require.NoError(t, err, "listing features must not error") firstFeatureId := features[0].Id - featureDependants, response, err := client.Feature.ListFeatureDependents(firstFeatureId) + featureDependants, response, err := client.Feature.ListFeatureDependents(context.TODO(), firstFeatureId) require.NoError(t, err, "getting a features dependants must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") @@ -111,7 +112,7 @@ func Test_can_get_feature_dependants(t *testing.T) { func Test_can_update_a_feature_lifecycle(t *testing.T) { client, _ := tests.NewClient() - features, _, err := client.Feature.ListFeatures() + features, _, err := client.Feature.ListFeatures(context.TODO()) require.NoError(t, err, "listing features must not error") firstFeatureId := features[0].Id @@ -120,7 +121,7 @@ func Test_can_update_a_feature_lifecycle(t *testing.T) { if origStatus == "DISABLED" { statusTo = "enable" } - statusChange, response, err := client.Feature.UpdateFeatureLifecycle(firstFeatureId, statusTo, nil) + statusChange, response, err := client.Feature.UpdateFeatureLifecycle(context.TODO(), firstFeatureId, statusTo, nil) require.NoError(t, err, "updating feature status should not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") @@ -133,7 +134,7 @@ func Test_can_update_a_feature_lifecycle(t *testing.T) { if origStatus == "DISABLED" { toOrigStatus = "disable" } - updatedStatusChange, response, err := client.Feature.UpdateFeatureLifecycle(firstFeatureId, toOrigStatus, nil) + updatedStatusChange, response, err := client.Feature.UpdateFeatureLifecycle(context.TODO(), firstFeatureId, toOrigStatus, nil) require.NoError(t, err, "updating feature status should not error") assert.Equal(t, origStatus, updatedStatusChange.Status, "did not change the status back") assert.Equal(t, "/api/v1/features/"+firstFeatureId+"/"+toOrigStatus, response.Response.Request.URL.Path, "path for request was incorrect") diff --git a/tests/integration/group_test.go b/tests/integration/group_test.go index a4dc6aca2..c980c798d 100644 --- a/tests/integration/group_test.go +++ b/tests/integration/group_test.go @@ -17,6 +17,7 @@ package integration import ( + "context" "net/http" "testing" "time" @@ -38,21 +39,21 @@ func Test_can_get_a_group(t *testing.T) { g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") assert.IsType(t, &okta.Group{}, group) // Get the group by ID → GET /api/v1/groups/{{groupId}} - foundGroup, _, err := client.Group.GetGroup(group.Id) + foundGroup, _, err := client.Group.GetGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when finding a group") assert.Equal(t, group.Id, foundGroup.Id, "Group that was found was not correct") // Delete the group → DELETE /api/v1/groups/{{groupId}} - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") // Verify that the group is deleted by calling get on group (Exception thrown with 404 error message) → GET /api/v1/groups/{{groupId}} - _, resp, err := client.Group.GetGroup(group.Id) + _, resp, err := client.Group.GetGroup(context.TODO(), group.Id) assert.Error(t, err, "Finding a group by id should have reported an error") assert.Equal(t, http.StatusNotFound, resp.StatusCode, "Should have resulted in a 404 when finding a deleted group") @@ -67,12 +68,12 @@ func Test_can_list_groups(t *testing.T) { g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") assert.IsType(t, &okta.Group{}, group) // List all groups and find the group created → GET /api/v1/groups - groupList, _, err := client.Group.ListGroups(nil) + groupList, _, err := client.Group.ListGroups(context.TODO(), nil) require.NoError(t, err, "Listing groups should not error") found := false for _, grp := range groupList { @@ -83,7 +84,7 @@ func Test_can_list_groups(t *testing.T) { assert.True(t, found, "Could not find group from list") // Delete the group → DELETE /api/v1/groups/{{groupId}} - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } @@ -96,12 +97,12 @@ func Test_can_search_for_a_group(t *testing.T) { g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") assert.IsType(t, &okta.Group{}, group) // Search the group by name with query parameter → GET /api/v1/groups?q=Search - groupList, _, err := client.Group.ListGroups(query.NewQueryParams(query.WithQ("Search Test Group"))) + groupList, _, err := client.Group.ListGroups(context.TODO(), query.NewQueryParams(query.WithQ("Search Test Group"))) assert.Len(t, groupList, 1, "Did not find correct amount of groups") require.NoError(t, err, "Listing groups should not error") found := false @@ -113,7 +114,7 @@ func Test_can_search_for_a_group(t *testing.T) { assert.True(t, found, "Could not find group from list") // Delete the group → DELETE /api/v1/groups/{{groupId}} - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } @@ -126,7 +127,7 @@ func Test_can_update_a_group(t *testing.T) { g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") assert.IsType(t, &okta.Group{}, group) @@ -134,15 +135,15 @@ func Test_can_update_a_group(t *testing.T) { ngp := &okta.GroupProfile{ Name: "Updated Name", } - client.Group.UpdateGroup(group.Id, okta.Group{Profile: ngp}) + client.Group.UpdateGroup(context.TODO(), group.Id, okta.Group{Profile: ngp}) // Verify that group profile is updated by calling get on the group and verifying the profile → GET /api/v1/groups/{{groupId}} - updatedGroup, _, err := client.Group.GetGroup(group.Id) + updatedGroup, _, err := client.Group.GetGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when getting updated group") assert.Equal(t, "Updated Name", updatedGroup.Profile.Name, "The group was not updated") // Delete the group → DELETE /api/v1/groups/{{groupId}} - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } @@ -166,7 +167,7 @@ func Test_group_user_operations(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(false)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") assert.IsType(t, &okta.User{}, user) @@ -178,16 +179,16 @@ func Test_group_user_operations(t *testing.T) { Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") assert.IsType(t, &okta.Group{}, group) // Add user to the group → POST /api/v1/groups/{{groupId}}/users/{{userId}} - _, err = client.Group.AddUserToGroup(group.Id, user.Id) + _, err = client.Group.AddUserToGroup(context.TODO(), group.Id, user.Id) require.NoError(t, err, "Should not error when adding user to group") // Validate user present in group → GET /api/v1/groups/{{groupId}}/users - users, _, err := client.Group.ListGroupUsers(group.Id, nil) + users, _, err := client.Group.ListGroupUsers(context.TODO(), group.Id, nil) found := false for _, tmpuser := range users { if tmpuser.Id == user.Id { @@ -197,15 +198,15 @@ func Test_group_user_operations(t *testing.T) { assert.True(t, found, "Could not find user in group") // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") // Delete the group → DELETE /api/v1/groups/{{groupId}} - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting a group") } @@ -229,7 +230,7 @@ func Test_group_rule_operations(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(true)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") assert.IsType(t, &okta.User{}, user) @@ -240,7 +241,7 @@ func Test_group_rule_operations(t *testing.T) { g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Should not error when creating a group") assert.IsType(t, &okta.Group{}, group) @@ -266,16 +267,16 @@ func Test_group_rule_operations(t *testing.T) { Type: "group_rule", Name: "Test group rule", } - groupRule, _, err := client.Group.CreateGroupRule(*gr) + groupRule, _, err := client.Group.CreateGroupRule(context.TODO(), *gr) require.NoError(t, err, "Should not error when creating a group Rule") assert.IsType(t, &okta.GroupRule{}, groupRule) // Activate the above rule and verify that user is added to the group → POST /api/v1/groups/rules/{{ruleId}}/lifecycle/activate - _, err = client.Group.ActivateGroupRule(groupRule.Id) + _, err = client.Group.ActivateGroupRule(context.TODO(), groupRule.Id) require.NoError(t, err, "Should not error when activating rule") time.Sleep(6 * time.Second) - users, _, err := client.Group.ListGroupUsers(group.Id, nil) + users, _, err := client.Group.ListGroupUsers(context.TODO(), group.Id, nil) found := false for _, tmpuser := range users { if tmpuser.Id == user.Id { @@ -285,7 +286,7 @@ func Test_group_rule_operations(t *testing.T) { assert.True(t, found, "Group rule execution did not happen") // List the group rules and validate the above rule is present → POST /api/v1/groups/rules - groupRules, _, err := client.Group.ListGroupRules(nil) + groupRules, _, err := client.Group.ListGroupRules(context.TODO(), nil) require.NoError(t, err, "Error should not happen when listing rules") found = false for _, tmpRules := range groupRules { @@ -296,7 +297,7 @@ func Test_group_rule_operations(t *testing.T) { assert.True(t, found, "Group rule execution did not happen") // Deactivate the rule → POST /api/v1/groups/rules/{{ruleId}}/lifecycle/deactivate - _, err = client.Group.DeactivateGroupRule(groupRule.Id) + _, err = client.Group.DeactivateGroupRule(context.TODO(), groupRule.Id) require.NoError(t, err, "Error should not happen when deactivating rule") // Update the rule (Rule can only be updated when it's deactivated) → POST /api/v1/groups/rules/{{ruleId}} @@ -319,14 +320,14 @@ func Test_group_rule_operations(t *testing.T) { Type: "group_rule", Name: "Test group rule Updated", } - newGroupRule, _, err := client.Group.UpdateGroupRule(groupRule.Id, *gr) + newGroupRule, _, err := client.Group.UpdateGroupRule(context.TODO(), groupRule.Id, *gr) require.NoError(t, err, "Should not error when updating rule") // Activate the updated rule and verify that the user is removed from the group → POST /api/v1/groups/rules/{{ruleId}}/lifecycle/activate - _, err = client.Group.ActivateGroupRule(newGroupRule.Id) + _, err = client.Group.ActivateGroupRule(context.TODO(), newGroupRule.Id) require.NoError(t, err, "Should not error when activating the group rule") time.Sleep(2 * time.Second) - users, _, err = client.Group.ListGroupUsers(group.Id, nil) + users, _, err = client.Group.ListGroupUsers(context.TODO(), group.Id, nil) found = false for _, tmpuser := range users { if tmpuser.Id == user.Id { @@ -336,21 +337,21 @@ func Test_group_rule_operations(t *testing.T) { assert.False(t, found, "Group rule execution did not happen to remove user") // Deactivate the user, group and group rule → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.Group.DeactivateGroupRule(newGroupRule.Id) + _, err = client.Group.DeactivateGroupRule(context.TODO(), newGroupRule.Id) require.NoError(t, err, "should not error when deactivating rule") - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "should not error when deactivating user") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting user") // Delete the group → DELETE /api/v1/groups/{{groupId}} - _, err = client.Group.DeleteGroup(group.Id) + _, err = client.Group.DeleteGroup(context.TODO(), group.Id) require.NoError(t, err, "Should not error when deleting Group") // Delete the group rule → DELETE /api/v1/groups/rules/{{ruleId}} - _, err = client.Group.DeleteGroupRule(groupRule.Id) + _, err = client.Group.DeleteGroupRule(context.TODO(), groupRule.Id) require.NoError(t, err, "Should not error when deleting Rule") } diff --git a/tests/integration/request_test.go b/tests/integration/request_test.go index cd0a2655c..c44705ea2 100644 --- a/tests/integration/request_test.go +++ b/tests/integration/request_test.go @@ -17,6 +17,7 @@ package integration import ( + "context" "io" "testing" @@ -59,17 +60,17 @@ func Test_private_key_request_can_create_a_user(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(false)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") assert.NotEmpty(t, user.Id, "appears the user was not created") tempProfile := *user.Profile assert.Equal(t, "john-private-key@example.com", tempProfile["email"], "did not get the correct user") // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") } diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go index b34b8c125..707b7363b 100644 --- a/tests/integration/user_test.go +++ b/tests/integration/user_test.go @@ -17,6 +17,7 @@ package integration import ( + "context" "net/http" "testing" "time" @@ -49,29 +50,29 @@ func Test_can_get_a_user(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(false)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") // Get the user by ID → GET /api/v1/users/{{userId}} - ubid, _, err := client.User.GetUser(user.Id) + ubid, _, err := client.User.GetUser(context.TODO(), user.Id) require.NoError(t, err, "Getting a user by id should not error") assert.Equal(t, user.Id, ubid.Id, "Could not find user by Id") // Get the user by login name → GET /api/v1/users/{{login}} - ubln, _, err := client.User.GetUser(profile["login"].(string)) + ubln, _, err := client.User.GetUser(context.TODO(), profile["login"].(string)) require.NoError(t, err, "Getting a user by login should not error") assert.Equal(t, user.Id, ubln.Id, "Could not find user by Login") // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") // Verify that the user is deleted by calling get on user (Exception thrown with 404 error message) → GET /api/v1/users/{{userId}} - _, _, err = client.User.GetUser(user.Id) + _, _, err = client.User.GetUser(context.TODO(), user.Id) require.Error(t, err, "User should not exist, but does") } @@ -95,18 +96,18 @@ func Test_can_activate_a_user(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(false)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") // Activate the user → POST /api/v1/users/{{userId}}/lifecycle/activate?sendEmail=false - token, _, err := client.User.ActivateUser(user.Id, query.NewQueryParams(query.WithSendEmail(false))) + token, _, err := client.User.ActivateUser(context.TODO(), user.Id, query.NewQueryParams(query.WithSendEmail(false))) require.NoError(t, err, "Could not activate the user") assert.NotEmpty(t, token, "Token was not provided") assert.IsType(t, &okta.UserActivationToken{}, token, "Activation did not return correct type") // Verify that the user is in the list of ACTIVE users with query parameter → GET /api/v1/users?filter=status eq "ACTIVE" filter := query.NewQueryParams(query.WithFilter("status eq \"ACTIVE\"")) - users, _, err := client.User.ListUsers(filter) + users, _, err := client.User.ListUsers(context.TODO(), filter) require.NoError(t, err, "Could not get active users") found := false for _, u := range users { @@ -117,11 +118,11 @@ func Test_can_activate_a_user(t *testing.T) { assert.True(t, found, "The user was not found") // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") } @@ -145,7 +146,7 @@ func Test_can_update_user_profile(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(false)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") // Update the user's profile by adding a nickname → PUT /api/v1/users/{{userId}} @@ -154,20 +155,20 @@ func Test_can_update_user_profile(t *testing.T) { updatedUser := &okta.User{ Profile: &newProfile, } - _, _, err = client.User.UpdateUser(user.Id, *updatedUser, nil) + _, _, err = client.User.UpdateUser(context.TODO(), user.Id, *updatedUser, nil) require.NoError(t, err, "Could not update the user") // Verify that user profile is updated by calling get on the user → GET /api/v1/users/{{userId}} - tmpUser, _, err := client.User.GetUser(user.Id) + tmpUser, _, err := client.User.GetUser(context.TODO(), user.Id) require.NoError(t, err, "User was not available to get") tmpProfile := *tmpUser.Profile assert.Equal(t, "Batman", tmpProfile["nickName"]) // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") } @@ -191,16 +192,16 @@ func Test_can_suspend_a_user(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(true)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") // Suspend the user → POST /api/v1/users/{{userId}}/lifecycle/suspend - _, err = client.User.SuspendUser(user.Id) + _, err = client.User.SuspendUser(context.TODO(), user.Id) require.NoError(t, err, "Could not suspend the user") // Verify that user is in the list of suspended users → GET /api/v1/users?filter=status eq "SUSPENDED" filter := query.NewQueryParams(query.WithFilter("status eq \"SUSPENDED\"")) - users, _, err := client.User.ListUsers(filter) + users, _, err := client.User.ListUsers(context.TODO(), filter) require.NoError(t, err, "Could not get suspended users") found := false for _, u := range users { @@ -211,12 +212,12 @@ func Test_can_suspend_a_user(t *testing.T) { assert.True(t, found, "The user was not found") // Unsuspend the user → POST /api/v1/users/{{userId}}/lifecycle/unsuspend - _, err = client.User.UnsuspendUser(user.Id) + _, err = client.User.UnsuspendUser(context.TODO(), user.Id) require.NoError(t, err, "Could not unsuspend the user") // Verify that user is in the list of active users → GET /api/v1/users?filter=status eq "ACTIVE" filter = query.NewQueryParams(query.WithFilter("status eq \"ACTIVE\"")) - users, _, err = client.User.ListUsers(filter) + users, _, err = client.User.ListUsers(context.TODO(), filter) require.NoError(t, err, "Could not get active users") found = false for _, u := range users { @@ -226,11 +227,11 @@ func Test_can_suspend_a_user(t *testing.T) { } // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") } @@ -254,7 +255,7 @@ func Test_can_change_users_password(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(true)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") //Sleep 1 second to make sure time has passed for password chagned timestamps @@ -271,25 +272,25 @@ func Test_can_change_users_password(t *testing.T) { OldPassword: op, NewPassword: np, } - _, _, err = client.User.ChangePassword(user.Id, *npr, nil) + _, _, err = client.User.ChangePassword(context.TODO(), user.Id, *npr, nil) require.NoError(t, err, "Could not change password") // Get the user and verify that 'passwordChanged' field has increased → GET /api/v1/users/{{userId}}/ - ubid, _, err := client.User.GetUser(user.Id) + ubid, _, err := client.User.GetUser(context.TODO(), user.Id) require.NoError(t, err, "Getting a user by login should not error") assert.Equal(t, user.Id, ubid.Id, "Could not find user by Login") assert.True(t, ubid.PasswordChanged.After(*user.PasswordChanged), "Appears that password change did not happen") // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") // Verify that the user is deleted by calling get on user (Exception thrown with 404 error message) → GET /api/v1/users/{{userId}} - _, _, err = client.User.GetUser(user.Id) + _, _, err = client.User.GetUser(context.TODO(), user.Id) require.Error(t, err, "User should not exist, but does") } @@ -313,11 +314,11 @@ func Test_can_get_reset_password_link_for_user(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(true)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") // Reset the user password → POST /api/v1/users/{{userId}}/lifecycle/reset_password?sendEmail=false - rpt, _, err := client.User.ResetPassword(user.Id, query.NewQueryParams(query.WithSendEmail(false))) + rpt, _, err := client.User.ResetPassword(context.TODO(), user.Id, query.NewQueryParams(query.WithSendEmail(false))) require.NoError(t, err, "Could not reset password") // Verify that the response returned contains the reset password link @@ -325,15 +326,15 @@ func Test_can_get_reset_password_link_for_user(t *testing.T) { assert.NotEmpty(t, rpt.ResetPasswordUrl, "Reset Password is not set") // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") // Verify that the user is deleted by calling get on user (Exception thrown with 404 error message) → GET /api/v1/users/{{userId}} - _, _, err = client.User.GetUser(user.Id) + _, _, err = client.User.GetUser(context.TODO(), user.Id) require.Error(t, err, "User should not exist, but does") } @@ -357,11 +358,11 @@ func Test_can_expire_a_users_password_and_get_a_temp_one(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(true)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") // Expire the user password → POST /api/v1/users/{{userId}}/lifecycle/expire_password?tempPassword=true - ep, _, err := client.User.ExpirePasswordAndGetTemporaryPassword(user.Id) + ep, _, err := client.User.ExpirePasswordAndGetTemporaryPassword(context.TODO(), user.Id) require.NoError(t, err, "Could not reset password") // Verify that the returned response contains a temporary password @@ -369,15 +370,15 @@ func Test_can_expire_a_users_password_and_get_a_temp_one(t *testing.T) { assert.NotEmpty(t, ep.TempPassword, "Temp Password not provided") // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") // Verify that the user is deleted by calling get on user (Exception thrown with 404 error message) → GET /api/v1/users/{{userId}} - _, _, err = client.User.GetUser(user.Id) + _, _, err = client.User.GetUser(context.TODO(), user.Id) require.Error(t, err, "User should not exist, but does") } @@ -401,7 +402,7 @@ func Test_can_change_user_recovery_question(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(true)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") // Update the user's recovery question → POST /api/v1/users/{{userId}}/credentials/change_recovery_question @@ -416,7 +417,7 @@ func Test_can_change_user_recovery_question(t *testing.T) { Password: nucp, RecoveryQuestion: nucrq, } - tmpuc, _, err := client.User.ChangeRecoveryQuestion(user.Id, *nuc) + tmpuc, _, err := client.User.ChangeRecoveryQuestion(context.TODO(), user.Id, *nuc) require.NoError(t, err, "Could not change recovery question") assert.IsType(t, &okta.UserCredentials{}, tmpuc) @@ -431,25 +432,25 @@ func Test_can_change_user_recovery_question(t *testing.T) { Password: np, RecoveryQuestion: rq, } - _, _, err = client.User.ForgotPasswordSetNewPassword(user.Id, *ucfp, nil) + _, _, err = client.User.ForgotPasswordSetNewPassword(context.TODO(), user.Id, *ucfp, nil) require.NoError(t, err, "Could not change password with recovery question") // Get the user and verify that 'passwordChanged' field has increased → GET /api/v1/users/{{userId}} - ubid, _, err := client.User.GetUser(user.Id) + ubid, _, err := client.User.GetUser(context.TODO(), user.Id) require.NoError(t, err, "Getting a user by login should not error") assert.Equal(t, user.Id, ubid.Id, "Could not find user by Login") assert.True(t, ubid.PasswordChanged.After(*user.PasswordChanged), "Appears that password change did not happen") // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") // Verify that the user is deleted by calling get on user (Exception thrown with 404 error message) → GET /api/v1/users/{{userId}} - _, _, err = client.User.GetUser(user.Id) + _, _, err = client.User.GetUser(context.TODO(), user.Id) require.Error(t, err, "User should not exist, but does") } @@ -473,18 +474,18 @@ func Test_can_assign_a_user_to_a_role(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(true)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") // Add 'USER_ADMIN' role to the user → POST /api/v1/users/{{userId}}/roles (Body → { type: 'USER_ADMIN' }) arr := &okta.AssignRoleRequest{ Type: "USER_ADMIN", } - _, _, err = client.User.AssignRoleToUser(user.Id, *arr, nil) + _, _, err = client.User.AssignRoleToUser(context.TODO(), user.Id, *arr, nil) require.NoError(t, err, "Should not have had an error when adding role to user") // List roles for the user and verify added role → GET /api/v1/users/{{userId}}/roles - roles, _, err := client.User.ListAssignedRolesForUser(user.Id, nil) + roles, _, err := client.User.ListAssignedRolesForUser(context.TODO(), user.Id, nil) found := false roleId := "" for _, role := range roles { @@ -496,11 +497,11 @@ func Test_can_assign_a_user_to_a_role(t *testing.T) { assert.True(t, found, "Could not verify USER_ADMIN was added to the user") // Remove role for the user → DELETE /api/v1/users/{{userId}}//roles/{{roleId}}/ - _, err = client.User.RemoveRoleFromUser(user.Id, roleId) + _, err = client.User.RemoveRoleFromUser(context.TODO(), user.Id, roleId) require.NoError(t, err, "Should not have had an error when removing role to user") // List roles for user and verify role was removed → GET /api/v1/users/{{userId}}/roles - roles, _, err = client.User.ListAssignedRolesForUser(user.Id, nil) + roles, _, err = client.User.ListAssignedRolesForUser(context.TODO(), user.Id, nil) found = false roleId = "" for _, role := range roles { @@ -512,15 +513,15 @@ func Test_can_assign_a_user_to_a_role(t *testing.T) { assert.False(t, found, "Could not verify USER_ADMIN was removed to the user") // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") // Verify that the user is deleted by calling get on user (Exception thrown with 404 error message) → GET /api/v1/users/{{userId}} - _, resp, err := client.User.GetUser(user.Id) + _, resp, err := client.User.GetUser(context.TODO(), user.Id) require.Error(t, err, "User should not exist, but does") assert.Equal(t, http.StatusNotFound, resp.StatusCode, "Should not have been able to find user") } @@ -545,7 +546,7 @@ func Test_user_group_target_role(t *testing.T) { } qp := query.NewQueryParams(query.WithActivate(true)) - user, _, err := client.User.CreateUser(*u, qp) + user, _, err := client.User.CreateUser(context.TODO(), *u, qp) require.NoError(t, err, "Creating an user should not error") // Create a new group → POST /api/v1/groups @@ -555,22 +556,22 @@ func Test_user_group_target_role(t *testing.T) { g := &okta.Group{ Profile: gp, } - group, _, err := client.Group.CreateGroup(*g) + group, _, err := client.Group.CreateGroup(context.TODO(), *g) require.NoError(t, err, "Creating an group should not error") // Add 'USER_ADMIN' role to the user → POST /api/v1/users/{{userId}}/roles (Body → { type: 'USER_ADMIN' }) arr := &okta.AssignRoleRequest{ Type: "USER_ADMIN", } - r, _, err := client.User.AssignRoleToUser(user.Id, *arr, nil) + r, _, err := client.User.AssignRoleToUser(context.TODO(), user.Id, *arr, nil) require.NoError(t, err, "Should not have had an error when adding role to user") // Add Group Target to 'USER_ADMIN' role → PUT /api/v1/users/{{userId}}/roles/{{roleId}}/targets/groups/{{groupId}} - resp, err := client.User.AddGroupTargetToRole(user.Id, r.Id, group.Id) + resp, err := client.User.AddGroupTargetToRole(context.TODO(), user.Id, r.Id, group.Id) require.NoError(t, err, "Should not have had an error when adding group target to role") // List Group Targets for role → GET /api/v1/users/{{userId}}/roles/{{roleId}}/targets/groups - groups, _, err := client.User.ListGroupTargetsForRole(user.Id, r.Id, nil) + groups, _, err := client.User.ListGroupTargetsForRole(context.TODO(), user.Id, r.Id, nil) found := false for _, tmpgroup := range groups { if tmpgroup.Id == group.Id { @@ -586,25 +587,25 @@ func Test_user_group_target_role(t *testing.T) { g = &okta.Group{ Profile: gp, } - newgroup, _, err := client.Group.CreateGroup(*g) - _, err = client.User.AddGroupTargetToRole(user.Id, r.Id, newgroup.Id) - _, err = client.User.RemoveGroupTargetFromRole(user.Id, r.Id, group.Id) + newgroup, _, err := client.Group.CreateGroup(context.TODO(), *g) + _, err = client.User.AddGroupTargetToRole(context.TODO(), user.Id, r.Id, newgroup.Id) + _, err = client.User.RemoveGroupTargetFromRole(context.TODO(), user.Id, r.Id, group.Id) require.NoError(t, err, "Should not have had an error when removing group target to role") // Deactivate the user → POST /api/v1/users/{{userId}}/lifecycle/deactivate - _, err = client.User.DeactivateUser(user.Id, nil) + _, err = client.User.DeactivateUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deactivating") // Delete the user → DELETE /api/v1/users/{{userId}} - _, err = client.User.DeactivateOrDeleteUser(user.Id, nil) + _, err = client.User.DeactivateOrDeleteUser(context.TODO(), user.Id, nil) require.NoError(t, err, "Should not error when deleting") // Verify that the user is deleted by calling get on user (Exception thrown with 404 error message) → GET /api/v1/users/{{userId}} - _, resp, err = client.User.GetUser(user.Id) + _, resp, err = client.User.GetUser(context.TODO(), user.Id) require.Error(t, err, "User should not exist, but does") assert.Equal(t, http.StatusNotFound, resp.StatusCode, "Should not have been able to find user") // Delete the group → DELETE /api/v1/groups/{{groupId}} - client.Group.DeleteGroup(group.Id) - client.Group.DeleteGroup(newgroup.Id) + client.Group.DeleteGroup(context.TODO(), group.Id) + client.Group.DeleteGroup(context.TODO(), newgroup.Id) } diff --git a/tests/integration/user_type_test.go b/tests/integration/user_type_test.go index d8600f682..cf21266a4 100644 --- a/tests/integration/user_type_test.go +++ b/tests/integration/user_type_test.go @@ -17,6 +17,7 @@ package integration import ( + "context" "testing" "time" @@ -35,13 +36,13 @@ func Test_can_create_user_type(t *testing.T) { Name: "userTypeName", } - userType, response, err := client.UserType.CreateUserType(ut) + userType, response, err := client.UserType.CreateUserType(context.TODO(), ut) require.NoError(t, err, "creating a user type should not error") tests.Assert_response(t, response, "POST", "/api/v1/meta/types/user") assert_user_type_model(t, userType) - _, err = client.UserType.DeleteUserType(userType.Id) + _, err = client.UserType.DeleteUserType(context.TODO(), userType.Id) require.NoError(t, err, "deleting a user type should not error") } @@ -49,7 +50,7 @@ func Test_can_create_user_type(t *testing.T) { func Test_can_list_user_types(t *testing.T) { client, _ := tests.NewClient() - userTypes, response, err := client.UserType.ListUserTypes() + userTypes, response, err := client.UserType.ListUserTypes(context.TODO()) require.NoError(t, err, "creating a user type should not error") tests.Assert_response(t, response, "GET", "/api/v1/meta/types/user") diff --git a/tests/testCommon.go b/tests/testCommon.go index 505ca471c..27e93081f 100644 --- a/tests/testCommon.go +++ b/tests/testCommon.go @@ -17,7 +17,6 @@ package tests import ( - "context" "fmt" "net/http" "testing" @@ -30,7 +29,7 @@ import ( ) func NewClient(conf ...okta.ConfigSetter) (*okta.Client, error) { - return okta.NewClient(context.Background(), conf...) + return okta.NewClient(conf...) } func MockResponse(responses ...*http.Response) httpmock.Responder { diff --git a/tests/unit/retry_logic_test.go b/tests/unit/retry_logic_test.go index 9f6745a1f..145b393be 100644 --- a/tests/unit/retry_logic_test.go +++ b/tests/unit/retry_logic_test.go @@ -17,6 +17,7 @@ package unit import ( + "context" "net/http" "strconv" "testing" @@ -43,7 +44,7 @@ func Test_429_Will_Automatically_Retry(t *testing.T) { ), ) - _, resp, err := client.User.ListUsers(nil) + _, resp, err := client.User.ListUsers(context.TODO(), nil) require.Nil(t, err, "Error should have been nil") require.NotNil(t, resp, "Response was nil") @@ -65,7 +66,7 @@ func Test_Will_Stop_Retrying_Based_On_Max_Retry_Configuration(t *testing.T) { ), ) - _, _, err := client.User.ListUsers(nil) + _, _, err := client.User.ListUsers(context.TODO(), nil) require.NotNil(t, err, "error was nil, but should have told the user they reached their max retry limit") httpmock.GetTotalCallCount() @@ -90,7 +91,7 @@ func Test_Will_Handle_Backoff_Strategy_For_429(t *testing.T) { ), ) - _, _, err := client.User.ListUsers(nil) + _, _, err := client.User.ListUsers(context.TODO(), nil) require.NotNil(t, err, "error was nil, but should have told the user they reached their max retry limit") httpmock.GetTotalCallCount() @@ -111,7 +112,7 @@ func Test_a_429_with_x_reset_header_throws_error(t *testing.T) { ), ) - _, _, err := client.User.ListUsers(nil) + _, _, err := client.User.ListUsers(context.TODO(), nil) require.NotNil(t, err, "error should not be nil. It should let user know the reset header is required") } @@ -128,19 +129,19 @@ func Test_a_429_with_no_date_header_throws_error(t *testing.T) { ), ) - _, _, err := client.User.ListUsers(nil) + _, _, err := client.User.ListUsers(context.TODO(), nil) require.NotNil(t, err, "error should not be nil. It should let user know the date header is required") } func Test_gets_the_correct_backoff_time(t *testing.T) { - backoff := okta.Get429BackoffTime(Mock429Response()) + backoff := okta.Get429BackoffTime(context.TODO(), Mock429Response()) require.Equal(t, int64(2), backoff, "backoff time should have only been 1 second") } func Test_with_multiple_x_rate_limit_request_times_still_retries(t *testing.T) { - backoff := okta.Get429BackoffTime(Mock429ResponseMultipleHeaders()) + backoff := okta.Get429BackoffTime(context.TODO(), Mock429ResponseMultipleHeaders()) require.Equal(t, int64(11), backoff, "Backoff time should handle the correct header") }