From c0aac5052f450af859304bf03e0b4161dbf37e6f Mon Sep 17 00:00:00 2001 From: SergkeiM Date: Wed, 29 Jul 2026 13:06:44 +0300 Subject: [PATCH] feat: Add Identity and Access Management (IAM) API endpoints This introduces client support and documentation for Permission Groups, Resource Groups, SSO Connectors, OAuth Clients, OAuth Scopes, and User Groups (including members). --- docs/content/2.client/21.iam/00.index.md | 18 ++ .../2.client/21.iam/01.permission-groups.md | 60 ++++++ .../2.client/21.iam/02.resource-groups.md | 143 +++++++++++++ docs/content/2.client/21.iam/03.sso.md | 164 +++++++++++++++ .../2.client/21.iam/04.oauth-clients.md | 190 ++++++++++++++++++ .../2.client/21.iam/05.oauth-scopes.md | 19 ++ .../21.iam/06.user-groups/00.index.md | 147 ++++++++++++++ .../21.iam/06.user-groups/01.members.md | 158 +++++++++++++++ src/Client.php | 2 + src/Endpoints/Iam.php | 76 +++++++ src/Endpoints/Iam/OauthClients.php | 123 ++++++++++++ src/Endpoints/Iam/OauthScopes.php | 21 ++ src/Endpoints/Iam/PermissionGroups.php | 39 ++++ src/Endpoints/Iam/ResourceGroups.php | 87 ++++++++ src/Endpoints/Iam/Sso.php | 101 ++++++++++ src/Endpoints/Iam/UserGroups.php | 98 +++++++++ src/Endpoints/Iam/UserGroups/Members.php | 89 ++++++++ test/Tests/Endpoints/Iam/OauthClientsTest.php | 133 ++++++++++++ test/Tests/Endpoints/Iam/OauthScopesTest.php | 27 +++ .../Endpoints/Iam/PermissionGroupsTest.php | 41 ++++ .../Endpoints/Iam/ResourceGroupsTest.php | 96 +++++++++ test/Tests/Endpoints/Iam/SsoTest.php | 107 ++++++++++ .../Endpoints/Iam/UserGroups/MembersTest.php | 89 ++++++++ test/Tests/Endpoints/Iam/UserGroupsTest.php | 93 +++++++++ 24 files changed, 2121 insertions(+) create mode 100644 docs/content/2.client/21.iam/00.index.md create mode 100644 docs/content/2.client/21.iam/01.permission-groups.md create mode 100644 docs/content/2.client/21.iam/02.resource-groups.md create mode 100644 docs/content/2.client/21.iam/03.sso.md create mode 100644 docs/content/2.client/21.iam/04.oauth-clients.md create mode 100644 docs/content/2.client/21.iam/05.oauth-scopes.md create mode 100644 docs/content/2.client/21.iam/06.user-groups/00.index.md create mode 100644 docs/content/2.client/21.iam/06.user-groups/01.members.md create mode 100644 src/Endpoints/Iam.php create mode 100644 src/Endpoints/Iam/OauthClients.php create mode 100644 src/Endpoints/Iam/OauthScopes.php create mode 100644 src/Endpoints/Iam/PermissionGroups.php create mode 100644 src/Endpoints/Iam/ResourceGroups.php create mode 100644 src/Endpoints/Iam/Sso.php create mode 100644 src/Endpoints/Iam/UserGroups.php create mode 100644 src/Endpoints/Iam/UserGroups/Members.php create mode 100644 test/Tests/Endpoints/Iam/OauthClientsTest.php create mode 100644 test/Tests/Endpoints/Iam/OauthScopesTest.php create mode 100644 test/Tests/Endpoints/Iam/PermissionGroupsTest.php create mode 100644 test/Tests/Endpoints/Iam/ResourceGroupsTest.php create mode 100644 test/Tests/Endpoints/Iam/SsoTest.php create mode 100644 test/Tests/Endpoints/Iam/UserGroups/MembersTest.php create mode 100644 test/Tests/Endpoints/Iam/UserGroupsTest.php diff --git a/docs/content/2.client/21.iam/00.index.md b/docs/content/2.client/21.iam/00.index.md new file mode 100644 index 0000000..599600f --- /dev/null +++ b/docs/content/2.client/21.iam/00.index.md @@ -0,0 +1,18 @@ +--- +title: Iam +description: "Identity and Access Management." +navigation: + title: Iam +--- + +Identity and Access Management. + +## Related + +- [Permission Groups](/client/iam/permission-groups) +- [Resource Groups](/client/iam/resource-groups) +- [Sso](/client/iam/sso) +- [Oauth Clients](/client/iam/oauth-clients) +- [Oauth Scopes](/client/iam/oauth-scopes) +- [User Groups](/client/iam/user-groups) + diff --git a/docs/content/2.client/21.iam/01.permission-groups.md b/docs/content/2.client/21.iam/01.permission-groups.md new file mode 100644 index 0000000..b0e4e6e --- /dev/null +++ b/docs/content/2.client/21.iam/01.permission-groups.md @@ -0,0 +1,60 @@ +--- +title: Permission Groups +description: "Permission Groups endpoint reference." +navigation: + title: Permission Groups +--- + +## List + +List all the permissions groups for an account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params, e.g. id, name, label." + default: "[]" +--- +:: + +```php [php] +$response = $client->iam()->permissionGroups()->list('ACCOUNT_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-permission-group-list"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Get information about a specific permission group in an account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "permissionGroupId" + type: "string" + required: true + description: "Permission Group identifier." +--- +:: + +```php [php] +$response = $client->iam()->permissionGroups()->get('ACCOUNT_ID', 'PERMISSION_GROUP_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-permission-group-details"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/21.iam/02.resource-groups.md b/docs/content/2.client/21.iam/02.resource-groups.md new file mode 100644 index 0000000..07a48d0 --- /dev/null +++ b/docs/content/2.client/21.iam/02.resource-groups.md @@ -0,0 +1,143 @@ +--- +title: Resource Groups +description: "Resource Groups endpoint reference." +navigation: + title: Resource Groups +--- + +## List + +List all the resource groups for an account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params, e.g. id, name." + default: "[]" +--- +:: + +```php [php] +$response = $client->iam()->resourceGroups()->list('ACCOUNT_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-resource-group-list"} +View this operation on the Cloudflare API Reference +:: + +## Create + +Create a new Resource Group under the specified account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "values" + type: "array" + required: true + description: "Resource Group values, requires name and scope." +--- +:: + +```php [php] +$response = $client->iam()->resourceGroups()->create('ACCOUNT_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-resource-group-create"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Get information about a specific resource group in an account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "resourceGroupId" + type: "string" + required: true + description: "Resource Group identifier." +--- +:: + +```php [php] +$response = $client->iam()->resourceGroups()->get('ACCOUNT_ID', 'RESOURCE_GROUP_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-resource-group-details"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Modify an existing resource group. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "resourceGroupId" + type: "string" + required: true + description: "Resource Group identifier." + - name: "values" + type: "array" + required: false + description: "Resource Group values, e.g. name, scope." + default: "[]" +--- +:: + +```php [php] +$response = $client->iam()->resourceGroups()->update('ACCOUNT_ID', 'RESOURCE_GROUP_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-resource-group-update"} +View this operation on the Cloudflare API Reference +:: + +## Delete + +Remove a resource group from an account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "resourceGroupId" + type: "string" + required: true + description: "Resource Group identifier." +--- +:: + +```php [php] +$response = $client->iam()->resourceGroups()->delete('ACCOUNT_ID', 'RESOURCE_GROUP_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-resource-group-delete"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/21.iam/03.sso.md b/docs/content/2.client/21.iam/03.sso.md new file mode 100644 index 0000000..dc419ef --- /dev/null +++ b/docs/content/2.client/21.iam/03.sso.md @@ -0,0 +1,164 @@ +--- +title: Sso +description: "Sso endpoint reference." +navigation: + title: Sso +--- + +## List + +Lists all SSO connectors configured for the account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." +--- +:: + +```php [php] +$response = $client->iam()->sso()->list('ACCOUNT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/get-all-sso-connectors"} +View this operation on the Cloudflare API Reference +:: + +## Create + +Creates a new SSO connector for logging into Cloudflare through an identity provider. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "values" + type: "array" + required: true + description: "SSO Connector values, requires email_domain." +--- +:: + +```php [php] +$response = $client->iam()->sso()->create('ACCOUNT_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/init-new-sso-connector"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Get information about a specific SSO connector. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "ssoConnectorId" + type: "string" + required: true + description: "SSO Connector identifier." +--- +:: + +```php [php] +$response = $client->iam()->sso()->get('ACCOUNT_ID', 'SSO_CONNECTOR_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/get-sso-connector"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Updates the state or configuration of an SSO connector. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "ssoConnectorId" + type: "string" + required: true + description: "SSO Connector identifier." + - name: "values" + type: "array" + required: false + description: "SSO Connector values, e.g. enabled, use_fedramp_language." + default: "[]" +--- +:: + +```php [php] +$response = $client->iam()->sso()->update('ACCOUNT_ID', 'SSO_CONNECTOR_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/update-sso-connector-state"} +View this operation on the Cloudflare API Reference +:: + +## Delete + +Deletes an SSO connector. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "ssoConnectorId" + type: "string" + required: true + description: "SSO Connector identifier." +--- +:: + +```php [php] +$response = $client->iam()->sso()->delete('ACCOUNT_ID', 'SSO_CONNECTOR_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/delete-sso-connector"} +View this operation on the Cloudflare API Reference +:: + +## Begin Verification + +Begin the verification process for an SSO connector. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "ssoConnectorId" + type: "string" + required: true + description: "SSO Connector identifier." +--- +:: + +```php [php] +$response = $client->iam()->sso()->beginVerification('ACCOUNT_ID', 'SSO_CONNECTOR_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/begin-sso-connector-verification"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/21.iam/04.oauth-clients.md b/docs/content/2.client/21.iam/04.oauth-clients.md new file mode 100644 index 0000000..0a200d3 --- /dev/null +++ b/docs/content/2.client/21.iam/04.oauth-clients.md @@ -0,0 +1,190 @@ +--- +title: Oauth Clients +description: "Oauth Clients endpoint reference." +navigation: + title: Oauth Clients +--- + +## List + +List all the OAuth clients for an account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." +--- +:: + +```php [php] +$response = $client->iam()->oauthClients()->list('ACCOUNT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/oauth-clients-list"} +View this operation on the Cloudflare API Reference +:: + +## Create + +Create a new OAuth client. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "values" + type: "array" + required: true + description: "OAuth Client values, requires client_name, grant_types, redirect_uris, response_types, scopes and token_endpoint_auth_method." +--- +:: + +```php [php] +$response = $client->iam()->oauthClients()->create('ACCOUNT_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/oauth-clients-create"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Get details of a specific OAuth client. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "oauthClientId" + type: "string" + required: true + description: "OAuth Client identifier." +--- +:: + +```php [php] +$response = $client->iam()->oauthClients()->get('ACCOUNT_ID', 'OAUTH_CLIENT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/oauth-clients-get"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Update an existing OAuth client. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "oauthClientId" + type: "string" + required: true + description: "OAuth Client identifier." + - name: "values" + type: "array" + required: false + description: "OAuth Client values, e.g. client_name, grant_types, redirect_uris." + default: "[]" +--- +:: + +```php [php] +$response = $client->iam()->oauthClients()->update('ACCOUNT_ID', 'OAUTH_CLIENT_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/oauth-clients-update"} +View this operation on the Cloudflare API Reference +:: + +## Delete + +Delete an OAuth client. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "oauthClientId" + type: "string" + required: true + description: "OAuth Client identifier." +--- +:: + +```php [php] +$response = $client->iam()->oauthClients()->delete('ACCOUNT_ID', 'OAUTH_CLIENT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/oauth-clients-delete"} +View this operation on the Cloudflare API Reference +:: + +## Rotate Secret + +Creates a second client secret so you can update your client configuration before deleting the old one. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "oauthClientId" + type: "string" + required: true + description: "OAuth Client identifier." +--- +:: + +```php [php] +$response = $client->iam()->oauthClients()->rotateSecret('ACCOUNT_ID', 'OAUTH_CLIENT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/oauth-clients-rotate-secret"} +View this operation on the Cloudflare API Reference +:: + +## Delete Rotated Secret + +Removes the old client secret after a rotation, keeping only the new one. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "oauthClientId" + type: "string" + required: true + description: "OAuth Client identifier." +--- +:: + +```php [php] +$response = $client->iam()->oauthClients()->deleteRotatedSecret('ACCOUNT_ID', 'OAUTH_CLIENT_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/oauth-clients-delete-rotated-secret"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/21.iam/05.oauth-scopes.md b/docs/content/2.client/21.iam/05.oauth-scopes.md new file mode 100644 index 0000000..58f4c7c --- /dev/null +++ b/docs/content/2.client/21.iam/05.oauth-scopes.md @@ -0,0 +1,19 @@ +--- +title: Oauth Scopes +description: "Oauth Scopes endpoint reference." +navigation: + title: Oauth Scopes +--- + +## List + +List all available OAuth scopes. + +```php [php] +$response = $client->iam()->oauthScopes()->list(); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/oauth-scopes-list"} +View this operation on the Cloudflare API Reference +:: + diff --git a/docs/content/2.client/21.iam/06.user-groups/00.index.md b/docs/content/2.client/21.iam/06.user-groups/00.index.md new file mode 100644 index 0000000..e062034 --- /dev/null +++ b/docs/content/2.client/21.iam/06.user-groups/00.index.md @@ -0,0 +1,147 @@ +--- +title: User Groups +description: "User Groups endpoint reference." +navigation: + title: User Groups +--- + +## List + +List all the user groups for an account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params, e.g. id, name, fuzzyName." + default: "[]" +--- +:: + +```php [php] +$response = $client->iam()->userGroups()->list('ACCOUNT_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-user-group-list"} +View this operation on the Cloudflare API Reference +:: + +## Create + +Create a new user group under the specified account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "values" + type: "array" + required: true + description: "User Group values, requires name." +--- +:: + +```php [php] +$response = $client->iam()->userGroups()->create('ACCOUNT_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-user-group-create"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Get information about a specific user group in an account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "userGroupId" + type: "string" + required: true + description: "User Group identifier." +--- +:: + +```php [php] +$response = $client->iam()->userGroups()->get('ACCOUNT_ID', 'USER_GROUP_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-user-group-details"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Modify an existing user group. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "userGroupId" + type: "string" + required: true + description: "User Group identifier." + - name: "values" + type: "array" + required: false + description: "User Group values, e.g. name, policies." + default: "[]" +--- +:: + +```php [php] +$response = $client->iam()->userGroups()->update('ACCOUNT_ID', 'USER_GROUP_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-user-group-update"} +View this operation on the Cloudflare API Reference +:: + +## Delete + +Remove a user group from an account. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "userGroupId" + type: "string" + required: true + description: "User Group identifier." +--- +:: + +```php [php] +$response = $client->iam()->userGroups()->delete('ACCOUNT_ID', 'USER_GROUP_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-user-group-delete"} +View this operation on the Cloudflare API Reference +:: + +## Related + +- [Members](/client/iam/user-groups/members) + diff --git a/docs/content/2.client/21.iam/06.user-groups/01.members.md b/docs/content/2.client/21.iam/06.user-groups/01.members.md new file mode 100644 index 0000000..29ac126 --- /dev/null +++ b/docs/content/2.client/21.iam/06.user-groups/01.members.md @@ -0,0 +1,158 @@ +--- +title: Members +description: "Members endpoint reference." +navigation: + title: Members +--- + +## List + +List all the members attached to a user group. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "userGroupId" + type: "string" + required: true + description: "User Group identifier." + - name: "params" + type: "array" + required: false + description: "Array containing the necessary params, e.g. fuzzyEmail." + default: "[]" +--- +:: + +```php [php] +$response = $client->iam()->userGroups()->members()->list('ACCOUNT_ID', 'USER_GROUP_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-user-group-member-list"} +View this operation on the Cloudflare API Reference +:: + +## Create + +Add members to a User Group. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "userGroupId" + type: "string" + required: true + description: "User Group identifier." + - name: "members" + type: "array" + required: true + description: "Array of member identifiers to add, e.g. [['id' => 'member_id']]." +--- +:: + +```php [php] +$response = $client->iam()->userGroups()->members()->create('ACCOUNT_ID', 'USER_GROUP_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-user-group-member-create"} +View this operation on the Cloudflare API Reference +:: + +## Update + +Replace the set of members attached to a User Group. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "userGroupId" + type: "string" + required: true + description: "User Group identifier." + - name: "members" + type: "array" + required: true + description: "Array of member identifiers, e.g. [['id' => 'member_id']]." +--- +:: + +```php [php] +$response = $client->iam()->userGroups()->members()->update('ACCOUNT_ID', 'USER_GROUP_ID', []); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-user-group-members-update"} +View this operation on the Cloudflare API Reference +:: + +## Delete + +Remove a member from a User Group. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "userGroupId" + type: "string" + required: true + description: "User Group identifier." + - name: "memberId" + type: "string" + required: true + description: "Member identifier." +--- +:: + +```php [php] +$response = $client->iam()->userGroups()->members()->delete('ACCOUNT_ID', 'USER_GROUP_ID', 'MEMBER_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-user-group-member-delete"} +View this operation on the Cloudflare API Reference +:: + +## Get + +Get information about a specific member of a User Group. + +::params-table +--- +params: + - name: "accountId" + type: "string" + required: true + description: "Account identifier." + - name: "userGroupId" + type: "string" + required: true + description: "User Group identifier." + - name: "memberId" + type: "string" + required: true + description: "Member identifier." +--- +:: + +```php [php] +$response = $client->iam()->userGroups()->members()->get('ACCOUNT_ID', 'USER_GROUP_ID', 'MEMBER_ID'); +``` + +::callout{icon="i-simple-icons-cloudflare" to="https://developers.cloudflare.com/api/operations/account-user-group-member-get"} +View this operation on the Cloudflare API Reference +:: + diff --git a/src/Client.php b/src/Client.php index 4715b48..7724d2f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -31,6 +31,7 @@ * @method \Cloudflare\Endpoints\BotManagement botManagement() * @method \Cloudflare\Endpoints\CloudConnector cloudConnector() * @method \Cloudflare\Endpoints\R2 r2() + * @method \Cloudflare\Endpoints\Iam iam() * * @author Sergkei Melingk * @@ -96,6 +97,7 @@ public function api(string $name): AbstractEndpoint 'botManagement' => new Endpoints\BotManagement($this), 'cloudConnector' => new Endpoints\CloudConnector($this), 'r2' => new Endpoints\R2($this), + 'iam' => new Endpoints\Iam($this), default => throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)) }; diff --git a/src/Endpoints/Iam.php b/src/Endpoints/Iam.php new file mode 100644 index 0000000..1632302 --- /dev/null +++ b/src/Endpoints/Iam.php @@ -0,0 +1,76 @@ +getClient()); + } + + /** + * Account Resource Groups + * + * @return \Cloudflare\Endpoints\Iam\ResourceGroups + */ + public function resourceGroups(): ResourceGroups + { + return new ResourceGroups($this->getClient()); + } + + /** + * SSO Connectors + * + * @return \Cloudflare\Endpoints\Iam\Sso + */ + public function sso(): Sso + { + return new Sso($this->getClient()); + } + + /** + * OAuth Clients + * + * @return \Cloudflare\Endpoints\Iam\OauthClients + */ + public function oauthClients(): OauthClients + { + return new OauthClients($this->getClient()); + } + + /** + * OAuth Scopes + * + * @return \Cloudflare\Endpoints\Iam\OauthScopes + */ + public function oauthScopes(): OauthScopes + { + return new OauthScopes($this->getClient()); + } + + /** + * Account User Groups + * + * @return \Cloudflare\Endpoints\Iam\UserGroups + */ + public function userGroups(): UserGroups + { + return new UserGroups($this->getClient()); + } +} diff --git a/src/Endpoints/Iam/OauthClients.php b/src/Endpoints/Iam/OauthClients.php new file mode 100644 index 0000000..ba451ed --- /dev/null +++ b/src/Endpoints/Iam/OauthClients.php @@ -0,0 +1,123 @@ +getHttpClient()->get("/accounts/{$accountId}/oauth_clients"); + } + + /** + * Create a new OAuth client. + * + * @link https://developers.cloudflare.com/api/operations/oauth-clients-create + * + * @param string $accountId Account identifier. + * @param array $values OAuth Client values, requires client_name, grant_types, redirect_uris, response_types, scopes and token_endpoint_auth_method. + * + * @return ResponseInterface Create OAuth Client response. + */ + public function create(string $accountId, array $values): ResponseInterface + { + $this->requiredParams([ + 'client_name', + 'grant_types', + 'redirect_uris', + 'response_types', + 'scopes', + 'token_endpoint_auth_method', + ], $values); + + return $this->getHttpClient()->post("/accounts/{$accountId}/oauth_clients", $values); + } + + /** + * Get details of a specific OAuth client. + * + * @link https://developers.cloudflare.com/api/operations/oauth-clients-get + * + * @param string $accountId Account identifier. + * @param string $oauthClientId OAuth Client identifier. + * + * @return ResponseInterface OAuth Client Details response. + */ + public function get(string $accountId, string $oauthClientId): ResponseInterface + { + return $this->getHttpClient()->get("/accounts/{$accountId}/oauth_clients/{$oauthClientId}"); + } + + /** + * Update an existing OAuth client. + * + * @link https://developers.cloudflare.com/api/operations/oauth-clients-update + * + * @param string $accountId Account identifier. + * @param string $oauthClientId OAuth Client identifier. + * @param array $values OAuth Client values, e.g. client_name, grant_types, redirect_uris. + * + * @return ResponseInterface Update OAuth Client response. + */ + public function update(string $accountId, string $oauthClientId, array $values = []): ResponseInterface + { + return $this->getHttpClient()->patch("/accounts/{$accountId}/oauth_clients/{$oauthClientId}", $values); + } + + /** + * Delete an OAuth client. + * + * @link https://developers.cloudflare.com/api/operations/oauth-clients-delete + * + * @param string $accountId Account identifier. + * @param string $oauthClientId OAuth Client identifier. + * + * @return ResponseInterface Delete OAuth Client response. + */ + public function delete(string $accountId, string $oauthClientId): ResponseInterface + { + return $this->getHttpClient()->delete("/accounts/{$accountId}/oauth_clients/{$oauthClientId}"); + } + + /** + * Creates a second client secret so you can update your client configuration before deleting the old one. + * + * @link https://developers.cloudflare.com/api/operations/oauth-clients-rotate-secret + * + * @param string $accountId Account identifier. + * @param string $oauthClientId OAuth Client identifier. + * + * @return ResponseInterface Rotate Secret response. + */ + public function rotateSecret(string $accountId, string $oauthClientId): ResponseInterface + { + return $this->getHttpClient()->post("/accounts/{$accountId}/oauth_clients/{$oauthClientId}/rotate_secret", []); + } + + /** + * Removes the old client secret after a rotation, keeping only the new one. + * + * @link https://developers.cloudflare.com/api/operations/oauth-clients-delete-rotated-secret + * + * @param string $accountId Account identifier. + * @param string $oauthClientId OAuth Client identifier. + * + * @return ResponseInterface Delete Rotated Secret response. + */ + public function deleteRotatedSecret(string $accountId, string $oauthClientId): ResponseInterface + { + return $this->getHttpClient()->delete("/accounts/{$accountId}/oauth_clients/{$oauthClientId}/rotate_secret"); + } +} diff --git a/src/Endpoints/Iam/OauthScopes.php b/src/Endpoints/Iam/OauthScopes.php new file mode 100644 index 0000000..499dc93 --- /dev/null +++ b/src/Endpoints/Iam/OauthScopes.php @@ -0,0 +1,21 @@ +getHttpClient()->get('/oauth/scopes'); + } +} diff --git a/src/Endpoints/Iam/PermissionGroups.php b/src/Endpoints/Iam/PermissionGroups.php new file mode 100644 index 0000000..d31b853 --- /dev/null +++ b/src/Endpoints/Iam/PermissionGroups.php @@ -0,0 +1,39 @@ +getHttpClient()->get("/accounts/{$accountId}/iam/permission_groups", $params); + } + + /** + * Get information about a specific permission group in an account. + * + * @link https://developers.cloudflare.com/api/operations/account-permission-group-details + * + * @param string $accountId Account identifier. + * @param string $permissionGroupId Permission Group identifier. + * + * @return ResponseInterface Permission Group Details response. + */ + public function get(string $accountId, string $permissionGroupId): ResponseInterface + { + return $this->getHttpClient()->get("/accounts/{$accountId}/iam/permission_groups/{$permissionGroupId}"); + } +} diff --git a/src/Endpoints/Iam/ResourceGroups.php b/src/Endpoints/Iam/ResourceGroups.php new file mode 100644 index 0000000..1ec970c --- /dev/null +++ b/src/Endpoints/Iam/ResourceGroups.php @@ -0,0 +1,87 @@ +getHttpClient()->get("/accounts/{$accountId}/iam/resource_groups", $params); + } + + /** + * Create a new Resource Group under the specified account. + * + * @link https://developers.cloudflare.com/api/operations/account-resource-group-create + * + * @param string $accountId Account identifier. + * @param array $values Resource Group values, requires name and scope. + * + * @return ResponseInterface Create Resource Group response. + */ + public function create(string $accountId, array $values): ResponseInterface + { + $this->requiredParams(['name', 'scope'], $values); + + return $this->getHttpClient()->post("/accounts/{$accountId}/iam/resource_groups", $values); + } + + /** + * Get information about a specific resource group in an account. + * + * @link https://developers.cloudflare.com/api/operations/account-resource-group-details + * + * @param string $accountId Account identifier. + * @param string $resourceGroupId Resource Group identifier. + * + * @return ResponseInterface Resource Group Details response. + */ + public function get(string $accountId, string $resourceGroupId): ResponseInterface + { + return $this->getHttpClient()->get("/accounts/{$accountId}/iam/resource_groups/{$resourceGroupId}"); + } + + /** + * Modify an existing resource group. + * + * @link https://developers.cloudflare.com/api/operations/account-resource-group-update + * + * @param string $accountId Account identifier. + * @param string $resourceGroupId Resource Group identifier. + * @param array $values Resource Group values, e.g. name, scope. + * + * @return ResponseInterface Update Resource Group response. + */ + public function update(string $accountId, string $resourceGroupId, array $values = []): ResponseInterface + { + return $this->getHttpClient()->put("/accounts/{$accountId}/iam/resource_groups/{$resourceGroupId}", $values); + } + + /** + * Remove a resource group from an account. + * + * @link https://developers.cloudflare.com/api/operations/account-resource-group-delete + * + * @param string $accountId Account identifier. + * @param string $resourceGroupId Resource Group identifier. + * + * @return ResponseInterface Delete Resource Group response. + */ + public function delete(string $accountId, string $resourceGroupId): ResponseInterface + { + return $this->getHttpClient()->delete("/accounts/{$accountId}/iam/resource_groups/{$resourceGroupId}"); + } +} diff --git a/src/Endpoints/Iam/Sso.php b/src/Endpoints/Iam/Sso.php new file mode 100644 index 0000000..1064a53 --- /dev/null +++ b/src/Endpoints/Iam/Sso.php @@ -0,0 +1,101 @@ +getHttpClient()->get("/accounts/{$accountId}/sso_connectors"); + } + + /** + * Creates a new SSO connector for logging into Cloudflare through an identity provider. + * + * @link https://developers.cloudflare.com/api/operations/init-new-sso-connector + * + * @param string $accountId Account identifier. + * @param array $values SSO Connector values, requires email_domain. + * + * @return ResponseInterface Create SSO Connector response. + */ + public function create(string $accountId, array $values): ResponseInterface + { + $this->requiredParams(['email_domain'], $values); + + return $this->getHttpClient()->post("/accounts/{$accountId}/sso_connectors", $values); + } + + /** + * Get information about a specific SSO connector. + * + * @link https://developers.cloudflare.com/api/operations/get-sso-connector + * + * @param string $accountId Account identifier. + * @param string $ssoConnectorId SSO Connector identifier. + * + * @return ResponseInterface SSO Connector Details response. + */ + public function get(string $accountId, string $ssoConnectorId): ResponseInterface + { + return $this->getHttpClient()->get("/accounts/{$accountId}/sso_connectors/{$ssoConnectorId}"); + } + + /** + * Updates the state or configuration of an SSO connector. + * + * @link https://developers.cloudflare.com/api/operations/update-sso-connector-state + * + * @param string $accountId Account identifier. + * @param string $ssoConnectorId SSO Connector identifier. + * @param array $values SSO Connector values, e.g. enabled, use_fedramp_language. + * + * @return ResponseInterface Update SSO Connector response. + */ + public function update(string $accountId, string $ssoConnectorId, array $values = []): ResponseInterface + { + return $this->getHttpClient()->patch("/accounts/{$accountId}/sso_connectors/{$ssoConnectorId}", $values); + } + + /** + * Deletes an SSO connector. + * + * @link https://developers.cloudflare.com/api/operations/delete-sso-connector + * + * @param string $accountId Account identifier. + * @param string $ssoConnectorId SSO Connector identifier. + * + * @return ResponseInterface Delete SSO Connector response. + */ + public function delete(string $accountId, string $ssoConnectorId): ResponseInterface + { + return $this->getHttpClient()->delete("/accounts/{$accountId}/sso_connectors/{$ssoConnectorId}"); + } + + /** + * Begin the verification process for an SSO connector. + * + * @link https://developers.cloudflare.com/api/operations/begin-sso-connector-verification + * + * @param string $accountId Account identifier. + * @param string $ssoConnectorId SSO Connector identifier. + * + * @return ResponseInterface Begin Verification response. + */ + public function beginVerification(string $accountId, string $ssoConnectorId): ResponseInterface + { + return $this->getHttpClient()->post("/accounts/{$accountId}/sso_connectors/{$ssoConnectorId}/begin_verification", []); + } +} diff --git a/src/Endpoints/Iam/UserGroups.php b/src/Endpoints/Iam/UserGroups.php new file mode 100644 index 0000000..d0964ed --- /dev/null +++ b/src/Endpoints/Iam/UserGroups.php @@ -0,0 +1,98 @@ +getHttpClient()->get("/accounts/{$accountId}/iam/user_groups", $params); + } + + /** + * Create a new user group under the specified account. + * + * @link https://developers.cloudflare.com/api/operations/account-user-group-create + * + * @param string $accountId Account identifier. + * @param array $values User Group values, requires name. + * + * @return ResponseInterface Create User Group response. + */ + public function create(string $accountId, array $values): ResponseInterface + { + $this->requiredParams(['name'], $values); + + return $this->getHttpClient()->post("/accounts/{$accountId}/iam/user_groups", $values); + } + + /** + * Get information about a specific user group in an account. + * + * @link https://developers.cloudflare.com/api/operations/account-user-group-details + * + * @param string $accountId Account identifier. + * @param string $userGroupId User Group identifier. + * + * @return ResponseInterface User Group Details response. + */ + public function get(string $accountId, string $userGroupId): ResponseInterface + { + return $this->getHttpClient()->get("/accounts/{$accountId}/iam/user_groups/{$userGroupId}"); + } + + /** + * Modify an existing user group. + * + * @link https://developers.cloudflare.com/api/operations/account-user-group-update + * + * @param string $accountId Account identifier. + * @param string $userGroupId User Group identifier. + * @param array $values User Group values, e.g. name, policies. + * + * @return ResponseInterface Update User Group response. + */ + public function update(string $accountId, string $userGroupId, array $values = []): ResponseInterface + { + return $this->getHttpClient()->put("/accounts/{$accountId}/iam/user_groups/{$userGroupId}", $values); + } + + /** + * Remove a user group from an account. + * + * @link https://developers.cloudflare.com/api/operations/account-user-group-delete + * + * @param string $accountId Account identifier. + * @param string $userGroupId User Group identifier. + * + * @return ResponseInterface Delete User Group response. + */ + public function delete(string $accountId, string $userGroupId): ResponseInterface + { + return $this->getHttpClient()->delete("/accounts/{$accountId}/iam/user_groups/{$userGroupId}"); + } + + /** + * Account User Group Members + * + * @return \Cloudflare\Endpoints\Iam\UserGroups\Members + */ + public function members(): Members + { + return new Members($this->getClient()); + } +} diff --git a/src/Endpoints/Iam/UserGroups/Members.php b/src/Endpoints/Iam/UserGroups/Members.php new file mode 100644 index 0000000..9170f6f --- /dev/null +++ b/src/Endpoints/Iam/UserGroups/Members.php @@ -0,0 +1,89 @@ +getHttpClient()->get("/accounts/{$accountId}/iam/user_groups/{$userGroupId}/members", $params); + } + + /** + * Add members to a User Group. + * + * @link https://developers.cloudflare.com/api/operations/account-user-group-member-create + * + * @param string $accountId Account identifier. + * @param string $userGroupId User Group identifier. + * @param array $members Array of member identifiers to add, e.g. [['id' => 'member_id']]. + * + * @return ResponseInterface Add Members response. + */ + public function create(string $accountId, string $userGroupId, array $members): ResponseInterface + { + return $this->getHttpClient()->post("/accounts/{$accountId}/iam/user_groups/{$userGroupId}/members", $members); + } + + /** + * Replace the set of members attached to a User Group. + * + * @link https://developers.cloudflare.com/api/operations/account-user-group-members-update + * + * @param string $accountId Account identifier. + * @param string $userGroupId User Group identifier. + * @param array $members Array of member identifiers, e.g. [['id' => 'member_id']]. + * + * @return ResponseInterface Replace Members response. + */ + public function update(string $accountId, string $userGroupId, array $members): ResponseInterface + { + return $this->getHttpClient()->put("/accounts/{$accountId}/iam/user_groups/{$userGroupId}/members", $members); + } + + /** + * Remove a member from a User Group. + * + * @link https://developers.cloudflare.com/api/operations/account-user-group-member-delete + * + * @param string $accountId Account identifier. + * @param string $userGroupId User Group identifier. + * @param string $memberId Member identifier. + * + * @return ResponseInterface Remove Member response. + */ + public function delete(string $accountId, string $userGroupId, string $memberId): ResponseInterface + { + return $this->getHttpClient()->delete("/accounts/{$accountId}/iam/user_groups/{$userGroupId}/members/{$memberId}"); + } + + /** + * Get information about a specific member of a User Group. + * + * @link https://developers.cloudflare.com/api/operations/account-user-group-member-get + * + * @param string $accountId Account identifier. + * @param string $userGroupId User Group identifier. + * @param string $memberId Member identifier. + * + * @return ResponseInterface Member Details response. + */ + public function get(string $accountId, string $userGroupId, string $memberId): ResponseInterface + { + return $this->getHttpClient()->get("/accounts/{$accountId}/iam/user_groups/{$userGroupId}/members/{$memberId}"); + } +} diff --git a/test/Tests/Endpoints/Iam/OauthClientsTest.php b/test/Tests/Endpoints/Iam/OauthClientsTest.php new file mode 100644 index 0000000..15ce68d --- /dev/null +++ b/test/Tests/Endpoints/Iam/OauthClientsTest.php @@ -0,0 +1,133 @@ + 'My OAuth App', + 'grant_types' => ['authorization_code'], + 'redirect_uris' => ['https://example.com/callback'], + 'response_types' => ['code'], + 'scopes' => ['account:read'], + 'token_endpoint_auth_method' => 'client_secret_post', + ]; + } + + #[Test] + public function shouldList() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'oauth_client_id']]])), + ]); + + $response = $client->iam()->oauthClients()->list('account_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/oauth_clients', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldCreate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'oauth_client_id']])), + ]); + + $response = $client->iam()->oauthClients()->create('account_id', $this->validValues()); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/oauth_clients', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldThrowExceptionWhenCreateParamsAreMissing() + { + $client = $this->mockClient([]); + + $this->expectException(\Cloudflare\Exceptions\MissingArgumentException::class); + + $client->iam()->oauthClients()->create('account_id', ['client_name' => 'My OAuth App']); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'oauth_client_id']])), + ]); + + $response = $client->iam()->oauthClients()->get('account_id', 'oauth_client_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/oauth_clients/oauth_client_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'oauth_client_id']])), + ]); + + $response = $client->iam()->oauthClients()->update('account_id', 'oauth_client_id', ['client_name' => 'Renamed App']); + + $this->assertTrue($response->successful()); + $this->assertSame('PATCH', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/oauth_clients/oauth_client_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldDelete() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'oauth_client_id']])), + ]); + + $response = $client->iam()->oauthClients()->delete('account_id', 'oauth_client_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/oauth_clients/oauth_client_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldRotateSecret() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'oauth_client_id']])), + ]); + + $response = $client->iam()->oauthClients()->rotateSecret('account_id', 'oauth_client_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/oauth_clients/oauth_client_id/rotate_secret', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldDeleteRotatedSecret() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'oauth_client_id']])), + ]); + + $response = $client->iam()->oauthClients()->deleteRotatedSecret('account_id', 'oauth_client_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/oauth_clients/oauth_client_id/rotate_secret', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Iam/OauthScopesTest.php b/test/Tests/Endpoints/Iam/OauthScopesTest.php new file mode 100644 index 0000000..27fe083 --- /dev/null +++ b/test/Tests/Endpoints/Iam/OauthScopesTest.php @@ -0,0 +1,27 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['scope' => 'account:read']]])), + ]); + + $response = $client->iam()->oauthScopes()->list(); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/oauth/scopes', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Iam/PermissionGroupsTest.php b/test/Tests/Endpoints/Iam/PermissionGroupsTest.php new file mode 100644 index 0000000..7b89ed0 --- /dev/null +++ b/test/Tests/Endpoints/Iam/PermissionGroupsTest.php @@ -0,0 +1,41 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'permission_group_id']]])), + ]); + + $response = $client->iam()->permissionGroups()->list('account_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/permission_groups', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'permission_group_id']])), + ]); + + $response = $client->iam()->permissionGroups()->get('account_id', 'permission_group_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/permission_groups/permission_group_id', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Iam/ResourceGroupsTest.php b/test/Tests/Endpoints/Iam/ResourceGroupsTest.php new file mode 100644 index 0000000..252d293 --- /dev/null +++ b/test/Tests/Endpoints/Iam/ResourceGroupsTest.php @@ -0,0 +1,96 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'resource_group_id']]])), + ]); + + $response = $client->iam()->resourceGroups()->list('account_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/resource_groups', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldCreate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'resource_group_id']])), + ]); + + $response = $client->iam()->resourceGroups()->create('account_id', [ + 'name' => 'my resource group', + 'scope' => ['key' => 'com.cloudflare.api.account.account_id', 'objects' => [['key' => '*']]], + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/resource_groups', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldThrowExceptionWhenCreateParamsAreMissing() + { + $client = $this->mockClient([]); + + $this->expectException(\Cloudflare\Exceptions\MissingArgumentException::class); + + $client->iam()->resourceGroups()->create('account_id', ['name' => 'my resource group']); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'resource_group_id']])), + ]); + + $response = $client->iam()->resourceGroups()->get('account_id', 'resource_group_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/resource_groups/resource_group_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'resource_group_id']])), + ]); + + $response = $client->iam()->resourceGroups()->update('account_id', 'resource_group_id', ['name' => 'renamed']); + + $this->assertTrue($response->successful()); + $this->assertSame('PUT', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/resource_groups/resource_group_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldDelete() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'resource_group_id']])), + ]); + + $response = $client->iam()->resourceGroups()->delete('account_id', 'resource_group_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/resource_groups/resource_group_id', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Iam/SsoTest.php b/test/Tests/Endpoints/Iam/SsoTest.php new file mode 100644 index 0000000..bbfd9e0 --- /dev/null +++ b/test/Tests/Endpoints/Iam/SsoTest.php @@ -0,0 +1,107 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'sso_connector_id']]])), + ]); + + $response = $client->iam()->sso()->list('account_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/sso_connectors', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldCreate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'sso_connector_id']])), + ]); + + $response = $client->iam()->sso()->create('account_id', ['email_domain' => 'example.com']); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/sso_connectors', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldThrowExceptionWhenCreateParamsAreMissing() + { + $client = $this->mockClient([]); + + $this->expectException(\Cloudflare\Exceptions\MissingArgumentException::class); + + $client->iam()->sso()->create('account_id', []); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'sso_connector_id']])), + ]); + + $response = $client->iam()->sso()->get('account_id', 'sso_connector_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/sso_connectors/sso_connector_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'sso_connector_id']])), + ]); + + $response = $client->iam()->sso()->update('account_id', 'sso_connector_id', ['enabled' => true]); + + $this->assertTrue($response->successful()); + $this->assertSame('PATCH', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/sso_connectors/sso_connector_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldDelete() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'sso_connector_id']])), + ]); + + $response = $client->iam()->sso()->delete('account_id', 'sso_connector_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/sso_connectors/sso_connector_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldBeginVerification() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'sso_connector_id']])), + ]); + + $response = $client->iam()->sso()->beginVerification('account_id', 'sso_connector_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/sso_connectors/sso_connector_id/begin_verification', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Iam/UserGroups/MembersTest.php b/test/Tests/Endpoints/Iam/UserGroups/MembersTest.php new file mode 100644 index 0000000..acf4723 --- /dev/null +++ b/test/Tests/Endpoints/Iam/UserGroups/MembersTest.php @@ -0,0 +1,89 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'member_id']]])), + ]); + + $response = $client->iam()->userGroups()->members()->list('account_id', 'user_group_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/user_groups/user_group_id/members', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldCreate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'member_id']]])), + ]); + + $response = $client->iam()->userGroups()->members()->create('account_id', 'user_group_id', [ + ['id' => 'member_id'], + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/user_groups/user_group_id/members', $this->lastRequest()->getUri()->getPath()); + $this->assertSame([['id' => 'member_id']], json_decode((string) $this->lastRequest()->getBody(), true)); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'member_id']]])), + ]); + + $response = $client->iam()->userGroups()->members()->update('account_id', 'user_group_id', [ + ['id' => 'member_id'], + ]); + + $this->assertTrue($response->successful()); + $this->assertSame('PUT', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/user_groups/user_group_id/members', $this->lastRequest()->getUri()->getPath()); + $this->assertSame([['id' => 'member_id']], json_decode((string) $this->lastRequest()->getBody(), true)); + } + + #[Test] + public function shouldDelete() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'member_id']])), + ]); + + $response = $client->iam()->userGroups()->members()->delete('account_id', 'user_group_id', 'member_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/user_groups/user_group_id/members/member_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'member_id']])), + ]); + + $response = $client->iam()->userGroups()->members()->get('account_id', 'user_group_id', 'member_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/user_groups/user_group_id/members/member_id', $this->lastRequest()->getUri()->getPath()); + } +} diff --git a/test/Tests/Endpoints/Iam/UserGroupsTest.php b/test/Tests/Endpoints/Iam/UserGroupsTest.php new file mode 100644 index 0000000..a5b7ff1 --- /dev/null +++ b/test/Tests/Endpoints/Iam/UserGroupsTest.php @@ -0,0 +1,93 @@ +mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => [['id' => 'user_group_id']]])), + ]); + + $response = $client->iam()->userGroups()->list('account_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/user_groups', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldCreate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'user_group_id']])), + ]); + + $response = $client->iam()->userGroups()->create('account_id', ['name' => 'My New User Group']); + + $this->assertTrue($response->successful()); + $this->assertSame('POST', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/user_groups', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldThrowExceptionWhenCreateParamsAreMissing() + { + $client = $this->mockClient([]); + + $this->expectException(\Cloudflare\Exceptions\MissingArgumentException::class); + + $client->iam()->userGroups()->create('account_id', []); + } + + #[Test] + public function shouldGetDetails() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'user_group_id']])), + ]); + + $response = $client->iam()->userGroups()->get('account_id', 'user_group_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('GET', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/user_groups/user_group_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldUpdate() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'user_group_id']])), + ]); + + $response = $client->iam()->userGroups()->update('account_id', 'user_group_id', ['name' => 'Renamed']); + + $this->assertTrue($response->successful()); + $this->assertSame('PUT', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/user_groups/user_group_id', $this->lastRequest()->getUri()->getPath()); + } + + #[Test] + public function shouldDelete() + { + $client = $this->mockClient([ + new Response(200, [], json_encode(['success' => true, 'result' => ['id' => 'user_group_id']])), + ]); + + $response = $client->iam()->userGroups()->delete('account_id', 'user_group_id'); + + $this->assertTrue($response->successful()); + $this->assertSame('DELETE', $this->lastRequest()->getMethod()); + $this->assertSame('/client/v4/accounts/account_id/iam/user_groups/user_group_id', $this->lastRequest()->getUri()->getPath()); + } +}