From c7ab9945e6e060048f777ca3c0d863f1e6a29913 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 7 May 2026 08:42:53 +0000 Subject: [PATCH 1/7] feat: Go SDK update for version v3.1.0 --- CHANGELOG.md | 6 + README.md | 4 +- appwrite/appwrite.go | 22 + client/client.go | 6 +- databases/databases.go | 186 + databases/databases_test.go | 64 + .../databases/create-big-int-attribute.md | 28 + .../databases/update-big-int-attribute.md | 28 + docs/examples/functions/create-variable.md | 1 + docs/examples/functions/list-variables.md | 2 + docs/examples/functions/update-variable.md | 2 +- docs/examples/project/create-ephemeral-key.md | 22 + docs/examples/project/create-mock-phone.md | 22 + docs/examples/project/create-smtp-test.md | 21 + docs/examples/project/delete-mock-phone.md | 21 + docs/examples/project/delete.md | 19 + docs/examples/project/get-email-template.md | 22 + docs/examples/project/get-mock-phone.md | 21 + .../examples/project/get-o-auth-2-provider.md | 21 + docs/examples/project/get-policy.md | 21 + docs/examples/project/list-email-templates.md | 22 + docs/examples/project/list-mock-phones.md | 22 + .../project/list-o-auth-2-providers.md | 22 + docs/examples/project/list-policies.md | 22 + docs/examples/project/update-auth-method.md | 22 + .../examples/project/update-email-template.md | 28 + .../update-membership-privacy-policy.md | 25 + docs/examples/project/update-mock-phone.md | 22 + .../project/update-o-auth-2-amazon.md | 23 + .../examples/project/update-o-auth-2-apple.md | 25 + .../project/update-o-auth-2-auth-0.md | 24 + .../project/update-o-auth-2-authentik.md | 24 + .../project/update-o-auth-2-autodesk.md | 23 + .../project/update-o-auth-2-bitbucket.md | 23 + .../examples/project/update-o-auth-2-bitly.md | 23 + docs/examples/project/update-o-auth-2-box.md | 23 + .../project/update-o-auth-2-dailymotion.md | 23 + .../project/update-o-auth-2-discord.md | 23 + .../project/update-o-auth-2-disqus.md | 23 + .../project/update-o-auth-2-dropbox.md | 23 + docs/examples/project/update-o-auth-2-etsy.md | 23 + .../project/update-o-auth-2-facebook.md | 23 + .../examples/project/update-o-auth-2-figma.md | 23 + .../project/update-o-auth-2-fusion-auth.md | 24 + .../project/update-o-auth-2-git-hub.md | 23 + .../project/update-o-auth-2-gitlab.md | 24 + .../project/update-o-auth-2-google.md | 23 + .../project/update-o-auth-2-keycloak.md | 25 + docs/examples/project/update-o-auth-2-kick.md | 23 + .../project/update-o-auth-2-linkedin.md | 23 + .../project/update-o-auth-2-microsoft.md | 24 + .../project/update-o-auth-2-notion.md | 23 + docs/examples/project/update-o-auth-2-oidc.md | 27 + docs/examples/project/update-o-auth-2-okta.md | 25 + .../project/update-o-auth-2-paypal-sandbox.md | 23 + .../project/update-o-auth-2-paypal.md | 23 + .../examples/project/update-o-auth-2-podio.md | 23 + .../project/update-o-auth-2-salesforce.md | 23 + .../examples/project/update-o-auth-2-slack.md | 23 + .../project/update-o-auth-2-spotify.md | 23 + .../project/update-o-auth-2-stripe.md | 23 + .../update-o-auth-2-tradeshift-sandbox.md | 23 + .../project/update-o-auth-2-tradeshift.md | 23 + .../project/update-o-auth-2-twitch.md | 23 + .../project/update-o-auth-2-word-press.md | 23 + .../examples/project/update-o-auth-2-yahoo.md | 23 + .../project/update-o-auth-2-yandex.md | 23 + docs/examples/project/update-o-auth-2-zoho.md | 23 + docs/examples/project/update-o-auth-2-zoom.md | 23 + docs/examples/project/update-o-auth-2x.md | 23 + .../update-password-dictionary-policy.md | 21 + .../project/update-password-history-policy.md | 21 + .../update-password-personal-data-policy.md | 21 + ...-protocol-status.md => update-protocol.md} | 2 +- ...te-service-status.md => update-service.md} | 2 +- .../project/update-session-alert-policy.md | 21 + .../project/update-session-duration-policy.md | 21 + .../update-session-invalidation-policy.md | 21 + .../project/update-session-limit-policy.md | 21 + docs/examples/project/update-smtp.md | 30 + .../project/update-user-limit-policy.md | 21 + docs/examples/proxy/create-api-rule.md | 21 + docs/examples/proxy/create-function-rule.md | 23 + docs/examples/proxy/create-redirect-rule.md | 25 + docs/examples/proxy/create-site-rule.md | 23 + docs/examples/proxy/delete-rule.md | 21 + docs/examples/proxy/get-rule.md | 21 + docs/examples/proxy/list-rules.md | 22 + docs/examples/proxy/update-rule-status.md | 21 + docs/examples/sites/create-variable.md | 1 + docs/examples/sites/list-variables.md | 2 + docs/examples/sites/update-variable.md | 2 +- .../tablesdb/create-big-int-column.md | 28 + .../tablesdb/update-big-int-column.md | 28 + functions/functions.go | 60 +- functions/functions_test.go | 4 +- models/attributeBigint.go | 56 + models/attributeBigint_test.go | 41 + models/authProvider.go | 2 +- models/authProvider_test.go | 2 +- models/block.go | 10 + models/block_test.go | 17 +- models/columnBigint.go | 56 + models/columnBigint_test.go | 41 + models/emailTemplate.go | 47 + models/emailTemplateList.go | 35 + models/emailTemplateList_test.go | 24 + models/emailTemplate_test.go | 44 + models/ephemeralKey.go | 50 + models/ephemeralKey_test.go | 41 + models/membership.go | 3 + models/membershipList_test.go | 2 +- models/membership_test.go | 5 +- models/mockNumber.go | 6 +- models/mockNumberList.go | 35 + models/mockNumberList_test.go | 24 + models/mockNumber_test.go | 12 +- models/oAuth2Amazon.go | 39 + models/oAuth2Amazon_test.go | 32 + models/oAuth2Apple.go | 44 + models/oAuth2Apple_test.go | 38 + models/oAuth2Auth0.go | 41 + models/oAuth2Auth0_test.go | 35 + models/oAuth2Authentik.go | 41 + models/oAuth2Authentik_test.go | 35 + models/oAuth2Autodesk.go | 39 + models/oAuth2Autodesk_test.go | 32 + models/oAuth2Bitbucket.go | 39 + models/oAuth2Bitbucket_test.go | 32 + models/oAuth2Bitly.go | 39 + models/oAuth2Bitly_test.go | 32 + models/oAuth2Box.go | 39 + models/oAuth2Box_test.go | 32 + models/oAuth2Dailymotion.go | 39 + models/oAuth2Dailymotion_test.go | 32 + models/oAuth2Discord.go | 39 + models/oAuth2Discord_test.go | 32 + models/oAuth2Disqus.go | 39 + models/oAuth2Disqus_test.go | 32 + models/oAuth2Dropbox.go | 39 + models/oAuth2Dropbox_test.go | 32 + models/oAuth2Etsy.go | 39 + models/oAuth2Etsy_test.go | 32 + models/oAuth2Facebook.go | 39 + models/oAuth2Facebook_test.go | 32 + models/oAuth2Figma.go | 39 + models/oAuth2Figma_test.go | 32 + models/oAuth2FusionAuth.go | 41 + models/oAuth2FusionAuth_test.go | 35 + models/oAuth2Github.go | 40 + models/oAuth2Github_test.go | 32 + models/oAuth2Gitlab.go | 42 + models/oAuth2Gitlab_test.go | 35 + models/oAuth2Google.go | 39 + models/oAuth2Google_test.go | 32 + models/oAuth2Keycloak.go | 43 + models/oAuth2Keycloak_test.go | 38 + models/oAuth2Kick.go | 39 + models/oAuth2Kick_test.go | 32 + models/oAuth2Linkedin.go | 39 + models/oAuth2Linkedin_test.go | 32 + models/oAuth2Microsoft.go | 42 + models/oAuth2Microsoft_test.go | 35 + models/oAuth2Notion.go | 39 + models/oAuth2Notion_test.go | 32 + models/oAuth2Oidc.go | 48 + models/oAuth2Oidc_test.go | 44 + models/oAuth2Okta.go | 43 + models/oAuth2Okta_test.go | 38 + models/oAuth2Paypal.go | 39 + models/oAuth2Paypal_test.go | 32 + models/oAuth2Podio.go | 39 + models/oAuth2Podio_test.go | 32 + models/oAuth2ProviderList.go | 35 + models/oAuth2ProviderList_test.go | 23 + models/oAuth2Salesforce.go | 39 + models/oAuth2Salesforce_test.go | 32 + models/oAuth2Slack.go | 39 + models/oAuth2Slack_test.go | 32 + models/oAuth2Spotify.go | 39 + models/oAuth2Spotify_test.go | 32 + models/oAuth2Stripe.go | 39 + models/oAuth2Stripe_test.go | 32 + models/oAuth2Tradeshift.go | 39 + models/oAuth2Tradeshift_test.go | 32 + models/oAuth2Twitch.go | 39 + models/oAuth2Twitch_test.go | 32 + models/oAuth2WordPress.go | 39 + models/oAuth2WordPress_test.go | 32 + models/oAuth2X.go | 39 + models/oAuth2X_test.go | 32 + models/oAuth2Yahoo.go | 39 + models/oAuth2Yahoo_test.go | 32 + models/oAuth2Yandex.go | 39 + models/oAuth2Yandex_test.go | 32 + models/oAuth2Zoho.go | 39 + models/oAuth2Zoho_test.go | 32 + models/oAuth2Zoom.go | 39 + models/oAuth2Zoom_test.go | 32 + models/policyList.go | 35 + models/policyList_test.go | 23 + models/policyMembershipPrivacy.go | 43 + models/policyMembershipPrivacy_test.go | 38 + models/policyPasswordDictionary.go | 35 + models/policyPasswordDictionary_test.go | 26 + models/policyPasswordHistory.go | 35 + models/policyPasswordHistory_test.go | 26 + models/policyPasswordPersonalData.go | 35 + models/policyPasswordPersonalData_test.go | 26 + models/policySessionAlert.go | 35 + models/policySessionAlert_test.go | 26 + models/policySessionDuration.go | 35 + models/policySessionDuration_test.go | 26 + models/policySessionInvalidation.go | 35 + models/policySessionInvalidation_test.go | 26 + models/policySessionLimit.go | 36 + models/policySessionLimit_test.go | 26 + models/policyUserLimit.go | 36 + models/policyUserLimit_test.go | 26 + models/project.go | 11 +- models/project_test.go | 19 +- models/proxyRule.go | 67 + models/proxyRuleList.go | 35 + models/proxyRuleList_test.go | 24 + models/proxyRule_test.go | 62 + project/project.go | 5766 ++++++++++++++++- project/project_test.go | 4001 +++++++++++- proxy/proxy.go | 401 ++ proxy/proxy_test.go | 322 + sites/sites.go | 60 +- sites/sites_test.go | 4 +- tablesdb/tables_db.go | 182 + tablesdb/tables_db_test.go | 64 + teams/teams_test.go | 5 + users/users_test.go | 1 + 235 files changed, 16942 insertions(+), 451 deletions(-) create mode 100644 docs/examples/databases/create-big-int-attribute.md create mode 100644 docs/examples/databases/update-big-int-attribute.md create mode 100644 docs/examples/project/create-ephemeral-key.md create mode 100644 docs/examples/project/create-mock-phone.md create mode 100644 docs/examples/project/create-smtp-test.md create mode 100644 docs/examples/project/delete-mock-phone.md create mode 100644 docs/examples/project/delete.md create mode 100644 docs/examples/project/get-email-template.md create mode 100644 docs/examples/project/get-mock-phone.md create mode 100644 docs/examples/project/get-o-auth-2-provider.md create mode 100644 docs/examples/project/get-policy.md create mode 100644 docs/examples/project/list-email-templates.md create mode 100644 docs/examples/project/list-mock-phones.md create mode 100644 docs/examples/project/list-o-auth-2-providers.md create mode 100644 docs/examples/project/list-policies.md create mode 100644 docs/examples/project/update-auth-method.md create mode 100644 docs/examples/project/update-email-template.md create mode 100644 docs/examples/project/update-membership-privacy-policy.md create mode 100644 docs/examples/project/update-mock-phone.md create mode 100644 docs/examples/project/update-o-auth-2-amazon.md create mode 100644 docs/examples/project/update-o-auth-2-apple.md create mode 100644 docs/examples/project/update-o-auth-2-auth-0.md create mode 100644 docs/examples/project/update-o-auth-2-authentik.md create mode 100644 docs/examples/project/update-o-auth-2-autodesk.md create mode 100644 docs/examples/project/update-o-auth-2-bitbucket.md create mode 100644 docs/examples/project/update-o-auth-2-bitly.md create mode 100644 docs/examples/project/update-o-auth-2-box.md create mode 100644 docs/examples/project/update-o-auth-2-dailymotion.md create mode 100644 docs/examples/project/update-o-auth-2-discord.md create mode 100644 docs/examples/project/update-o-auth-2-disqus.md create mode 100644 docs/examples/project/update-o-auth-2-dropbox.md create mode 100644 docs/examples/project/update-o-auth-2-etsy.md create mode 100644 docs/examples/project/update-o-auth-2-facebook.md create mode 100644 docs/examples/project/update-o-auth-2-figma.md create mode 100644 docs/examples/project/update-o-auth-2-fusion-auth.md create mode 100644 docs/examples/project/update-o-auth-2-git-hub.md create mode 100644 docs/examples/project/update-o-auth-2-gitlab.md create mode 100644 docs/examples/project/update-o-auth-2-google.md create mode 100644 docs/examples/project/update-o-auth-2-keycloak.md create mode 100644 docs/examples/project/update-o-auth-2-kick.md create mode 100644 docs/examples/project/update-o-auth-2-linkedin.md create mode 100644 docs/examples/project/update-o-auth-2-microsoft.md create mode 100644 docs/examples/project/update-o-auth-2-notion.md create mode 100644 docs/examples/project/update-o-auth-2-oidc.md create mode 100644 docs/examples/project/update-o-auth-2-okta.md create mode 100644 docs/examples/project/update-o-auth-2-paypal-sandbox.md create mode 100644 docs/examples/project/update-o-auth-2-paypal.md create mode 100644 docs/examples/project/update-o-auth-2-podio.md create mode 100644 docs/examples/project/update-o-auth-2-salesforce.md create mode 100644 docs/examples/project/update-o-auth-2-slack.md create mode 100644 docs/examples/project/update-o-auth-2-spotify.md create mode 100644 docs/examples/project/update-o-auth-2-stripe.md create mode 100644 docs/examples/project/update-o-auth-2-tradeshift-sandbox.md create mode 100644 docs/examples/project/update-o-auth-2-tradeshift.md create mode 100644 docs/examples/project/update-o-auth-2-twitch.md create mode 100644 docs/examples/project/update-o-auth-2-word-press.md create mode 100644 docs/examples/project/update-o-auth-2-yahoo.md create mode 100644 docs/examples/project/update-o-auth-2-yandex.md create mode 100644 docs/examples/project/update-o-auth-2-zoho.md create mode 100644 docs/examples/project/update-o-auth-2-zoom.md create mode 100644 docs/examples/project/update-o-auth-2x.md create mode 100644 docs/examples/project/update-password-dictionary-policy.md create mode 100644 docs/examples/project/update-password-history-policy.md create mode 100644 docs/examples/project/update-password-personal-data-policy.md rename docs/examples/project/{update-protocol-status.md => update-protocol.md} (88%) rename docs/examples/project/{update-service-status.md => update-service.md} (88%) create mode 100644 docs/examples/project/update-session-alert-policy.md create mode 100644 docs/examples/project/update-session-duration-policy.md create mode 100644 docs/examples/project/update-session-invalidation-policy.md create mode 100644 docs/examples/project/update-session-limit-policy.md create mode 100644 docs/examples/project/update-smtp.md create mode 100644 docs/examples/project/update-user-limit-policy.md create mode 100644 docs/examples/proxy/create-api-rule.md create mode 100644 docs/examples/proxy/create-function-rule.md create mode 100644 docs/examples/proxy/create-redirect-rule.md create mode 100644 docs/examples/proxy/create-site-rule.md create mode 100644 docs/examples/proxy/delete-rule.md create mode 100644 docs/examples/proxy/get-rule.md create mode 100644 docs/examples/proxy/list-rules.md create mode 100644 docs/examples/proxy/update-rule-status.md create mode 100644 docs/examples/tablesdb/create-big-int-column.md create mode 100644 docs/examples/tablesdb/update-big-int-column.md create mode 100644 models/attributeBigint.go create mode 100644 models/attributeBigint_test.go create mode 100644 models/columnBigint.go create mode 100644 models/columnBigint_test.go create mode 100644 models/emailTemplate.go create mode 100644 models/emailTemplateList.go create mode 100644 models/emailTemplateList_test.go create mode 100644 models/emailTemplate_test.go create mode 100644 models/ephemeralKey.go create mode 100644 models/ephemeralKey_test.go create mode 100644 models/mockNumberList.go create mode 100644 models/mockNumberList_test.go create mode 100644 models/oAuth2Amazon.go create mode 100644 models/oAuth2Amazon_test.go create mode 100644 models/oAuth2Apple.go create mode 100644 models/oAuth2Apple_test.go create mode 100644 models/oAuth2Auth0.go create mode 100644 models/oAuth2Auth0_test.go create mode 100644 models/oAuth2Authentik.go create mode 100644 models/oAuth2Authentik_test.go create mode 100644 models/oAuth2Autodesk.go create mode 100644 models/oAuth2Autodesk_test.go create mode 100644 models/oAuth2Bitbucket.go create mode 100644 models/oAuth2Bitbucket_test.go create mode 100644 models/oAuth2Bitly.go create mode 100644 models/oAuth2Bitly_test.go create mode 100644 models/oAuth2Box.go create mode 100644 models/oAuth2Box_test.go create mode 100644 models/oAuth2Dailymotion.go create mode 100644 models/oAuth2Dailymotion_test.go create mode 100644 models/oAuth2Discord.go create mode 100644 models/oAuth2Discord_test.go create mode 100644 models/oAuth2Disqus.go create mode 100644 models/oAuth2Disqus_test.go create mode 100644 models/oAuth2Dropbox.go create mode 100644 models/oAuth2Dropbox_test.go create mode 100644 models/oAuth2Etsy.go create mode 100644 models/oAuth2Etsy_test.go create mode 100644 models/oAuth2Facebook.go create mode 100644 models/oAuth2Facebook_test.go create mode 100644 models/oAuth2Figma.go create mode 100644 models/oAuth2Figma_test.go create mode 100644 models/oAuth2FusionAuth.go create mode 100644 models/oAuth2FusionAuth_test.go create mode 100644 models/oAuth2Github.go create mode 100644 models/oAuth2Github_test.go create mode 100644 models/oAuth2Gitlab.go create mode 100644 models/oAuth2Gitlab_test.go create mode 100644 models/oAuth2Google.go create mode 100644 models/oAuth2Google_test.go create mode 100644 models/oAuth2Keycloak.go create mode 100644 models/oAuth2Keycloak_test.go create mode 100644 models/oAuth2Kick.go create mode 100644 models/oAuth2Kick_test.go create mode 100644 models/oAuth2Linkedin.go create mode 100644 models/oAuth2Linkedin_test.go create mode 100644 models/oAuth2Microsoft.go create mode 100644 models/oAuth2Microsoft_test.go create mode 100644 models/oAuth2Notion.go create mode 100644 models/oAuth2Notion_test.go create mode 100644 models/oAuth2Oidc.go create mode 100644 models/oAuth2Oidc_test.go create mode 100644 models/oAuth2Okta.go create mode 100644 models/oAuth2Okta_test.go create mode 100644 models/oAuth2Paypal.go create mode 100644 models/oAuth2Paypal_test.go create mode 100644 models/oAuth2Podio.go create mode 100644 models/oAuth2Podio_test.go create mode 100644 models/oAuth2ProviderList.go create mode 100644 models/oAuth2ProviderList_test.go create mode 100644 models/oAuth2Salesforce.go create mode 100644 models/oAuth2Salesforce_test.go create mode 100644 models/oAuth2Slack.go create mode 100644 models/oAuth2Slack_test.go create mode 100644 models/oAuth2Spotify.go create mode 100644 models/oAuth2Spotify_test.go create mode 100644 models/oAuth2Stripe.go create mode 100644 models/oAuth2Stripe_test.go create mode 100644 models/oAuth2Tradeshift.go create mode 100644 models/oAuth2Tradeshift_test.go create mode 100644 models/oAuth2Twitch.go create mode 100644 models/oAuth2Twitch_test.go create mode 100644 models/oAuth2WordPress.go create mode 100644 models/oAuth2WordPress_test.go create mode 100644 models/oAuth2X.go create mode 100644 models/oAuth2X_test.go create mode 100644 models/oAuth2Yahoo.go create mode 100644 models/oAuth2Yahoo_test.go create mode 100644 models/oAuth2Yandex.go create mode 100644 models/oAuth2Yandex_test.go create mode 100644 models/oAuth2Zoho.go create mode 100644 models/oAuth2Zoho_test.go create mode 100644 models/oAuth2Zoom.go create mode 100644 models/oAuth2Zoom_test.go create mode 100644 models/policyList.go create mode 100644 models/policyList_test.go create mode 100644 models/policyMembershipPrivacy.go create mode 100644 models/policyMembershipPrivacy_test.go create mode 100644 models/policyPasswordDictionary.go create mode 100644 models/policyPasswordDictionary_test.go create mode 100644 models/policyPasswordHistory.go create mode 100644 models/policyPasswordHistory_test.go create mode 100644 models/policyPasswordPersonalData.go create mode 100644 models/policyPasswordPersonalData_test.go create mode 100644 models/policySessionAlert.go create mode 100644 models/policySessionAlert_test.go create mode 100644 models/policySessionDuration.go create mode 100644 models/policySessionDuration_test.go create mode 100644 models/policySessionInvalidation.go create mode 100644 models/policySessionInvalidation_test.go create mode 100644 models/policySessionLimit.go create mode 100644 models/policySessionLimit_test.go create mode 100644 models/policyUserLimit.go create mode 100644 models/policyUserLimit_test.go create mode 100644 models/proxyRule.go create mode 100644 models/proxyRuleList.go create mode 100644 models/proxyRuleList_test.go create mode 100644 models/proxyRule_test.go create mode 100644 proxy/proxy.go create mode 100644 proxy/proxy_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index d83e8b40..a2bd1d5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## v3.1.0 + +* Added: Introduced `bigint` create/update APIs for legacy Databases attributes +* Added: Introduced `bigint` create/update APIs for `TablesDB` columns +* Updated: Extended key-list query filters with `key`, `resourceType`, `resourceId`, and `secret` + ## v3.0.0 * [BREAKING] Renamed Webhook model fields: `security` → `tls`, `httpUser` → `authUsername`, `httpPass` → `authPassword`, `signatureKey` → `secret` diff --git a/README.md b/README.md index 7a60c04b..76e362cd 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Appwrite Go SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-go.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.9.1-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.9.4-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-go/releases).** +**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-go/releases).** Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Go SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/appwrite/appwrite.go b/appwrite/appwrite.go index 967d7b87..a858a2a5 100644 --- a/appwrite/appwrite.go +++ b/appwrite/appwrite.go @@ -15,6 +15,7 @@ import ( "github.com/appwrite/sdk-for-go/v3/locale" "github.com/appwrite/sdk-for-go/v3/messaging" "github.com/appwrite/sdk-for-go/v3/project" + "github.com/appwrite/sdk-for-go/v3/proxy" "github.com/appwrite/sdk-for-go/v3/sites" "github.com/appwrite/sdk-for-go/v3/storage" "github.com/appwrite/sdk-for-go/v3/tablesdb" @@ -57,6 +58,9 @@ func NewMessaging(clt client.Client) *messaging.Messaging { func NewProject(clt client.Client) *project.Project { return project.New(clt) } +func NewProxy(clt client.Client) *proxy.Proxy { + return proxy.New(clt) +} func NewSites(clt client.Client) *sites.Sites { return sites.New(clt) } @@ -177,6 +181,24 @@ func WithForwardedUserAgent(value string) client.ClientOption { } // Helper method to construct NewClient() // +// Your secret dev API key +func WithDevKey(value string) client.ClientOption { + return func(clt *client.Client) error { + clt.Headers["X-Appwrite-Dev-Key"] = value + return nil + } +} +// Helper method to construct NewClient() +// +// The user cookie to authenticate with. Used by SDKs that forward an incoming Cookie header in server-side runtimes. +func WithCookie(value string) client.ClientOption { + return func(clt *client.Client) error { + clt.Headers["Cookie"] = value + return nil + } +} +// Helper method to construct NewClient() +// // Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data. func WithImpersonateUserId(value string) client.ClientOption { return func(clt *client.Client) error { diff --git a/client/client.go b/client/client.go index 4cd174cb..8175418f 100644 --- a/client/client.go +++ b/client/client.go @@ -73,12 +73,12 @@ type Client struct { // Initialize a new Appwrite client with a given timeout func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ - "X-Appwrite-Response-Format" : "1.9.1", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.0.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "X-Appwrite-Response-Format" : "1.9.4", + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.1.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v3.0.0", + "x-sdk-version": "v3.1.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { diff --git a/databases/databases.go b/databases/databases.go index 7750df9f..0165b5a6 100644 --- a/databases/databases.go +++ b/databases/databases.go @@ -1065,6 +1065,192 @@ func (srv *Databases) ListAttributes(DatabaseId string, CollectionId string, opt } return &parsed, nil +} +type CreateBigIntAttributeOptions struct { + Min int + Max int + Default int + Array bool + enabledSetters map[string]bool +} +func (options CreateBigIntAttributeOptions) New() *CreateBigIntAttributeOptions { + options.enabledSetters = map[string]bool{ + "Min": false, + "Max": false, + "Default": false, + "Array": false, + } + return &options +} +type CreateBigIntAttributeOption func(*CreateBigIntAttributeOptions) +func (srv *Databases) WithCreateBigIntAttributeMin(v int) CreateBigIntAttributeOption { + return func(o *CreateBigIntAttributeOptions) { + o.Min = v + o.enabledSetters["Min"] = true + } +} +func (srv *Databases) WithCreateBigIntAttributeMax(v int) CreateBigIntAttributeOption { + return func(o *CreateBigIntAttributeOptions) { + o.Max = v + o.enabledSetters["Max"] = true + } +} +func (srv *Databases) WithCreateBigIntAttributeDefault(v int) CreateBigIntAttributeOption { + return func(o *CreateBigIntAttributeOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func (srv *Databases) WithCreateBigIntAttributeArray(v bool) CreateBigIntAttributeOption { + return func(o *CreateBigIntAttributeOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} + +// CreateBigIntAttribute create a bigint attribute. Optionally, minimum and +// maximum values can be provided. +// +// Deprecated: This API has been deprecated since 1.8.0. Please use `TablesDB.createBigIntColumn` instead. +func (srv *Databases) CreateBigIntAttribute(DatabaseId string, CollectionId string, Key string, Required bool, optionalSetters ...CreateBigIntAttributeOption)(*models.AttributeBigint, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/bigint") + options := CreateBigIntAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + if options.enabledSetters["Min"] { + params["min"] = options.Min + } + if options.enabledSetters["Max"] { + params["max"] = options.Max + } + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.AttributeBigint{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.AttributeBigint + parsed, ok := resp.Result.(models.AttributeBigint) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateBigIntAttributeOptions struct { + Min int + Max int + NewKey string + enabledSetters map[string]bool +} +func (options UpdateBigIntAttributeOptions) New() *UpdateBigIntAttributeOptions { + options.enabledSetters = map[string]bool{ + "Min": false, + "Max": false, + "NewKey": false, + } + return &options +} +type UpdateBigIntAttributeOption func(*UpdateBigIntAttributeOptions) +func (srv *Databases) WithUpdateBigIntAttributeMin(v int) UpdateBigIntAttributeOption { + return func(o *UpdateBigIntAttributeOptions) { + o.Min = v + o.enabledSetters["Min"] = true + } +} +func (srv *Databases) WithUpdateBigIntAttributeMax(v int) UpdateBigIntAttributeOption { + return func(o *UpdateBigIntAttributeOptions) { + o.Max = v + o.enabledSetters["Max"] = true + } +} +func (srv *Databases) WithUpdateBigIntAttributeNewKey(v string) UpdateBigIntAttributeOption { + return func(o *UpdateBigIntAttributeOptions) { + o.NewKey = v + o.enabledSetters["NewKey"] = true + } +} + +// UpdateBigIntAttribute update a bigint attribute. Changing the `default` +// value will not update already existing documents. +// +// Deprecated: This API has been deprecated since 1.8.0. Please use `TablesDB.updateBigIntColumn` instead. +func (srv *Databases) UpdateBigIntAttribute(DatabaseId string, CollectionId string, Key string, Required bool, Default int, optionalSetters ...UpdateBigIntAttributeOption)(*models.AttributeBigint, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{collectionId}", CollectionId, "{key}", Key) + path := r.Replace("/databases/{databaseId}/collections/{collectionId}/attributes/bigint/{key}") + options := UpdateBigIntAttributeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["collectionId"] = CollectionId + params["key"] = Key + params["required"] = Required + params["default"] = Default + if options.enabledSetters["Min"] { + params["min"] = options.Min + } + if options.enabledSetters["Max"] { + params["max"] = options.Max + } + if options.enabledSetters["NewKey"] { + params["newKey"] = options.NewKey + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.AttributeBigint{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.AttributeBigint + parsed, ok := resp.Result.(models.AttributeBigint) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + } type CreateBooleanAttributeOptions struct { Default bool diff --git a/databases/databases_test.go b/databases/databases_test.go index 7d15e65d..e9ada676 100644 --- a/databases/databases_test.go +++ b/databases/databases_test.go @@ -776,6 +776,70 @@ func TestDatabases(t *testing.T) { } }) + t.Run("Test CreateBigIntAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "count", + "type": "bigint", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateBigIntAttribute("", "", "", true) + if err != nil { + t.Errorf("Method CreateBigIntAttribute failed: %v", err) + } + }) + + t.Run("Test UpdateBigIntAttribute", func(t *testing.T) { + mockResponse := ` +{ + "key": "count", + "type": "bigint", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateBigIntAttribute("", "", "", true, 1) + if err != nil { + t.Errorf("Method UpdateBigIntAttribute failed: %v", err) + } + }) + t.Run("Test CreateBooleanAttribute", func(t *testing.T) { mockResponse := ` { diff --git a/docs/examples/databases/create-big-int-attribute.md b/docs/examples/databases/create-big-int-attribute.md new file mode 100644 index 00000000..51378c45 --- /dev/null +++ b/docs/examples/databases/create-big-int-attribute.md @@ -0,0 +1,28 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/databases" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := databases.New(client) + +response, error := service.CreateBigIntAttribute( + "", + "", + "", + false, + databases.WithCreateBigIntAttributeMin(0), + databases.WithCreateBigIntAttributeMax(0), + databases.WithCreateBigIntAttributeDefault(0), + databases.WithCreateBigIntAttributeArray(false), +) +``` diff --git a/docs/examples/databases/update-big-int-attribute.md b/docs/examples/databases/update-big-int-attribute.md new file mode 100644 index 00000000..2b9e38fb --- /dev/null +++ b/docs/examples/databases/update-big-int-attribute.md @@ -0,0 +1,28 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/databases" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := databases.New(client) + +response, error := service.UpdateBigIntAttribute( + "", + "", + "", + false, + 0, + databases.WithUpdateBigIntAttributeMin(0), + databases.WithUpdateBigIntAttributeMax(0), + databases.WithUpdateBigIntAttributeNewKey(""), +) +``` diff --git a/docs/examples/functions/create-variable.md b/docs/examples/functions/create-variable.md index f6035737..a923034a 100644 --- a/docs/examples/functions/create-variable.md +++ b/docs/examples/functions/create-variable.md @@ -17,6 +17,7 @@ service := functions.New(client) response, error := service.CreateVariable( "", + "", "", "", functions.WithCreateVariableSecret(false), diff --git a/docs/examples/functions/list-variables.md b/docs/examples/functions/list-variables.md index b01d4c04..facc02e7 100644 --- a/docs/examples/functions/list-variables.md +++ b/docs/examples/functions/list-variables.md @@ -17,5 +17,7 @@ service := functions.New(client) response, error := service.ListVariables( "", + functions.WithListVariablesQueries([]interface{}{}), + functions.WithListVariablesTotal(false), ) ``` diff --git a/docs/examples/functions/update-variable.md b/docs/examples/functions/update-variable.md index 287cf699..1c4a5a7b 100644 --- a/docs/examples/functions/update-variable.md +++ b/docs/examples/functions/update-variable.md @@ -18,7 +18,7 @@ service := functions.New(client) response, error := service.UpdateVariable( "", "", - "", + functions.WithUpdateVariableKey(""), functions.WithUpdateVariableValue(""), functions.WithUpdateVariableSecret(false), ) diff --git a/docs/examples/project/create-ephemeral-key.md b/docs/examples/project/create-ephemeral-key.md new file mode 100644 index 00000000..6d4e6ee8 --- /dev/null +++ b/docs/examples/project/create-ephemeral-key.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.CreateEphemeralKey( + []interface{}{}, + 600, +) +``` diff --git a/docs/examples/project/create-mock-phone.md b/docs/examples/project/create-mock-phone.md new file mode 100644 index 00000000..ff08bf1e --- /dev/null +++ b/docs/examples/project/create-mock-phone.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.CreateMockPhone( + "+12065550100", + "", +) +``` diff --git a/docs/examples/project/create-smtp-test.md b/docs/examples/project/create-smtp-test.md new file mode 100644 index 00000000..75d07d4a --- /dev/null +++ b/docs/examples/project/create-smtp-test.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.CreateSMTPTest( + []interface{}{}, +) +``` diff --git a/docs/examples/project/delete-mock-phone.md b/docs/examples/project/delete-mock-phone.md new file mode 100644 index 00000000..a0c4c409 --- /dev/null +++ b/docs/examples/project/delete-mock-phone.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.DeleteMockPhone( + "+12065550100", +) +``` diff --git a/docs/examples/project/delete.md b/docs/examples/project/delete.md new file mode 100644 index 00000000..20ce8535 --- /dev/null +++ b/docs/examples/project/delete.md @@ -0,0 +1,19 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.Delete()) +``` diff --git a/docs/examples/project/get-email-template.md b/docs/examples/project/get-email-template.md new file mode 100644 index 00000000..64f1a067 --- /dev/null +++ b/docs/examples/project/get-email-template.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.GetEmailTemplate( + "verification", + project.WithGetEmailTemplateLocale("af"), +) +``` diff --git a/docs/examples/project/get-mock-phone.md b/docs/examples/project/get-mock-phone.md new file mode 100644 index 00000000..37e91d26 --- /dev/null +++ b/docs/examples/project/get-mock-phone.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.GetMockPhone( + "+12065550100", +) +``` diff --git a/docs/examples/project/get-o-auth-2-provider.md b/docs/examples/project/get-o-auth-2-provider.md new file mode 100644 index 00000000..92803115 --- /dev/null +++ b/docs/examples/project/get-o-auth-2-provider.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.GetOAuth2Provider( + "amazon", +) +``` diff --git a/docs/examples/project/get-policy.md b/docs/examples/project/get-policy.md new file mode 100644 index 00000000..ac24a2ba --- /dev/null +++ b/docs/examples/project/get-policy.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.GetPolicy( + "password-dictionary", +) +``` diff --git a/docs/examples/project/list-email-templates.md b/docs/examples/project/list-email-templates.md new file mode 100644 index 00000000..3cd6052e --- /dev/null +++ b/docs/examples/project/list-email-templates.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.ListEmailTemplates( + project.WithListEmailTemplatesQueries([]interface{}{}), + project.WithListEmailTemplatesTotal(false), +) +``` diff --git a/docs/examples/project/list-mock-phones.md b/docs/examples/project/list-mock-phones.md new file mode 100644 index 00000000..0db42b94 --- /dev/null +++ b/docs/examples/project/list-mock-phones.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.ListMockPhones( + project.WithListMockPhonesQueries([]interface{}{}), + project.WithListMockPhonesTotal(false), +) +``` diff --git a/docs/examples/project/list-o-auth-2-providers.md b/docs/examples/project/list-o-auth-2-providers.md new file mode 100644 index 00000000..4130e5aa --- /dev/null +++ b/docs/examples/project/list-o-auth-2-providers.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.ListOAuth2Providers( + project.WithListOAuth2ProvidersQueries([]interface{}{}), + project.WithListOAuth2ProvidersTotal(false), +) +``` diff --git a/docs/examples/project/list-policies.md b/docs/examples/project/list-policies.md new file mode 100644 index 00000000..baf2aef7 --- /dev/null +++ b/docs/examples/project/list-policies.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.ListPolicies( + project.WithListPoliciesQueries([]interface{}{}), + project.WithListPoliciesTotal(false), +) +``` diff --git a/docs/examples/project/update-auth-method.md b/docs/examples/project/update-auth-method.md new file mode 100644 index 00000000..6809ea9a --- /dev/null +++ b/docs/examples/project/update-auth-method.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateAuthMethod( + "email-password", + false, +) +``` diff --git a/docs/examples/project/update-email-template.md b/docs/examples/project/update-email-template.md new file mode 100644 index 00000000..fd52f392 --- /dev/null +++ b/docs/examples/project/update-email-template.md @@ -0,0 +1,28 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateEmailTemplate( + "verification", + project.WithUpdateEmailTemplateLocale("af"), + project.WithUpdateEmailTemplateSubject(""), + project.WithUpdateEmailTemplateMessage(""), + project.WithUpdateEmailTemplateSenderName(""), + project.WithUpdateEmailTemplateSenderEmail("email@example.com"), + project.WithUpdateEmailTemplateReplyToEmail("email@example.com"), + project.WithUpdateEmailTemplateReplyToName(""), +) +``` diff --git a/docs/examples/project/update-membership-privacy-policy.md b/docs/examples/project/update-membership-privacy-policy.md new file mode 100644 index 00000000..687c6f0e --- /dev/null +++ b/docs/examples/project/update-membership-privacy-policy.md @@ -0,0 +1,25 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateMembershipPrivacyPolicy( + project.WithUpdateMembershipPrivacyPolicyUserId(false), + project.WithUpdateMembershipPrivacyPolicyUserEmail(false), + project.WithUpdateMembershipPrivacyPolicyUserPhone(false), + project.WithUpdateMembershipPrivacyPolicyUserName(false), + project.WithUpdateMembershipPrivacyPolicyUserMFA(false), +) +``` diff --git a/docs/examples/project/update-mock-phone.md b/docs/examples/project/update-mock-phone.md new file mode 100644 index 00000000..e03b5c8d --- /dev/null +++ b/docs/examples/project/update-mock-phone.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateMockPhone( + "+12065550100", + "", +) +``` diff --git a/docs/examples/project/update-o-auth-2-amazon.md b/docs/examples/project/update-o-auth-2-amazon.md new file mode 100644 index 00000000..40f1328d --- /dev/null +++ b/docs/examples/project/update-o-auth-2-amazon.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Amazon( + project.WithUpdateOAuth2AmazonClientId(""), + project.WithUpdateOAuth2AmazonClientSecret(""), + project.WithUpdateOAuth2AmazonEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-apple.md b/docs/examples/project/update-o-auth-2-apple.md new file mode 100644 index 00000000..52a9a7eb --- /dev/null +++ b/docs/examples/project/update-o-auth-2-apple.md @@ -0,0 +1,25 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Apple( + project.WithUpdateOAuth2AppleServiceId(""), + project.WithUpdateOAuth2AppleKeyId(""), + project.WithUpdateOAuth2AppleTeamId(""), + project.WithUpdateOAuth2AppleP8File(""), + project.WithUpdateOAuth2AppleEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-auth-0.md b/docs/examples/project/update-o-auth-2-auth-0.md new file mode 100644 index 00000000..a0af729e --- /dev/null +++ b/docs/examples/project/update-o-auth-2-auth-0.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Auth0( + project.WithUpdateOAuth2Auth0ClientId(""), + project.WithUpdateOAuth2Auth0ClientSecret(""), + project.WithUpdateOAuth2Auth0Endpoint(""), + project.WithUpdateOAuth2Auth0Enabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-authentik.md b/docs/examples/project/update-o-auth-2-authentik.md new file mode 100644 index 00000000..adf50fca --- /dev/null +++ b/docs/examples/project/update-o-auth-2-authentik.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Authentik( + project.WithUpdateOAuth2AuthentikClientId(""), + project.WithUpdateOAuth2AuthentikClientSecret(""), + project.WithUpdateOAuth2AuthentikEndpoint(""), + project.WithUpdateOAuth2AuthentikEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-autodesk.md b/docs/examples/project/update-o-auth-2-autodesk.md new file mode 100644 index 00000000..5dc1b7a8 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-autodesk.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Autodesk( + project.WithUpdateOAuth2AutodeskClientId(""), + project.WithUpdateOAuth2AutodeskClientSecret(""), + project.WithUpdateOAuth2AutodeskEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-bitbucket.md b/docs/examples/project/update-o-auth-2-bitbucket.md new file mode 100644 index 00000000..e221a5cc --- /dev/null +++ b/docs/examples/project/update-o-auth-2-bitbucket.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Bitbucket( + project.WithUpdateOAuth2BitbucketKey(""), + project.WithUpdateOAuth2BitbucketSecret(""), + project.WithUpdateOAuth2BitbucketEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-bitly.md b/docs/examples/project/update-o-auth-2-bitly.md new file mode 100644 index 00000000..86e56a40 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-bitly.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Bitly( + project.WithUpdateOAuth2BitlyClientId(""), + project.WithUpdateOAuth2BitlyClientSecret(""), + project.WithUpdateOAuth2BitlyEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-box.md b/docs/examples/project/update-o-auth-2-box.md new file mode 100644 index 00000000..eda503e7 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-box.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Box( + project.WithUpdateOAuth2BoxClientId(""), + project.WithUpdateOAuth2BoxClientSecret(""), + project.WithUpdateOAuth2BoxEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-dailymotion.md b/docs/examples/project/update-o-auth-2-dailymotion.md new file mode 100644 index 00000000..a60b58ae --- /dev/null +++ b/docs/examples/project/update-o-auth-2-dailymotion.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Dailymotion( + project.WithUpdateOAuth2DailymotionApiKey(""), + project.WithUpdateOAuth2DailymotionApiSecret(""), + project.WithUpdateOAuth2DailymotionEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-discord.md b/docs/examples/project/update-o-auth-2-discord.md new file mode 100644 index 00000000..2aa0b489 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-discord.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Discord( + project.WithUpdateOAuth2DiscordClientId(""), + project.WithUpdateOAuth2DiscordClientSecret(""), + project.WithUpdateOAuth2DiscordEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-disqus.md b/docs/examples/project/update-o-auth-2-disqus.md new file mode 100644 index 00000000..65cb257b --- /dev/null +++ b/docs/examples/project/update-o-auth-2-disqus.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Disqus( + project.WithUpdateOAuth2DisqusPublicKey(""), + project.WithUpdateOAuth2DisqusSecretKey(""), + project.WithUpdateOAuth2DisqusEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-dropbox.md b/docs/examples/project/update-o-auth-2-dropbox.md new file mode 100644 index 00000000..43449c15 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-dropbox.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Dropbox( + project.WithUpdateOAuth2DropboxAppKey(""), + project.WithUpdateOAuth2DropboxAppSecret(""), + project.WithUpdateOAuth2DropboxEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-etsy.md b/docs/examples/project/update-o-auth-2-etsy.md new file mode 100644 index 00000000..e27df083 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-etsy.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Etsy( + project.WithUpdateOAuth2EtsyKeyString(""), + project.WithUpdateOAuth2EtsySharedSecret(""), + project.WithUpdateOAuth2EtsyEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-facebook.md b/docs/examples/project/update-o-auth-2-facebook.md new file mode 100644 index 00000000..c7153635 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-facebook.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Facebook( + project.WithUpdateOAuth2FacebookAppId(""), + project.WithUpdateOAuth2FacebookAppSecret(""), + project.WithUpdateOAuth2FacebookEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-figma.md b/docs/examples/project/update-o-auth-2-figma.md new file mode 100644 index 00000000..594f730d --- /dev/null +++ b/docs/examples/project/update-o-auth-2-figma.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Figma( + project.WithUpdateOAuth2FigmaClientId(""), + project.WithUpdateOAuth2FigmaClientSecret(""), + project.WithUpdateOAuth2FigmaEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-fusion-auth.md b/docs/examples/project/update-o-auth-2-fusion-auth.md new file mode 100644 index 00000000..4dcb531b --- /dev/null +++ b/docs/examples/project/update-o-auth-2-fusion-auth.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2FusionAuth( + project.WithUpdateOAuth2FusionAuthClientId(""), + project.WithUpdateOAuth2FusionAuthClientSecret(""), + project.WithUpdateOAuth2FusionAuthEndpoint(""), + project.WithUpdateOAuth2FusionAuthEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-git-hub.md b/docs/examples/project/update-o-auth-2-git-hub.md new file mode 100644 index 00000000..ac141d81 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-git-hub.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2GitHub( + project.WithUpdateOAuth2GitHubClientId(""), + project.WithUpdateOAuth2GitHubClientSecret(""), + project.WithUpdateOAuth2GitHubEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-gitlab.md b/docs/examples/project/update-o-auth-2-gitlab.md new file mode 100644 index 00000000..0da520ad --- /dev/null +++ b/docs/examples/project/update-o-auth-2-gitlab.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Gitlab( + project.WithUpdateOAuth2GitlabApplicationId(""), + project.WithUpdateOAuth2GitlabSecret(""), + project.WithUpdateOAuth2GitlabEndpoint("https://example.com"), + project.WithUpdateOAuth2GitlabEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-google.md b/docs/examples/project/update-o-auth-2-google.md new file mode 100644 index 00000000..b6c9bc9d --- /dev/null +++ b/docs/examples/project/update-o-auth-2-google.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Google( + project.WithUpdateOAuth2GoogleClientId(""), + project.WithUpdateOAuth2GoogleClientSecret(""), + project.WithUpdateOAuth2GoogleEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-keycloak.md b/docs/examples/project/update-o-auth-2-keycloak.md new file mode 100644 index 00000000..449b053c --- /dev/null +++ b/docs/examples/project/update-o-auth-2-keycloak.md @@ -0,0 +1,25 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Keycloak( + project.WithUpdateOAuth2KeycloakClientId(""), + project.WithUpdateOAuth2KeycloakClientSecret(""), + project.WithUpdateOAuth2KeycloakEndpoint(""), + project.WithUpdateOAuth2KeycloakRealmName(""), + project.WithUpdateOAuth2KeycloakEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-kick.md b/docs/examples/project/update-o-auth-2-kick.md new file mode 100644 index 00000000..c074e758 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-kick.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Kick( + project.WithUpdateOAuth2KickClientId(""), + project.WithUpdateOAuth2KickClientSecret(""), + project.WithUpdateOAuth2KickEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-linkedin.md b/docs/examples/project/update-o-auth-2-linkedin.md new file mode 100644 index 00000000..5dc25372 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-linkedin.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Linkedin( + project.WithUpdateOAuth2LinkedinClientId(""), + project.WithUpdateOAuth2LinkedinPrimaryClientSecret(""), + project.WithUpdateOAuth2LinkedinEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-microsoft.md b/docs/examples/project/update-o-auth-2-microsoft.md new file mode 100644 index 00000000..993a4fb9 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-microsoft.md @@ -0,0 +1,24 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Microsoft( + project.WithUpdateOAuth2MicrosoftApplicationId(""), + project.WithUpdateOAuth2MicrosoftApplicationSecret(""), + project.WithUpdateOAuth2MicrosoftTenant(""), + project.WithUpdateOAuth2MicrosoftEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-notion.md b/docs/examples/project/update-o-auth-2-notion.md new file mode 100644 index 00000000..6a38af4f --- /dev/null +++ b/docs/examples/project/update-o-auth-2-notion.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Notion( + project.WithUpdateOAuth2NotionOauthClientId(""), + project.WithUpdateOAuth2NotionOauthClientSecret(""), + project.WithUpdateOAuth2NotionEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-oidc.md b/docs/examples/project/update-o-auth-2-oidc.md new file mode 100644 index 00000000..cf72e223 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-oidc.md @@ -0,0 +1,27 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Oidc( + project.WithUpdateOAuth2OidcClientId(""), + project.WithUpdateOAuth2OidcClientSecret(""), + project.WithUpdateOAuth2OidcWellKnownURL("https://example.com"), + project.WithUpdateOAuth2OidcAuthorizationURL("https://example.com"), + project.WithUpdateOAuth2OidcTokenURL("https://example.com"), + project.WithUpdateOAuth2OidcUserInfoURL("https://example.com"), + project.WithUpdateOAuth2OidcEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-okta.md b/docs/examples/project/update-o-auth-2-okta.md new file mode 100644 index 00000000..54b705ed --- /dev/null +++ b/docs/examples/project/update-o-auth-2-okta.md @@ -0,0 +1,25 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Okta( + project.WithUpdateOAuth2OktaClientId(""), + project.WithUpdateOAuth2OktaClientSecret(""), + project.WithUpdateOAuth2OktaDomain(""), + project.WithUpdateOAuth2OktaAuthorizationServerId(""), + project.WithUpdateOAuth2OktaEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-paypal-sandbox.md b/docs/examples/project/update-o-auth-2-paypal-sandbox.md new file mode 100644 index 00000000..e97df81d --- /dev/null +++ b/docs/examples/project/update-o-auth-2-paypal-sandbox.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2PaypalSandbox( + project.WithUpdateOAuth2PaypalSandboxClientId(""), + project.WithUpdateOAuth2PaypalSandboxSecretKey(""), + project.WithUpdateOAuth2PaypalSandboxEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-paypal.md b/docs/examples/project/update-o-auth-2-paypal.md new file mode 100644 index 00000000..b7eeb319 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-paypal.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Paypal( + project.WithUpdateOAuth2PaypalClientId(""), + project.WithUpdateOAuth2PaypalSecretKey(""), + project.WithUpdateOAuth2PaypalEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-podio.md b/docs/examples/project/update-o-auth-2-podio.md new file mode 100644 index 00000000..057f0369 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-podio.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Podio( + project.WithUpdateOAuth2PodioClientId(""), + project.WithUpdateOAuth2PodioClientSecret(""), + project.WithUpdateOAuth2PodioEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-salesforce.md b/docs/examples/project/update-o-auth-2-salesforce.md new file mode 100644 index 00000000..9439a8e1 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-salesforce.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Salesforce( + project.WithUpdateOAuth2SalesforceCustomerKey(""), + project.WithUpdateOAuth2SalesforceCustomerSecret(""), + project.WithUpdateOAuth2SalesforceEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-slack.md b/docs/examples/project/update-o-auth-2-slack.md new file mode 100644 index 00000000..e9fb3f56 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-slack.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Slack( + project.WithUpdateOAuth2SlackClientId(""), + project.WithUpdateOAuth2SlackClientSecret(""), + project.WithUpdateOAuth2SlackEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-spotify.md b/docs/examples/project/update-o-auth-2-spotify.md new file mode 100644 index 00000000..2e854894 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-spotify.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Spotify( + project.WithUpdateOAuth2SpotifyClientId(""), + project.WithUpdateOAuth2SpotifyClientSecret(""), + project.WithUpdateOAuth2SpotifyEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-stripe.md b/docs/examples/project/update-o-auth-2-stripe.md new file mode 100644 index 00000000..801b26ec --- /dev/null +++ b/docs/examples/project/update-o-auth-2-stripe.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Stripe( + project.WithUpdateOAuth2StripeClientId(""), + project.WithUpdateOAuth2StripeApiSecretKey(""), + project.WithUpdateOAuth2StripeEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-tradeshift-sandbox.md b/docs/examples/project/update-o-auth-2-tradeshift-sandbox.md new file mode 100644 index 00000000..93863ebb --- /dev/null +++ b/docs/examples/project/update-o-auth-2-tradeshift-sandbox.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2TradeshiftSandbox( + project.WithUpdateOAuth2TradeshiftSandboxOauth2ClientId(""), + project.WithUpdateOAuth2TradeshiftSandboxOauth2ClientSecret(""), + project.WithUpdateOAuth2TradeshiftSandboxEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-tradeshift.md b/docs/examples/project/update-o-auth-2-tradeshift.md new file mode 100644 index 00000000..901b78d5 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-tradeshift.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Tradeshift( + project.WithUpdateOAuth2TradeshiftOauth2ClientId(""), + project.WithUpdateOAuth2TradeshiftOauth2ClientSecret(""), + project.WithUpdateOAuth2TradeshiftEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-twitch.md b/docs/examples/project/update-o-auth-2-twitch.md new file mode 100644 index 00000000..f79cc086 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-twitch.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Twitch( + project.WithUpdateOAuth2TwitchClientId(""), + project.WithUpdateOAuth2TwitchClientSecret(""), + project.WithUpdateOAuth2TwitchEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-word-press.md b/docs/examples/project/update-o-auth-2-word-press.md new file mode 100644 index 00000000..b9bd6a99 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-word-press.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2WordPress( + project.WithUpdateOAuth2WordPressClientId(""), + project.WithUpdateOAuth2WordPressClientSecret(""), + project.WithUpdateOAuth2WordPressEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-yahoo.md b/docs/examples/project/update-o-auth-2-yahoo.md new file mode 100644 index 00000000..da70f7da --- /dev/null +++ b/docs/examples/project/update-o-auth-2-yahoo.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Yahoo( + project.WithUpdateOAuth2YahooClientId(""), + project.WithUpdateOAuth2YahooClientSecret(""), + project.WithUpdateOAuth2YahooEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-yandex.md b/docs/examples/project/update-o-auth-2-yandex.md new file mode 100644 index 00000000..94955c32 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-yandex.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Yandex( + project.WithUpdateOAuth2YandexClientId(""), + project.WithUpdateOAuth2YandexClientSecret(""), + project.WithUpdateOAuth2YandexEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-zoho.md b/docs/examples/project/update-o-auth-2-zoho.md new file mode 100644 index 00000000..62bc2904 --- /dev/null +++ b/docs/examples/project/update-o-auth-2-zoho.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Zoho( + project.WithUpdateOAuth2ZohoClientId(""), + project.WithUpdateOAuth2ZohoClientSecret(""), + project.WithUpdateOAuth2ZohoEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2-zoom.md b/docs/examples/project/update-o-auth-2-zoom.md new file mode 100644 index 00000000..afc7519d --- /dev/null +++ b/docs/examples/project/update-o-auth-2-zoom.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2Zoom( + project.WithUpdateOAuth2ZoomClientId(""), + project.WithUpdateOAuth2ZoomClientSecret(""), + project.WithUpdateOAuth2ZoomEnabled(false), +) +``` diff --git a/docs/examples/project/update-o-auth-2x.md b/docs/examples/project/update-o-auth-2x.md new file mode 100644 index 00000000..596e626d --- /dev/null +++ b/docs/examples/project/update-o-auth-2x.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateOAuth2X( + project.WithUpdateOAuth2XCustomerKey(""), + project.WithUpdateOAuth2XSecretKey(""), + project.WithUpdateOAuth2XEnabled(false), +) +``` diff --git a/docs/examples/project/update-password-dictionary-policy.md b/docs/examples/project/update-password-dictionary-policy.md new file mode 100644 index 00000000..c3ba706c --- /dev/null +++ b/docs/examples/project/update-password-dictionary-policy.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdatePasswordDictionaryPolicy( + false, +) +``` diff --git a/docs/examples/project/update-password-history-policy.md b/docs/examples/project/update-password-history-policy.md new file mode 100644 index 00000000..c8a698f8 --- /dev/null +++ b/docs/examples/project/update-password-history-policy.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdatePasswordHistoryPolicy( + 1, +) +``` diff --git a/docs/examples/project/update-password-personal-data-policy.md b/docs/examples/project/update-password-personal-data-policy.md new file mode 100644 index 00000000..f165c7f5 --- /dev/null +++ b/docs/examples/project/update-password-personal-data-policy.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdatePasswordPersonalDataPolicy( + false, +) +``` diff --git a/docs/examples/project/update-protocol-status.md b/docs/examples/project/update-protocol.md similarity index 88% rename from docs/examples/project/update-protocol-status.md rename to docs/examples/project/update-protocol.md index d156bcb0..af30a8ee 100644 --- a/docs/examples/project/update-protocol-status.md +++ b/docs/examples/project/update-protocol.md @@ -15,7 +15,7 @@ client := client.New( service := project.New(client) -response, error := service.UpdateProtocolStatus( +response, error := service.UpdateProtocol( "rest", false, ) diff --git a/docs/examples/project/update-service-status.md b/docs/examples/project/update-service.md similarity index 88% rename from docs/examples/project/update-service-status.md rename to docs/examples/project/update-service.md index edd019c4..4efb06c2 100644 --- a/docs/examples/project/update-service-status.md +++ b/docs/examples/project/update-service.md @@ -15,7 +15,7 @@ client := client.New( service := project.New(client) -response, error := service.UpdateServiceStatus( +response, error := service.UpdateService( "account", false, ) diff --git a/docs/examples/project/update-session-alert-policy.md b/docs/examples/project/update-session-alert-policy.md new file mode 100644 index 00000000..321c07f9 --- /dev/null +++ b/docs/examples/project/update-session-alert-policy.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateSessionAlertPolicy( + false, +) +``` diff --git a/docs/examples/project/update-session-duration-policy.md b/docs/examples/project/update-session-duration-policy.md new file mode 100644 index 00000000..3f979d32 --- /dev/null +++ b/docs/examples/project/update-session-duration-policy.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateSessionDurationPolicy( + 5, +) +``` diff --git a/docs/examples/project/update-session-invalidation-policy.md b/docs/examples/project/update-session-invalidation-policy.md new file mode 100644 index 00000000..e01da7cd --- /dev/null +++ b/docs/examples/project/update-session-invalidation-policy.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateSessionInvalidationPolicy( + false, +) +``` diff --git a/docs/examples/project/update-session-limit-policy.md b/docs/examples/project/update-session-limit-policy.md new file mode 100644 index 00000000..31518f28 --- /dev/null +++ b/docs/examples/project/update-session-limit-policy.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateSessionLimitPolicy( + 1, +) +``` diff --git a/docs/examples/project/update-smtp.md b/docs/examples/project/update-smtp.md new file mode 100644 index 00000000..c9423a2b --- /dev/null +++ b/docs/examples/project/update-smtp.md @@ -0,0 +1,30 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateSMTP( + project.WithUpdateSMTPHost(""), + project.WithUpdateSMTPPort(0), + project.WithUpdateSMTPUsername(""), + project.WithUpdateSMTPPassword(""), + project.WithUpdateSMTPSenderEmail("email@example.com"), + project.WithUpdateSMTPSenderName(""), + project.WithUpdateSMTPReplyToEmail("email@example.com"), + project.WithUpdateSMTPReplyToName(""), + project.WithUpdateSMTPSecure("tls"), + project.WithUpdateSMTPEnabled(false), +) +``` diff --git a/docs/examples/project/update-user-limit-policy.md b/docs/examples/project/update-user-limit-policy.md new file mode 100644 index 00000000..e3e6de3b --- /dev/null +++ b/docs/examples/project/update-user-limit-policy.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/project" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := project.New(client) + +response, error := service.UpdateUserLimitPolicy( + 1, +) +``` diff --git a/docs/examples/proxy/create-api-rule.md b/docs/examples/proxy/create-api-rule.md new file mode 100644 index 00000000..de1757c2 --- /dev/null +++ b/docs/examples/proxy/create-api-rule.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/proxy" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := proxy.New(client) + +response, error := service.CreateAPIRule( + "", +) +``` diff --git a/docs/examples/proxy/create-function-rule.md b/docs/examples/proxy/create-function-rule.md new file mode 100644 index 00000000..2108e21a --- /dev/null +++ b/docs/examples/proxy/create-function-rule.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/proxy" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := proxy.New(client) + +response, error := service.CreateFunctionRule( + "", + "", + proxy.WithCreateFunctionRuleBranch(""), +) +``` diff --git a/docs/examples/proxy/create-redirect-rule.md b/docs/examples/proxy/create-redirect-rule.md new file mode 100644 index 00000000..fec32800 --- /dev/null +++ b/docs/examples/proxy/create-redirect-rule.md @@ -0,0 +1,25 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/proxy" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := proxy.New(client) + +response, error := service.CreateRedirectRule( + "", + "https://example.com", + "301", + "", + "site", +) +``` diff --git a/docs/examples/proxy/create-site-rule.md b/docs/examples/proxy/create-site-rule.md new file mode 100644 index 00000000..b53ee56d --- /dev/null +++ b/docs/examples/proxy/create-site-rule.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/proxy" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := proxy.New(client) + +response, error := service.CreateSiteRule( + "", + "", + proxy.WithCreateSiteRuleBranch(""), +) +``` diff --git a/docs/examples/proxy/delete-rule.md b/docs/examples/proxy/delete-rule.md new file mode 100644 index 00000000..202ad1fc --- /dev/null +++ b/docs/examples/proxy/delete-rule.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/proxy" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := proxy.New(client) + +response, error := service.DeleteRule( + "", +) +``` diff --git a/docs/examples/proxy/get-rule.md b/docs/examples/proxy/get-rule.md new file mode 100644 index 00000000..59a582c0 --- /dev/null +++ b/docs/examples/proxy/get-rule.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/proxy" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := proxy.New(client) + +response, error := service.GetRule( + "", +) +``` diff --git a/docs/examples/proxy/list-rules.md b/docs/examples/proxy/list-rules.md new file mode 100644 index 00000000..236abf34 --- /dev/null +++ b/docs/examples/proxy/list-rules.md @@ -0,0 +1,22 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/proxy" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := proxy.New(client) + +response, error := service.ListRules( + proxy.WithListRulesQueries([]interface{}{}), + proxy.WithListRulesTotal(false), +) +``` diff --git a/docs/examples/proxy/update-rule-status.md b/docs/examples/proxy/update-rule-status.md new file mode 100644 index 00000000..e76b0ad4 --- /dev/null +++ b/docs/examples/proxy/update-rule-status.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/proxy" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := proxy.New(client) + +response, error := service.UpdateRuleStatus( + "", +) +``` diff --git a/docs/examples/sites/create-variable.md b/docs/examples/sites/create-variable.md index 55c7bc24..986dab0e 100644 --- a/docs/examples/sites/create-variable.md +++ b/docs/examples/sites/create-variable.md @@ -17,6 +17,7 @@ service := sites.New(client) response, error := service.CreateVariable( "", + "", "", "", sites.WithCreateVariableSecret(false), diff --git a/docs/examples/sites/list-variables.md b/docs/examples/sites/list-variables.md index e156b586..e7b27cf6 100644 --- a/docs/examples/sites/list-variables.md +++ b/docs/examples/sites/list-variables.md @@ -17,5 +17,7 @@ service := sites.New(client) response, error := service.ListVariables( "", + sites.WithListVariablesQueries([]interface{}{}), + sites.WithListVariablesTotal(false), ) ``` diff --git a/docs/examples/sites/update-variable.md b/docs/examples/sites/update-variable.md index 54c18b70..b2e0102b 100644 --- a/docs/examples/sites/update-variable.md +++ b/docs/examples/sites/update-variable.md @@ -18,7 +18,7 @@ service := sites.New(client) response, error := service.UpdateVariable( "", "", - "", + sites.WithUpdateVariableKey(""), sites.WithUpdateVariableValue(""), sites.WithUpdateVariableSecret(false), ) diff --git a/docs/examples/tablesdb/create-big-int-column.md b/docs/examples/tablesdb/create-big-int-column.md new file mode 100644 index 00000000..b302e05f --- /dev/null +++ b/docs/examples/tablesdb/create-big-int-column.md @@ -0,0 +1,28 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/tablesdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := tablesdb.New(client) + +response, error := service.CreateBigIntColumn( + "", + "", + "", + false, + tablesdb.WithCreateBigIntColumnMin(0), + tablesdb.WithCreateBigIntColumnMax(0), + tablesdb.WithCreateBigIntColumnDefault(0), + tablesdb.WithCreateBigIntColumnArray(false), +) +``` diff --git a/docs/examples/tablesdb/update-big-int-column.md b/docs/examples/tablesdb/update-big-int-column.md new file mode 100644 index 00000000..089b8bef --- /dev/null +++ b/docs/examples/tablesdb/update-big-int-column.md @@ -0,0 +1,28 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/tablesdb" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := tablesdb.New(client) + +response, error := service.UpdateBigIntColumn( + "", + "", + "", + false, + 0, + tablesdb.WithUpdateBigIntColumnMin(0), + tablesdb.WithUpdateBigIntColumnMax(0), + tablesdb.WithUpdateBigIntColumnNewKey(""), +) +``` diff --git a/functions/functions.go b/functions/functions.go index 28e9660a..f57fa1e9 100644 --- a/functions/functions.go +++ b/functions/functions.go @@ -1572,13 +1572,48 @@ func (srv *Functions) DeleteExecution(FunctionId string, ExecutionId string)(*in return &parsed, nil } - +type ListVariablesOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListVariablesOptions) New() *ListVariablesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + } + return &options +} +type ListVariablesOption func(*ListVariablesOptions) +func (srv *Functions) WithListVariablesQueries(v []string) ListVariablesOption { + return func(o *ListVariablesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *Functions) WithListVariablesTotal(v bool) ListVariablesOption { + return func(o *ListVariablesOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + // ListVariables get a list of all variables of a specific function. -func (srv *Functions) ListVariables(FunctionId string)(*models.VariableList, error) { +func (srv *Functions) ListVariables(FunctionId string, optionalSetters ...ListVariablesOption)(*models.VariableList, error) { r := strings.NewReplacer("{functionId}", FunctionId) path := r.Replace("/functions/{functionId}/variables") + options := ListVariablesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } params := map[string]interface{}{} params["functionId"] = FunctionId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } headers := map[string]interface{}{ } @@ -1623,10 +1658,10 @@ func (srv *Functions) WithCreateVariableSecret(v bool) CreateVariableOption { o.enabledSetters["Secret"] = true } } - + // CreateVariable create a new function environment variable. These variables // can be accessed in the function at runtime as environment variables. -func (srv *Functions) CreateVariable(FunctionId string, Key string, Value string, optionalSetters ...CreateVariableOption)(*models.Variable, error) { +func (srv *Functions) CreateVariable(FunctionId string, VariableId string, Key string, Value string, optionalSetters ...CreateVariableOption)(*models.Variable, error) { r := strings.NewReplacer("{functionId}", FunctionId) path := r.Replace("/functions/{functionId}/variables") options := CreateVariableOptions{}.New() @@ -1635,6 +1670,7 @@ func (srv *Functions) CreateVariable(FunctionId string, Key string, Value string } params := map[string]interface{}{} params["functionId"] = FunctionId + params["variableId"] = VariableId params["key"] = Key params["value"] = Value if options.enabledSetters["Secret"] { @@ -1704,18 +1740,26 @@ func (srv *Functions) GetVariable(FunctionId string, VariableId string)(*models. } type UpdateVariableOptions struct { + Key string Value string Secret bool enabledSetters map[string]bool } func (options UpdateVariableOptions) New() *UpdateVariableOptions { options.enabledSetters = map[string]bool{ + "Key": false, "Value": false, "Secret": false, } return &options } type UpdateVariableOption func(*UpdateVariableOptions) +func (srv *Functions) WithUpdateVariableKey(v string) UpdateVariableOption { + return func(o *UpdateVariableOptions) { + o.Key = v + o.enabledSetters["Key"] = true + } +} func (srv *Functions) WithUpdateVariableValue(v string) UpdateVariableOption { return func(o *UpdateVariableOptions) { o.Value = v @@ -1728,9 +1772,9 @@ func (srv *Functions) WithUpdateVariableSecret(v bool) UpdateVariableOption { o.enabledSetters["Secret"] = true } } - + // UpdateVariable update variable by its unique ID. -func (srv *Functions) UpdateVariable(FunctionId string, VariableId string, Key string, optionalSetters ...UpdateVariableOption)(*models.Variable, error) { +func (srv *Functions) UpdateVariable(FunctionId string, VariableId string, optionalSetters ...UpdateVariableOption)(*models.Variable, error) { r := strings.NewReplacer("{functionId}", FunctionId, "{variableId}", VariableId) path := r.Replace("/functions/{functionId}/variables/{variableId}") options := UpdateVariableOptions{}.New() @@ -1740,7 +1784,9 @@ func (srv *Functions) UpdateVariable(FunctionId string, VariableId string, Key s params := map[string]interface{}{} params["functionId"] = FunctionId params["variableId"] = VariableId - params["key"] = Key + if options.enabledSetters["Key"] { + params["key"] = options.Key + } if options.enabledSetters["Value"] { params["value"] = options.Value } diff --git a/functions/functions_test.go b/functions/functions_test.go index d703514f..44a491d2 100644 --- a/functions/functions_test.go +++ b/functions/functions_test.go @@ -1133,7 +1133,7 @@ func TestFunctions(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.CreateVariable("", "", "") + _, err := srv.CreateVariable("", "", "", "") if err != nil { t.Errorf("Method CreateVariable failed: %v", err) } @@ -1199,7 +1199,7 @@ func TestFunctions(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.UpdateVariable("", "", "") + _, err := srv.UpdateVariable("", "") if err != nil { t.Errorf("Method UpdateVariable failed: %v", err) } diff --git a/models/attributeBigint.go b/models/attributeBigint.go new file mode 100644 index 00000000..173d6947 --- /dev/null +++ b/models/attributeBigint.go @@ -0,0 +1,56 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// AttributeBigInt Model +type AttributeBigint struct { + // Attribute Key. + Key string `json:"key"` + // Attribute type. + Type string `json:"type"` + // Attribute status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an attribute. + Error string `json:"error"` + // Is attribute required? + Required bool `json:"required"` + // Is attribute an array? + Array bool `json:"array"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Minimum value to enforce for new documents. + Min int `json:"min"` + // Maximum value to enforce for new documents. + Max int `json:"max"` + // Default value for attribute when not provided. Cannot be set when attribute + // is required. + Default int `json:"default"` + + // Used by Decode() method + data []byte +} + +func (model AttributeBigint) New(data []byte) *AttributeBigint { + model.data = data + return &model +} + +func (model *AttributeBigint) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/attributeBigint_test.go b/models/attributeBigint_test.go new file mode 100644 index 00000000..d20fe2ad --- /dev/null +++ b/models/attributeBigint_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestAttributeBigintModel(t *testing.T) { + model := AttributeBigint{ Key: "count", Type: "bigint", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result AttributeBigint + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/authProvider.go b/models/authProvider.go index 5b2ea574..bc12ddba 100644 --- a/models/authProvider.go +++ b/models/authProvider.go @@ -14,7 +14,7 @@ type AuthProvider struct { // OAuth 2.0 application ID. AppId string `json:"appId"` // OAuth 2.0 application secret. Might be JSON string if provider requires - // extra configuration. + // extra configuration. This property is write-only and always returned empty. Secret string `json:"secret"` // Auth Provider is active and can be used to create session. Enabled bool `json:"enabled"` diff --git a/models/authProvider_test.go b/models/authProvider_test.go index 75577cb1..160ad31f 100644 --- a/models/authProvider_test.go +++ b/models/authProvider_test.go @@ -6,7 +6,7 @@ import ( ) func TestAuthProviderModel(t *testing.T) { - model := AuthProvider{ Key: "github", Name: "GitHub", AppId: "259125845563242502", Secret: "Bpw_g9c2TGXxfgLshDbSaL8tsCcqgczQ", Enabled: true, } + model := AuthProvider{ Key: "github", Name: "GitHub", AppId: "259125845563242502", Secret: "string", Enabled: true, } data, err := json.Marshal(model) if err != nil { diff --git a/models/block.go b/models/block.go index 7d00c915..875d53ff 100644 --- a/models/block.go +++ b/models/block.go @@ -18,6 +18,16 @@ type Block struct { // Block expiration date in ISO 8601 format. Can be null if the block does not // expire. ExpiredAt string `json:"expiredAt"` + // Name of the project this block applies to. + ProjectName string `json:"projectName"` + // Region of the project this block applies to. + Region string `json:"region"` + // Name of the organization that owns the project. + OrganizationName string `json:"organizationName"` + // ID of the organization that owns the project. + OrganizationId string `json:"organizationId"` + // Billing plan of the organization that owns the project. + BillingPlan string `json:"billingPlan"` // Used by Decode() method data []byte diff --git a/models/block_test.go b/models/block_test.go index 016ecd5a..94c78d1a 100644 --- a/models/block_test.go +++ b/models/block_test.go @@ -6,7 +6,7 @@ import ( ) func TestBlockModel(t *testing.T) { - model := Block{ CreatedAt: "2020-10-15T06:38:00.000+00:00", ResourceType: "project", ResourceId: "5e5ea5c16897e", } + model := Block{ CreatedAt: "2020-10-15T06:38:00.000+00:00", ResourceType: "project", ResourceId: "5e5ea5c16897e", ProjectName: "My Project", Region: "fra", OrganizationName: "Acme Inc.", OrganizationId: "5e5ea5c16897e", BillingPlan: "pro", } data, err := json.Marshal(model) if err != nil { @@ -26,4 +26,19 @@ func TestBlockModel(t *testing.T) { } if result.ResourceId != model.ResourceId { t.Errorf("Expected ResourceId %v, got %v", model.ResourceId, result.ResourceId) + } + if result.ProjectName != model.ProjectName { + t.Errorf("Expected ProjectName %v, got %v", model.ProjectName, result.ProjectName) + } + if result.Region != model.Region { + t.Errorf("Expected Region %v, got %v", model.Region, result.Region) + } + if result.OrganizationName != model.OrganizationName { + t.Errorf("Expected OrganizationName %v, got %v", model.OrganizationName, result.OrganizationName) + } + if result.OrganizationId != model.OrganizationId { + t.Errorf("Expected OrganizationId %v, got %v", model.OrganizationId, result.OrganizationId) + } + if result.BillingPlan != model.BillingPlan { + t.Errorf("Expected BillingPlan %v, got %v", model.BillingPlan, result.BillingPlan) }} diff --git a/models/columnBigint.go b/models/columnBigint.go new file mode 100644 index 00000000..789588f1 --- /dev/null +++ b/models/columnBigint.go @@ -0,0 +1,56 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// ColumnBigInt Model +type ColumnBigint struct { + // Column Key. + Key string `json:"key"` + // Column type. + Type string `json:"type"` + // Column status. Possible values: `available`, `processing`, `deleting`, + // `stuck`, or `failed` + Status string `json:"status"` + // Error message. Displays error generated on failure of creating or deleting + // an column. + Error string `json:"error"` + // Is column required? + Required bool `json:"required"` + // Is column an array? + Array bool `json:"array"` + // Column creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Column update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Minimum value to enforce for new documents. + Min int `json:"min"` + // Maximum value to enforce for new documents. + Max int `json:"max"` + // Default value for column when not provided. Cannot be set when column is + // required. + Default int `json:"default"` + + // Used by Decode() method + data []byte +} + +func (model ColumnBigint) New(data []byte) *ColumnBigint { + model.data = data + return &model +} + +func (model *ColumnBigint) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/columnBigint_test.go b/models/columnBigint_test.go new file mode 100644 index 00000000..ff45da3c --- /dev/null +++ b/models/columnBigint_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestColumnBigintModel(t *testing.T) { + model := ColumnBigint{ Key: "count", Type: "bigint", Status: "available", Error: "string", Required: true, CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ColumnBigint + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Error != model.Error { + t.Errorf("Expected Error %v, got %v", model.Error, result.Error) + } + if result.Required != model.Required { + t.Errorf("Expected Required %v, got %v", model.Required, result.Required) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + }} diff --git a/models/emailTemplate.go b/models/emailTemplate.go new file mode 100644 index 00000000..2c1b542f --- /dev/null +++ b/models/emailTemplate.go @@ -0,0 +1,47 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// EmailTemplate Model +type EmailTemplate struct { + // Template type + TemplateId string `json:"templateId"` + // Template locale + Locale string `json:"locale"` + // Template message + Message string `json:"message"` + // Name of the sender + SenderName string `json:"senderName"` + // Email of the sender + SenderEmail string `json:"senderEmail"` + // Reply to email address + ReplyToEmail string `json:"replyToEmail"` + // Reply to name + ReplyToName string `json:"replyToName"` + // Email subject + Subject string `json:"subject"` + + // Used by Decode() method + data []byte +} + +func (model EmailTemplate) New(data []byte) *EmailTemplate { + model.data = data + return &model +} + +func (model *EmailTemplate) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/emailTemplateList.go b/models/emailTemplateList.go new file mode 100644 index 00000000..6ab1cb12 --- /dev/null +++ b/models/emailTemplateList.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// EmailTemplatesList Model +type EmailTemplateList struct { + // Total number of templates that matched your query. + Total int `json:"total"` + // List of templates. + Templates []EmailTemplate `json:"templates"` + + // Used by Decode() method + data []byte +} + +func (model EmailTemplateList) New(data []byte) *EmailTemplateList { + model.data = data + return &model +} + +func (model *EmailTemplateList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/emailTemplateList_test.go b/models/emailTemplateList_test.go new file mode 100644 index 00000000..b9d74d19 --- /dev/null +++ b/models/emailTemplateList_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestEmailTemplateListModel(t *testing.T) { + model := EmailTemplateList{ Total: 5, Templates: []EmailTemplate{EmailTemplate{ TemplateId: "verification", Locale: "en_us", Message: "Click on the link to verify your account.", SenderName: "My User", SenderEmail: "mail@appwrite.io", ReplyToEmail: "emails@appwrite.io", ReplyToName: "Support Team", Subject: "Please verify your email address", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result EmailTemplateList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/emailTemplate_test.go b/models/emailTemplate_test.go new file mode 100644 index 00000000..72d0cffe --- /dev/null +++ b/models/emailTemplate_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestEmailTemplateModel(t *testing.T) { + model := EmailTemplate{ TemplateId: "verification", Locale: "en_us", Message: "Click on the link to verify your account.", SenderName: "My User", SenderEmail: "mail@appwrite.io", ReplyToEmail: "emails@appwrite.io", ReplyToName: "Support Team", Subject: "Please verify your email address", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result EmailTemplate + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.TemplateId != model.TemplateId { + t.Errorf("Expected TemplateId %v, got %v", model.TemplateId, result.TemplateId) + } + if result.Locale != model.Locale { + t.Errorf("Expected Locale %v, got %v", model.Locale, result.Locale) + } + if result.Message != model.Message { + t.Errorf("Expected Message %v, got %v", model.Message, result.Message) + } + if result.SenderName != model.SenderName { + t.Errorf("Expected SenderName %v, got %v", model.SenderName, result.SenderName) + } + if result.SenderEmail != model.SenderEmail { + t.Errorf("Expected SenderEmail %v, got %v", model.SenderEmail, result.SenderEmail) + } + if result.ReplyToEmail != model.ReplyToEmail { + t.Errorf("Expected ReplyToEmail %v, got %v", model.ReplyToEmail, result.ReplyToEmail) + } + if result.ReplyToName != model.ReplyToName { + t.Errorf("Expected ReplyToName %v, got %v", model.ReplyToName, result.ReplyToName) + } + if result.Subject != model.Subject { + t.Errorf("Expected Subject %v, got %v", model.Subject, result.Subject) + }} diff --git a/models/ephemeralKey.go b/models/ephemeralKey.go new file mode 100644 index 00000000..3d2ab930 --- /dev/null +++ b/models/ephemeralKey.go @@ -0,0 +1,50 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// EphemeralKey Model +type EphemeralKey struct { + // Key ID. + Id string `json:"$id"` + // Key creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Key update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Key name. + Name string `json:"name"` + // Key expiration date in ISO 8601 format. + Expire string `json:"expire"` + // Allowed permission scopes. + Scopes []string `json:"scopes"` + // Secret key. + Secret string `json:"secret"` + // Most recent access date in ISO 8601 format. This attribute is only updated + // again after 24 hours. + AccessedAt string `json:"accessedAt"` + // List of SDK user agents that used this key. + Sdks []string `json:"sdks"` + + // Used by Decode() method + data []byte +} + +func (model EphemeralKey) New(data []byte) *EphemeralKey { + model.data = data + return &model +} + +func (model *EphemeralKey) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/ephemeralKey_test.go b/models/ephemeralKey_test.go new file mode 100644 index 00000000..e5aadb44 --- /dev/null +++ b/models/ephemeralKey_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestEphemeralKeyModel(t *testing.T) { + model := EphemeralKey{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "My API Key", Expire: "2020-10-15T06:38:00.000+00:00", Scopes: []string{"test"}, Secret: "919c2d18fb5d4...a2ae413da83346ad2", AccessedAt: "2020-10-15T06:38:00.000+00:00", Sdks: []string{"test"}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result EphemeralKey + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Name != model.Name { + t.Errorf("Expected Name %v, got %v", model.Name, result.Name) + } + if result.Expire != model.Expire { + t.Errorf("Expected Expire %v, got %v", model.Expire, result.Expire) + } + if result.Secret != model.Secret { + t.Errorf("Expected Secret %v, got %v", model.Secret, result.Secret) + } + if result.AccessedAt != model.AccessedAt { + t.Errorf("Expected AccessedAt %v, got %v", model.AccessedAt, result.AccessedAt) + }} diff --git a/models/membership.go b/models/membership.go index 777b9dd2..4479a5a3 100644 --- a/models/membership.go +++ b/models/membership.go @@ -21,6 +21,9 @@ type Membership struct { // User email address. Hide this attribute by toggling membership privacy in // the Console. UserEmail string `json:"userEmail"` + // User phone number. Hide this attribute by toggling membership privacy in + // the Console. + UserPhone string `json:"userPhone"` // Team ID. TeamId string `json:"teamId"` // Team name. diff --git a/models/membershipList_test.go b/models/membershipList_test.go index 2973da02..31da6b52 100644 --- a/models/membershipList_test.go +++ b/models/membershipList_test.go @@ -6,7 +6,7 @@ import ( ) func TestMembershipListModel(t *testing.T) { - model := MembershipList{ Total: 5, Memberships: []Membership{Membership{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5ea5c16897e", UserName: "John Doe", UserEmail: "john@appwrite.io", TeamId: "5e5ea5c16897e", TeamName: "VIP", Invited: "2020-10-15T06:38:00.000+00:00", Joined: "2020-10-15T06:38:00.000+00:00", Confirm: true, Mfa: true, Roles: []string{"test"}, }, + model := MembershipList{ Total: 5, Memberships: []Membership{Membership{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5ea5c16897e", UserName: "John Doe", UserEmail: "john@appwrite.io", UserPhone: "+1 555 555 5555", TeamId: "5e5ea5c16897e", TeamName: "VIP", Invited: "2020-10-15T06:38:00.000+00:00", Joined: "2020-10-15T06:38:00.000+00:00", Confirm: true, Mfa: true, Roles: []string{"test"}, }, }, } data, err := json.Marshal(model) diff --git a/models/membership_test.go b/models/membership_test.go index 3c62e3e2..597b79e6 100644 --- a/models/membership_test.go +++ b/models/membership_test.go @@ -6,7 +6,7 @@ import ( ) func TestMembershipModel(t *testing.T) { - model := Membership{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5ea5c16897e", UserName: "John Doe", UserEmail: "john@appwrite.io", TeamId: "5e5ea5c16897e", TeamName: "VIP", Invited: "2020-10-15T06:38:00.000+00:00", Joined: "2020-10-15T06:38:00.000+00:00", Confirm: true, Mfa: true, Roles: []string{"test"}, } + model := Membership{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", UserId: "5e5ea5c16897e", UserName: "John Doe", UserEmail: "john@appwrite.io", UserPhone: "+1 555 555 5555", TeamId: "5e5ea5c16897e", TeamName: "VIP", Invited: "2020-10-15T06:38:00.000+00:00", Joined: "2020-10-15T06:38:00.000+00:00", Confirm: true, Mfa: true, Roles: []string{"test"}, } data, err := json.Marshal(model) if err != nil { @@ -36,6 +36,9 @@ func TestMembershipModel(t *testing.T) { if result.UserEmail != model.UserEmail { t.Errorf("Expected UserEmail %v, got %v", model.UserEmail, result.UserEmail) } + if result.UserPhone != model.UserPhone { + t.Errorf("Expected UserPhone %v, got %v", model.UserPhone, result.UserPhone) + } if result.TeamId != model.TeamId { t.Errorf("Expected TeamId %v, got %v", model.TeamId, result.TeamId) } diff --git a/models/mockNumber.go b/models/mockNumber.go index b9d0647b..11ec33dd 100644 --- a/models/mockNumber.go +++ b/models/mockNumber.go @@ -9,9 +9,13 @@ import ( type MockNumber struct { // Mock phone number for testing phone authentication. Useful for testing // phone authentication without sending an SMS. - Phone string `json:"phone"` + Number string `json:"number"` // Mock OTP for the number. Otp string `json:"otp"` + // Attribute creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Attribute update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` // Used by Decode() method data []byte diff --git a/models/mockNumberList.go b/models/mockNumberList.go new file mode 100644 index 00000000..2b72a716 --- /dev/null +++ b/models/mockNumberList.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// MockNumbersList Model +type MockNumberList struct { + // Total number of mockNumbers that matched your query. + Total int `json:"total"` + // List of mockNumbers. + MockNumbers []MockNumber `json:"mockNumbers"` + + // Used by Decode() method + data []byte +} + +func (model MockNumberList) New(data []byte) *MockNumberList { + model.data = data + return &model +} + +func (model *MockNumberList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/mockNumberList_test.go b/models/mockNumberList_test.go new file mode 100644 index 00000000..5a6ac4eb --- /dev/null +++ b/models/mockNumberList_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestMockNumberListModel(t *testing.T) { + model := MockNumberList{ Total: 5, MockNumbers: []MockNumber{MockNumber{ Number: "+1612842323", Otp: "123456", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result MockNumberList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/mockNumber_test.go b/models/mockNumber_test.go index 422ad244..19dd04b4 100644 --- a/models/mockNumber_test.go +++ b/models/mockNumber_test.go @@ -6,7 +6,7 @@ import ( ) func TestMockNumberModel(t *testing.T) { - model := MockNumber{ Phone: "+1612842323", Otp: "123456", } + model := MockNumber{ Number: "+1612842323", Otp: "123456", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", } data, err := json.Marshal(model) if err != nil { @@ -18,9 +18,15 @@ func TestMockNumberModel(t *testing.T) { if err != nil { t.Fatal(err) } - if result.Phone != model.Phone { - t.Errorf("Expected Phone %v, got %v", model.Phone, result.Phone) + if result.Number != model.Number { + t.Errorf("Expected Number %v, got %v", model.Number, result.Number) } if result.Otp != model.Otp { t.Errorf("Expected Otp %v, got %v", model.Otp, result.Otp) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) }} diff --git a/models/oAuth2Amazon.go b/models/oAuth2Amazon.go new file mode 100644 index 00000000..228c245f --- /dev/null +++ b/models/oAuth2Amazon.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Amazon Model +type OAuth2Amazon struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Amazon OAuth2 client ID. + ClientId string `json:"clientId"` + // Amazon OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Amazon) New(data []byte) *OAuth2Amazon { + model.data = data + return &model +} + +func (model *OAuth2Amazon) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Amazon_test.go b/models/oAuth2Amazon_test.go new file mode 100644 index 00000000..a5a1d57d --- /dev/null +++ b/models/oAuth2Amazon_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2AmazonModel(t *testing.T) { + model := OAuth2Amazon{ Id: "github", Enabled: true, ClientId: "amzn1.application-oa2-client.87400c00000000000000000000063d5b2", ClientSecret: "79ffe4000000000000000000000000000000000000000000000000000002de55", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Amazon + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Apple.go b/models/oAuth2Apple.go new file mode 100644 index 00000000..7ddeaf1d --- /dev/null +++ b/models/oAuth2Apple.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Apple Model +type OAuth2Apple struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Apple OAuth2 service ID. + ServiceId string `json:"serviceId"` + // Apple OAuth2 key ID. + KeyId string `json:"keyId"` + // Apple OAuth2 team ID. + TeamId string `json:"teamId"` + // Apple OAuth2 .p8 private key file contents. The secret key wrapped by the + // PEM markers is 200 characters long. + P8File string `json:"p8File"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Apple) New(data []byte) *OAuth2Apple { + model.data = data + return &model +} + +func (model *OAuth2Apple) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Apple_test.go b/models/oAuth2Apple_test.go new file mode 100644 index 00000000..af158275 --- /dev/null +++ b/models/oAuth2Apple_test.go @@ -0,0 +1,38 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2AppleModel(t *testing.T) { + model := OAuth2Apple{ Id: "apple", Enabled: true, ServiceId: "ip.appwrite.app.web", KeyId: "P4000000N8", TeamId: "D4000000R6", P8File: "-----BEGIN PRIVATE KEY-----MIGTAg...jy2Xbna-----END PRIVATE KEY-----", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Apple + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ServiceId != model.ServiceId { + t.Errorf("Expected ServiceId %v, got %v", model.ServiceId, result.ServiceId) + } + if result.KeyId != model.KeyId { + t.Errorf("Expected KeyId %v, got %v", model.KeyId, result.KeyId) + } + if result.TeamId != model.TeamId { + t.Errorf("Expected TeamId %v, got %v", model.TeamId, result.TeamId) + } + if result.P8File != model.P8File { + t.Errorf("Expected P8File %v, got %v", model.P8File, result.P8File) + }} diff --git a/models/oAuth2Auth0.go b/models/oAuth2Auth0.go new file mode 100644 index 00000000..48896a4f --- /dev/null +++ b/models/oAuth2Auth0.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Auth0 Model +type OAuth2Auth0 struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Auth0 OAuth2 client ID. + ClientId string `json:"clientId"` + // Auth0 OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + // Auth0 OAuth2 endpoint domain. + Endpoint string `json:"endpoint"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Auth0) New(data []byte) *OAuth2Auth0 { + model.data = data + return &model +} + +func (model *OAuth2Auth0) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Auth0_test.go b/models/oAuth2Auth0_test.go new file mode 100644 index 00000000..07dada05 --- /dev/null +++ b/models/oAuth2Auth0_test.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2Auth0Model(t *testing.T) { + model := OAuth2Auth0{ Id: "github", Enabled: true, ClientId: "OaOkIA000000000000000000005KLSYq", ClientSecret: "zXz0000-00000000000000000000000000000-00000000000000000000PJafnF", Endpoint: "example.us.auth0.com", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Auth0 + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + } + if result.Endpoint != model.Endpoint { + t.Errorf("Expected Endpoint %v, got %v", model.Endpoint, result.Endpoint) + }} diff --git a/models/oAuth2Authentik.go b/models/oAuth2Authentik.go new file mode 100644 index 00000000..70c5a0d7 --- /dev/null +++ b/models/oAuth2Authentik.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Authentik Model +type OAuth2Authentik struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Authentik OAuth2 client ID. + ClientId string `json:"clientId"` + // Authentik OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + // Authentik OAuth2 endpoint domain. + Endpoint string `json:"endpoint"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Authentik) New(data []byte) *OAuth2Authentik { + model.data = data + return &model +} + +func (model *OAuth2Authentik) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Authentik_test.go b/models/oAuth2Authentik_test.go new file mode 100644 index 00000000..aeefaeec --- /dev/null +++ b/models/oAuth2Authentik_test.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2AuthentikModel(t *testing.T) { + model := OAuth2Authentik{ Id: "github", Enabled: true, ClientId: "dTKOPa0000000000000000000000000000e7G8hv", ClientSecret: "ntQadq000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000Hp5WK", Endpoint: "example.authentik.com", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Authentik + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + } + if result.Endpoint != model.Endpoint { + t.Errorf("Expected Endpoint %v, got %v", model.Endpoint, result.Endpoint) + }} diff --git a/models/oAuth2Autodesk.go b/models/oAuth2Autodesk.go new file mode 100644 index 00000000..e1c32e18 --- /dev/null +++ b/models/oAuth2Autodesk.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Autodesk Model +type OAuth2Autodesk struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Autodesk OAuth2 client ID. + ClientId string `json:"clientId"` + // Autodesk OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Autodesk) New(data []byte) *OAuth2Autodesk { + model.data = data + return &model +} + +func (model *OAuth2Autodesk) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Autodesk_test.go b/models/oAuth2Autodesk_test.go new file mode 100644 index 00000000..f8db242a --- /dev/null +++ b/models/oAuth2Autodesk_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2AutodeskModel(t *testing.T) { + model := OAuth2Autodesk{ Id: "github", Enabled: true, ClientId: "5zw90v00000000000000000000kVYXN7", ClientSecret: "7I000000000000MW", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Autodesk + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Bitbucket.go b/models/oAuth2Bitbucket.go new file mode 100644 index 00000000..c3f5f2ae --- /dev/null +++ b/models/oAuth2Bitbucket.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Bitbucket Model +type OAuth2Bitbucket struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Bitbucket OAuth2 key. + Key string `json:"key"` + // Bitbucket OAuth2 secret. + Secret string `json:"secret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Bitbucket) New(data []byte) *OAuth2Bitbucket { + model.data = data + return &model +} + +func (model *OAuth2Bitbucket) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Bitbucket_test.go b/models/oAuth2Bitbucket_test.go new file mode 100644 index 00000000..10af6b12 --- /dev/null +++ b/models/oAuth2Bitbucket_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2BitbucketModel(t *testing.T) { + model := OAuth2Bitbucket{ Id: "github", Enabled: true, Key: "Knt70000000000ByRc", Secret: "NMfLZJ00000000000000000000TLQdDx", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Bitbucket + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.Key != model.Key { + t.Errorf("Expected Key %v, got %v", model.Key, result.Key) + } + if result.Secret != model.Secret { + t.Errorf("Expected Secret %v, got %v", model.Secret, result.Secret) + }} diff --git a/models/oAuth2Bitly.go b/models/oAuth2Bitly.go new file mode 100644 index 00000000..5a130eec --- /dev/null +++ b/models/oAuth2Bitly.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Bitly Model +type OAuth2Bitly struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Bitly OAuth2 client ID. + ClientId string `json:"clientId"` + // Bitly OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Bitly) New(data []byte) *OAuth2Bitly { + model.data = data + return &model +} + +func (model *OAuth2Bitly) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Bitly_test.go b/models/oAuth2Bitly_test.go new file mode 100644 index 00000000..387a23e5 --- /dev/null +++ b/models/oAuth2Bitly_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2BitlyModel(t *testing.T) { + model := OAuth2Bitly{ Id: "github", Enabled: true, ClientId: "d95151000000000000000000000000000067af9b", ClientSecret: "a13e250000000000000000000000000000d73095", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Bitly + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Box.go b/models/oAuth2Box.go new file mode 100644 index 00000000..d806c1d3 --- /dev/null +++ b/models/oAuth2Box.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Box Model +type OAuth2Box struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Box OAuth2 client ID. + ClientId string `json:"clientId"` + // Box OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Box) New(data []byte) *OAuth2Box { + model.data = data + return &model +} + +func (model *OAuth2Box) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Box_test.go b/models/oAuth2Box_test.go new file mode 100644 index 00000000..02ee9caf --- /dev/null +++ b/models/oAuth2Box_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2BoxModel(t *testing.T) { + model := OAuth2Box{ Id: "github", Enabled: true, ClientId: "deglcs00000000000000000000x2og6y", ClientSecret: "OKM1f100000000000000000000eshEif", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Box + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Dailymotion.go b/models/oAuth2Dailymotion.go new file mode 100644 index 00000000..2c8b8ce2 --- /dev/null +++ b/models/oAuth2Dailymotion.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Dailymotion Model +type OAuth2Dailymotion struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Dailymotion OAuth2 API key. + ApiKey string `json:"apiKey"` + // Dailymotion OAuth2 API secret. + ApiSecret string `json:"apiSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Dailymotion) New(data []byte) *OAuth2Dailymotion { + model.data = data + return &model +} + +func (model *OAuth2Dailymotion) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Dailymotion_test.go b/models/oAuth2Dailymotion_test.go new file mode 100644 index 00000000..f5852c72 --- /dev/null +++ b/models/oAuth2Dailymotion_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2DailymotionModel(t *testing.T) { + model := OAuth2Dailymotion{ Id: "github", Enabled: true, ApiKey: "07a9000000000000067f", ApiSecret: "a399a90000000000000000000000000000d90639", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Dailymotion + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ApiKey != model.ApiKey { + t.Errorf("Expected ApiKey %v, got %v", model.ApiKey, result.ApiKey) + } + if result.ApiSecret != model.ApiSecret { + t.Errorf("Expected ApiSecret %v, got %v", model.ApiSecret, result.ApiSecret) + }} diff --git a/models/oAuth2Discord.go b/models/oAuth2Discord.go new file mode 100644 index 00000000..dcd4b23f --- /dev/null +++ b/models/oAuth2Discord.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Discord Model +type OAuth2Discord struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Discord OAuth2 client ID. + ClientId string `json:"clientId"` + // Discord OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Discord) New(data []byte) *OAuth2Discord { + model.data = data + return &model +} + +func (model *OAuth2Discord) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Discord_test.go b/models/oAuth2Discord_test.go new file mode 100644 index 00000000..d03aa3dd --- /dev/null +++ b/models/oAuth2Discord_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2DiscordModel(t *testing.T) { + model := OAuth2Discord{ Id: "github", Enabled: true, ClientId: "950722000000343754", ClientSecret: "YmPXnM000000000000000000002zFg5D", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Discord + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Disqus.go b/models/oAuth2Disqus.go new file mode 100644 index 00000000..944cf7b8 --- /dev/null +++ b/models/oAuth2Disqus.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Disqus Model +type OAuth2Disqus struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Disqus OAuth2 public key. + PublicKey string `json:"publicKey"` + // Disqus OAuth2 secret key. + SecretKey string `json:"secretKey"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Disqus) New(data []byte) *OAuth2Disqus { + model.data = data + return &model +} + +func (model *OAuth2Disqus) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Disqus_test.go b/models/oAuth2Disqus_test.go new file mode 100644 index 00000000..74985cbc --- /dev/null +++ b/models/oAuth2Disqus_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2DisqusModel(t *testing.T) { + model := OAuth2Disqus{ Id: "github", Enabled: true, PublicKey: "cgegH70000000000000000000000000000000000000000000000000000Hr1nYX", SecretKey: "W7Bykj00000000000000000000000000000000000000000000000000003o43w9", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Disqus + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.PublicKey != model.PublicKey { + t.Errorf("Expected PublicKey %v, got %v", model.PublicKey, result.PublicKey) + } + if result.SecretKey != model.SecretKey { + t.Errorf("Expected SecretKey %v, got %v", model.SecretKey, result.SecretKey) + }} diff --git a/models/oAuth2Dropbox.go b/models/oAuth2Dropbox.go new file mode 100644 index 00000000..8d58e44a --- /dev/null +++ b/models/oAuth2Dropbox.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Dropbox Model +type OAuth2Dropbox struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Dropbox OAuth2 app key. + AppKey string `json:"appKey"` + // Dropbox OAuth2 app secret. + AppSecret string `json:"appSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Dropbox) New(data []byte) *OAuth2Dropbox { + model.data = data + return &model +} + +func (model *OAuth2Dropbox) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Dropbox_test.go b/models/oAuth2Dropbox_test.go new file mode 100644 index 00000000..44d4d794 --- /dev/null +++ b/models/oAuth2Dropbox_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2DropboxModel(t *testing.T) { + model := OAuth2Dropbox{ Id: "github", Enabled: true, AppKey: "jl000000000009t", AppSecret: "g200000000000vw", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Dropbox + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.AppKey != model.AppKey { + t.Errorf("Expected AppKey %v, got %v", model.AppKey, result.AppKey) + } + if result.AppSecret != model.AppSecret { + t.Errorf("Expected AppSecret %v, got %v", model.AppSecret, result.AppSecret) + }} diff --git a/models/oAuth2Etsy.go b/models/oAuth2Etsy.go new file mode 100644 index 00000000..5f17abc9 --- /dev/null +++ b/models/oAuth2Etsy.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Etsy Model +type OAuth2Etsy struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Etsy OAuth2 keystring. + KeyString string `json:"keyString"` + // Etsy OAuth2 shared secret. + SharedSecret string `json:"sharedSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Etsy) New(data []byte) *OAuth2Etsy { + model.data = data + return &model +} + +func (model *OAuth2Etsy) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Etsy_test.go b/models/oAuth2Etsy_test.go new file mode 100644 index 00000000..e42ee6a1 --- /dev/null +++ b/models/oAuth2Etsy_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2EtsyModel(t *testing.T) { + model := OAuth2Etsy{ Id: "github", Enabled: true, KeyString: "nsgzxh0000000000008j85a2", SharedSecret: "tp000000ru", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Etsy + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.KeyString != model.KeyString { + t.Errorf("Expected KeyString %v, got %v", model.KeyString, result.KeyString) + } + if result.SharedSecret != model.SharedSecret { + t.Errorf("Expected SharedSecret %v, got %v", model.SharedSecret, result.SharedSecret) + }} diff --git a/models/oAuth2Facebook.go b/models/oAuth2Facebook.go new file mode 100644 index 00000000..6f22e25e --- /dev/null +++ b/models/oAuth2Facebook.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Facebook Model +type OAuth2Facebook struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Facebook OAuth2 app ID. + AppId string `json:"appId"` + // Facebook OAuth2 app secret. + AppSecret string `json:"appSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Facebook) New(data []byte) *OAuth2Facebook { + model.data = data + return &model +} + +func (model *OAuth2Facebook) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Facebook_test.go b/models/oAuth2Facebook_test.go new file mode 100644 index 00000000..b3d5476f --- /dev/null +++ b/models/oAuth2Facebook_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2FacebookModel(t *testing.T) { + model := OAuth2Facebook{ Id: "github", Enabled: true, AppId: "260600000007694", AppSecret: "2d0b2800000000000000000000d38af4", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Facebook + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.AppId != model.AppId { + t.Errorf("Expected AppId %v, got %v", model.AppId, result.AppId) + } + if result.AppSecret != model.AppSecret { + t.Errorf("Expected AppSecret %v, got %v", model.AppSecret, result.AppSecret) + }} diff --git a/models/oAuth2Figma.go b/models/oAuth2Figma.go new file mode 100644 index 00000000..1246ed7f --- /dev/null +++ b/models/oAuth2Figma.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Figma Model +type OAuth2Figma struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Figma OAuth2 client ID. + ClientId string `json:"clientId"` + // Figma OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Figma) New(data []byte) *OAuth2Figma { + model.data = data + return &model +} + +func (model *OAuth2Figma) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Figma_test.go b/models/oAuth2Figma_test.go new file mode 100644 index 00000000..6765b0a3 --- /dev/null +++ b/models/oAuth2Figma_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2FigmaModel(t *testing.T) { + model := OAuth2Figma{ Id: "github", Enabled: true, ClientId: "byay5H0000000000VtiI40", ClientSecret: "yEpOYn0000000000000000004iIsU5", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Figma + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2FusionAuth.go b/models/oAuth2FusionAuth.go new file mode 100644 index 00000000..2ed430a5 --- /dev/null +++ b/models/oAuth2FusionAuth.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2FusionAuth Model +type OAuth2FusionAuth struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // FusionAuth OAuth2 client ID. + ClientId string `json:"clientId"` + // FusionAuth OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + // FusionAuth OAuth2 endpoint domain. + Endpoint string `json:"endpoint"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2FusionAuth) New(data []byte) *OAuth2FusionAuth { + model.data = data + return &model +} + +func (model *OAuth2FusionAuth) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2FusionAuth_test.go b/models/oAuth2FusionAuth_test.go new file mode 100644 index 00000000..f4acd5a7 --- /dev/null +++ b/models/oAuth2FusionAuth_test.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2FusionAuthModel(t *testing.T) { + model := OAuth2FusionAuth{ Id: "github", Enabled: true, ClientId: "b2222c00-0000-0000-0000-000000862097", ClientSecret: "Jx4s0C0000000000000000000000000000000wGqLsc", Endpoint: "example.fusionauth.io", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2FusionAuth + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + } + if result.Endpoint != model.Endpoint { + t.Errorf("Expected Endpoint %v, got %v", model.Endpoint, result.Endpoint) + }} diff --git a/models/oAuth2Github.go b/models/oAuth2Github.go new file mode 100644 index 00000000..16a7ff1d --- /dev/null +++ b/models/oAuth2Github.go @@ -0,0 +1,40 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2GitHub Model +type OAuth2Github struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // GitHub OAuth2 client ID. For GitHub Apps, use the "App ID" when both an App + // ID and client ID are available. + ClientId string `json:"clientId"` + // GitHub OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Github) New(data []byte) *OAuth2Github { + model.data = data + return &model +} + +func (model *OAuth2Github) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Github_test.go b/models/oAuth2Github_test.go new file mode 100644 index 00000000..d56c255d --- /dev/null +++ b/models/oAuth2Github_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2GithubModel(t *testing.T) { + model := OAuth2Github{ Id: "github", Enabled: true, ClientId: "e4d87900000000540733", ClientSecret: "5e07c00000000000000000000000000000198bcc", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Github + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Gitlab.go b/models/oAuth2Gitlab.go new file mode 100644 index 00000000..048c4227 --- /dev/null +++ b/models/oAuth2Gitlab.go @@ -0,0 +1,42 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Gitlab Model +type OAuth2Gitlab struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // GitLab OAuth2 application ID. + ApplicationId string `json:"applicationId"` + // GitLab OAuth2 secret. + Secret string `json:"secret"` + // GitLab OAuth2 endpoint URL. Defaults to https://gitlab.com for self-hosted + // instances. + Endpoint string `json:"endpoint"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Gitlab) New(data []byte) *OAuth2Gitlab { + model.data = data + return &model +} + +func (model *OAuth2Gitlab) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Gitlab_test.go b/models/oAuth2Gitlab_test.go new file mode 100644 index 00000000..6e9c90c4 --- /dev/null +++ b/models/oAuth2Gitlab_test.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2GitlabModel(t *testing.T) { + model := OAuth2Gitlab{ Id: "github", Enabled: true, ApplicationId: "d41ffe0000000000000000000000000000000000000000000000000000d5e252", Secret: "gloas-838cfa0000000000000000000000000000000000000000000000000000ecbb38", Endpoint: "https://gitlab.com", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Gitlab + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ApplicationId != model.ApplicationId { + t.Errorf("Expected ApplicationId %v, got %v", model.ApplicationId, result.ApplicationId) + } + if result.Secret != model.Secret { + t.Errorf("Expected Secret %v, got %v", model.Secret, result.Secret) + } + if result.Endpoint != model.Endpoint { + t.Errorf("Expected Endpoint %v, got %v", model.Endpoint, result.Endpoint) + }} diff --git a/models/oAuth2Google.go b/models/oAuth2Google.go new file mode 100644 index 00000000..560bed0e --- /dev/null +++ b/models/oAuth2Google.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Google Model +type OAuth2Google struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Google OAuth2 client ID. + ClientId string `json:"clientId"` + // Google OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Google) New(data []byte) *OAuth2Google { + model.data = data + return &model +} + +func (model *OAuth2Google) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Google_test.go b/models/oAuth2Google_test.go new file mode 100644 index 00000000..87a36ad9 --- /dev/null +++ b/models/oAuth2Google_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2GoogleModel(t *testing.T) { + model := OAuth2Google{ Id: "github", Enabled: true, ClientId: "your-google-client-id.apps.googleusercontent.com", ClientSecret: "your-google-client-secret", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Google + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Keycloak.go b/models/oAuth2Keycloak.go new file mode 100644 index 00000000..f7bc73b1 --- /dev/null +++ b/models/oAuth2Keycloak.go @@ -0,0 +1,43 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Keycloak Model +type OAuth2Keycloak struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Keycloak OAuth2 client ID. + ClientId string `json:"clientId"` + // Keycloak OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + // Keycloak OAuth2 endpoint domain. + Endpoint string `json:"endpoint"` + // Keycloak OAuth2 realm name. + RealmName string `json:"realmName"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Keycloak) New(data []byte) *OAuth2Keycloak { + model.data = data + return &model +} + +func (model *OAuth2Keycloak) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Keycloak_test.go b/models/oAuth2Keycloak_test.go new file mode 100644 index 00000000..50ca7e79 --- /dev/null +++ b/models/oAuth2Keycloak_test.go @@ -0,0 +1,38 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2KeycloakModel(t *testing.T) { + model := OAuth2Keycloak{ Id: "github", Enabled: true, ClientId: "appwrite-o0000000st-app", ClientSecret: "jdjrJd00000000000000000000HUsaZO", Endpoint: "keycloak.example.com", RealmName: "appwrite-realm", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Keycloak + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + } + if result.Endpoint != model.Endpoint { + t.Errorf("Expected Endpoint %v, got %v", model.Endpoint, result.Endpoint) + } + if result.RealmName != model.RealmName { + t.Errorf("Expected RealmName %v, got %v", model.RealmName, result.RealmName) + }} diff --git a/models/oAuth2Kick.go b/models/oAuth2Kick.go new file mode 100644 index 00000000..1ae8fcff --- /dev/null +++ b/models/oAuth2Kick.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Kick Model +type OAuth2Kick struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Kick OAuth2 client ID. + ClientId string `json:"clientId"` + // Kick OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Kick) New(data []byte) *OAuth2Kick { + model.data = data + return &model +} + +func (model *OAuth2Kick) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Kick_test.go b/models/oAuth2Kick_test.go new file mode 100644 index 00000000..33e96f41 --- /dev/null +++ b/models/oAuth2Kick_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2KickModel(t *testing.T) { + model := OAuth2Kick{ Id: "github", Enabled: true, ClientId: "01KQ7C00000000000001MFHS32", ClientSecret: "34ac5600000000000000000000000000000000000000000000000000e830c8b", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Kick + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Linkedin.go b/models/oAuth2Linkedin.go new file mode 100644 index 00000000..7ece5557 --- /dev/null +++ b/models/oAuth2Linkedin.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Linkedin Model +type OAuth2Linkedin struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // LinkedIn OAuth2 client ID. + ClientId string `json:"clientId"` + // LinkedIn OAuth2 primary client secret. + PrimaryClientSecret string `json:"primaryClientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Linkedin) New(data []byte) *OAuth2Linkedin { + model.data = data + return &model +} + +func (model *OAuth2Linkedin) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Linkedin_test.go b/models/oAuth2Linkedin_test.go new file mode 100644 index 00000000..a8f7ee21 --- /dev/null +++ b/models/oAuth2Linkedin_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2LinkedinModel(t *testing.T) { + model := OAuth2Linkedin{ Id: "github", Enabled: true, ClientId: "770000000000dv", PrimaryClientSecret: "your-linkedin-client-secret", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Linkedin + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.PrimaryClientSecret != model.PrimaryClientSecret { + t.Errorf("Expected PrimaryClientSecret %v, got %v", model.PrimaryClientSecret, result.PrimaryClientSecret) + }} diff --git a/models/oAuth2Microsoft.go b/models/oAuth2Microsoft.go new file mode 100644 index 00000000..35c38a77 --- /dev/null +++ b/models/oAuth2Microsoft.go @@ -0,0 +1,42 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Microsoft Model +type OAuth2Microsoft struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Microsoft OAuth2 application ID. + ApplicationId string `json:"applicationId"` + // Microsoft OAuth2 application secret. + ApplicationSecret string `json:"applicationSecret"` + // Microsoft Entra ID tenant identifier. Use 'common', 'organizations', + // 'consumers' or a specific tenant ID. + Tenant string `json:"tenant"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Microsoft) New(data []byte) *OAuth2Microsoft { + model.data = data + return &model +} + +func (model *OAuth2Microsoft) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Microsoft_test.go b/models/oAuth2Microsoft_test.go new file mode 100644 index 00000000..188dee22 --- /dev/null +++ b/models/oAuth2Microsoft_test.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2MicrosoftModel(t *testing.T) { + model := OAuth2Microsoft{ Id: "github", Enabled: true, ApplicationId: "00001111-aaaa-2222-bbbb-3333cccc4444", ApplicationSecret: "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u", Tenant: "common", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Microsoft + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ApplicationId != model.ApplicationId { + t.Errorf("Expected ApplicationId %v, got %v", model.ApplicationId, result.ApplicationId) + } + if result.ApplicationSecret != model.ApplicationSecret { + t.Errorf("Expected ApplicationSecret %v, got %v", model.ApplicationSecret, result.ApplicationSecret) + } + if result.Tenant != model.Tenant { + t.Errorf("Expected Tenant %v, got %v", model.Tenant, result.Tenant) + }} diff --git a/models/oAuth2Notion.go b/models/oAuth2Notion.go new file mode 100644 index 00000000..2a0765d4 --- /dev/null +++ b/models/oAuth2Notion.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Notion Model +type OAuth2Notion struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Notion OAuth2 client ID. + OauthClientId string `json:"oauthClientId"` + // Notion OAuth2 client secret. + OauthClientSecret string `json:"oauthClientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Notion) New(data []byte) *OAuth2Notion { + model.data = data + return &model +} + +func (model *OAuth2Notion) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Notion_test.go b/models/oAuth2Notion_test.go new file mode 100644 index 00000000..37602278 --- /dev/null +++ b/models/oAuth2Notion_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2NotionModel(t *testing.T) { + model := OAuth2Notion{ Id: "github", Enabled: true, OauthClientId: "341d8700-0000-0000-0000-000000446ee3", OauthClientSecret: "secret_dLUr4b000000000000000000000000000000lFHAa9", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Notion + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.OauthClientId != model.OauthClientId { + t.Errorf("Expected OauthClientId %v, got %v", model.OauthClientId, result.OauthClientId) + } + if result.OauthClientSecret != model.OauthClientSecret { + t.Errorf("Expected OauthClientSecret %v, got %v", model.OauthClientSecret, result.OauthClientSecret) + }} diff --git a/models/oAuth2Oidc.go b/models/oAuth2Oidc.go new file mode 100644 index 00000000..49297d03 --- /dev/null +++ b/models/oAuth2Oidc.go @@ -0,0 +1,48 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Oidc Model +type OAuth2Oidc struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // OpenID Connect OAuth2 client ID. + ClientId string `json:"clientId"` + // OpenID Connect OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + // OpenID Connect well-known configuration URL. When set, authorization, + // token, and user info endpoints can be discovered automatically. + WellKnownURL string `json:"wellKnownURL"` + // OpenID Connect authorization endpoint URL. + AuthorizationURL string `json:"authorizationURL"` + // OpenID Connect token endpoint URL. + TokenURL string `json:"tokenURL"` + // OpenID Connect user info endpoint URL. + UserInfoURL string `json:"userInfoURL"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Oidc) New(data []byte) *OAuth2Oidc { + model.data = data + return &model +} + +func (model *OAuth2Oidc) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Oidc_test.go b/models/oAuth2Oidc_test.go new file mode 100644 index 00000000..c9229d87 --- /dev/null +++ b/models/oAuth2Oidc_test.go @@ -0,0 +1,44 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2OidcModel(t *testing.T) { + model := OAuth2Oidc{ Id: "github", Enabled: true, ClientId: "qibI2x0000000000000000000000000006L2YFoG", ClientSecret: "Ah68ed000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003qpcHV", WellKnownURL: "https://myoauth.com/.well-known/openid-configuration", AuthorizationURL: "https://myoauth.com/oauth2/authorize", TokenURL: "https://myoauth.com/oauth2/token", UserInfoURL: "https://myoauth.com/oauth2/userinfo", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Oidc + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + } + if result.WellKnownURL != model.WellKnownURL { + t.Errorf("Expected WellKnownURL %v, got %v", model.WellKnownURL, result.WellKnownURL) + } + if result.AuthorizationURL != model.AuthorizationURL { + t.Errorf("Expected AuthorizationURL %v, got %v", model.AuthorizationURL, result.AuthorizationURL) + } + if result.TokenURL != model.TokenURL { + t.Errorf("Expected TokenURL %v, got %v", model.TokenURL, result.TokenURL) + } + if result.UserInfoURL != model.UserInfoURL { + t.Errorf("Expected UserInfoURL %v, got %v", model.UserInfoURL, result.UserInfoURL) + }} diff --git a/models/oAuth2Okta.go b/models/oAuth2Okta.go new file mode 100644 index 00000000..88101acb --- /dev/null +++ b/models/oAuth2Okta.go @@ -0,0 +1,43 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Okta Model +type OAuth2Okta struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Okta OAuth2 client ID. + ClientId string `json:"clientId"` + // Okta OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + // Okta OAuth2 domain. + Domain string `json:"domain"` + // Okta OAuth2 authorization server ID. + AuthorizationServerId string `json:"authorizationServerId"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Okta) New(data []byte) *OAuth2Okta { + model.data = data + return &model +} + +func (model *OAuth2Okta) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Okta_test.go b/models/oAuth2Okta_test.go new file mode 100644 index 00000000..46c5212d --- /dev/null +++ b/models/oAuth2Okta_test.go @@ -0,0 +1,38 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2OktaModel(t *testing.T) { + model := OAuth2Okta{ Id: "github", Enabled: true, ClientId: "0oa00000000000000698", ClientSecret: "Kiq0000000000000000000000000000000000000-00000000000H2L5-3SJ-vRV", Domain: "trial-6400025.okta.com", AuthorizationServerId: "aus000000000000000h7z", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Okta + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + } + if result.Domain != model.Domain { + t.Errorf("Expected Domain %v, got %v", model.Domain, result.Domain) + } + if result.AuthorizationServerId != model.AuthorizationServerId { + t.Errorf("Expected AuthorizationServerId %v, got %v", model.AuthorizationServerId, result.AuthorizationServerId) + }} diff --git a/models/oAuth2Paypal.go b/models/oAuth2Paypal.go new file mode 100644 index 00000000..3800974b --- /dev/null +++ b/models/oAuth2Paypal.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Paypal Model +type OAuth2Paypal struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // PayPal OAuth2 client ID. + ClientId string `json:"clientId"` + // PayPal OAuth2 secret key. + SecretKey string `json:"secretKey"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Paypal) New(data []byte) *OAuth2Paypal { + model.data = data + return &model +} + +func (model *OAuth2Paypal) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Paypal_test.go b/models/oAuth2Paypal_test.go new file mode 100644 index 00000000..b3826177 --- /dev/null +++ b/models/oAuth2Paypal_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2PaypalModel(t *testing.T) { + model := OAuth2Paypal{ Id: "github", Enabled: true, ClientId: "AdhIEG7-000000000000-0000000000000000000000000000000-0000000000000000000000-2pyB", SecretKey: "EH8KCXtew--000000000000000000000000000000000000000_C-1_5UP_000000000000000CB7KDp", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Paypal + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.SecretKey != model.SecretKey { + t.Errorf("Expected SecretKey %v, got %v", model.SecretKey, result.SecretKey) + }} diff --git a/models/oAuth2Podio.go b/models/oAuth2Podio.go new file mode 100644 index 00000000..a7a46ca4 --- /dev/null +++ b/models/oAuth2Podio.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Podio Model +type OAuth2Podio struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Podio OAuth2 client ID. + ClientId string `json:"clientId"` + // Podio OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Podio) New(data []byte) *OAuth2Podio { + model.data = data + return &model +} + +func (model *OAuth2Podio) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Podio_test.go b/models/oAuth2Podio_test.go new file mode 100644 index 00000000..2b20d03d --- /dev/null +++ b/models/oAuth2Podio_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2PodioModel(t *testing.T) { + model := OAuth2Podio{ Id: "github", Enabled: true, ClientId: "appwrite-oauth-test-app", ClientSecret: "Rn247T0000000000000000000000000000000000000000000000000000W2zWTN", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Podio + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2ProviderList.go b/models/oAuth2ProviderList.go new file mode 100644 index 00000000..acab50a9 --- /dev/null +++ b/models/oAuth2ProviderList.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2ProvidersList Model +type OAuth2ProviderList struct { + // Total number of OAuth2 providers in the given project. + Total int `json:"total"` + // List of OAuth2 providers. + Providers []interface{} `json:"providers"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2ProviderList) New(data []byte) *OAuth2ProviderList { + model.data = data + return &model +} + +func (model *OAuth2ProviderList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2ProviderList_test.go b/models/oAuth2ProviderList_test.go new file mode 100644 index 00000000..3f3560dc --- /dev/null +++ b/models/oAuth2ProviderList_test.go @@ -0,0 +1,23 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2ProviderListModel(t *testing.T) { + model := OAuth2ProviderList{ Total: 5, Providers: []interface{}{}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2ProviderList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/oAuth2Salesforce.go b/models/oAuth2Salesforce.go new file mode 100644 index 00000000..c2d2f1f8 --- /dev/null +++ b/models/oAuth2Salesforce.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Salesforce Model +type OAuth2Salesforce struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Salesforce OAuth2 consumer key. + CustomerKey string `json:"customerKey"` + // Salesforce OAuth2 consumer secret. + CustomerSecret string `json:"customerSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Salesforce) New(data []byte) *OAuth2Salesforce { + model.data = data + return &model +} + +func (model *OAuth2Salesforce) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Salesforce_test.go b/models/oAuth2Salesforce_test.go new file mode 100644 index 00000000..6f9c818f --- /dev/null +++ b/models/oAuth2Salesforce_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2SalesforceModel(t *testing.T) { + model := OAuth2Salesforce{ Id: "github", Enabled: true, CustomerKey: "3MVG9I0000000000000000000000000000000000000000000000000000000000000000000000000C5Aejq", CustomerSecret: "3w000000000000e2", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Salesforce + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.CustomerKey != model.CustomerKey { + t.Errorf("Expected CustomerKey %v, got %v", model.CustomerKey, result.CustomerKey) + } + if result.CustomerSecret != model.CustomerSecret { + t.Errorf("Expected CustomerSecret %v, got %v", model.CustomerSecret, result.CustomerSecret) + }} diff --git a/models/oAuth2Slack.go b/models/oAuth2Slack.go new file mode 100644 index 00000000..fc212240 --- /dev/null +++ b/models/oAuth2Slack.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Slack Model +type OAuth2Slack struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Slack OAuth2 client ID. + ClientId string `json:"clientId"` + // Slack OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Slack) New(data []byte) *OAuth2Slack { + model.data = data + return &model +} + +func (model *OAuth2Slack) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Slack_test.go b/models/oAuth2Slack_test.go new file mode 100644 index 00000000..417079dc --- /dev/null +++ b/models/oAuth2Slack_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2SlackModel(t *testing.T) { + model := OAuth2Slack{ Id: "github", Enabled: true, ClientId: "23000000089.15000000000023", ClientSecret: "81656000000000000000000000f3d2fd", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Slack + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Spotify.go b/models/oAuth2Spotify.go new file mode 100644 index 00000000..edf21096 --- /dev/null +++ b/models/oAuth2Spotify.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Spotify Model +type OAuth2Spotify struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Spotify OAuth2 client ID. + ClientId string `json:"clientId"` + // Spotify OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Spotify) New(data []byte) *OAuth2Spotify { + model.data = data + return &model +} + +func (model *OAuth2Spotify) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Spotify_test.go b/models/oAuth2Spotify_test.go new file mode 100644 index 00000000..5c3ec029 --- /dev/null +++ b/models/oAuth2Spotify_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2SpotifyModel(t *testing.T) { + model := OAuth2Spotify{ Id: "github", Enabled: true, ClientId: "6ec271000000000000000000009beace", ClientSecret: "db068a000000000000000000008b5b9f", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Spotify + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Stripe.go b/models/oAuth2Stripe.go new file mode 100644 index 00000000..44c9b0ea --- /dev/null +++ b/models/oAuth2Stripe.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Stripe Model +type OAuth2Stripe struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Stripe OAuth2 client ID. + ClientId string `json:"clientId"` + // Stripe OAuth2 API secret key. + ApiSecretKey string `json:"apiSecretKey"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Stripe) New(data []byte) *OAuth2Stripe { + model.data = data + return &model +} + +func (model *OAuth2Stripe) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Stripe_test.go b/models/oAuth2Stripe_test.go new file mode 100644 index 00000000..3bda33de --- /dev/null +++ b/models/oAuth2Stripe_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2StripeModel(t *testing.T) { + model := OAuth2Stripe{ Id: "github", Enabled: true, ClientId: "ca_UKibXX0000000000000000000006byvR", ApiSecretKey: "sk_51SfOd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000QGWYfp", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Stripe + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ApiSecretKey != model.ApiSecretKey { + t.Errorf("Expected ApiSecretKey %v, got %v", model.ApiSecretKey, result.ApiSecretKey) + }} diff --git a/models/oAuth2Tradeshift.go b/models/oAuth2Tradeshift.go new file mode 100644 index 00000000..42b8c6d4 --- /dev/null +++ b/models/oAuth2Tradeshift.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Tradeshift Model +type OAuth2Tradeshift struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Tradeshift OAuth2 client ID. + Oauth2ClientId string `json:"oauth2ClientId"` + // Tradeshift OAuth2 client secret. + Oauth2ClientSecret string `json:"oauth2ClientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Tradeshift) New(data []byte) *OAuth2Tradeshift { + model.data = data + return &model +} + +func (model *OAuth2Tradeshift) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Tradeshift_test.go b/models/oAuth2Tradeshift_test.go new file mode 100644 index 00000000..f7eec444 --- /dev/null +++ b/models/oAuth2Tradeshift_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2TradeshiftModel(t *testing.T) { + model := OAuth2Tradeshift{ Id: "github", Enabled: true, Oauth2ClientId: "appwrite-test-org.appwrite-test-app", Oauth2ClientSecret: "7cb52700-0000-0000-0000-000000ca5b83", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Tradeshift + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.Oauth2ClientId != model.Oauth2ClientId { + t.Errorf("Expected Oauth2ClientId %v, got %v", model.Oauth2ClientId, result.Oauth2ClientId) + } + if result.Oauth2ClientSecret != model.Oauth2ClientSecret { + t.Errorf("Expected Oauth2ClientSecret %v, got %v", model.Oauth2ClientSecret, result.Oauth2ClientSecret) + }} diff --git a/models/oAuth2Twitch.go b/models/oAuth2Twitch.go new file mode 100644 index 00000000..9d8abade --- /dev/null +++ b/models/oAuth2Twitch.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Twitch Model +type OAuth2Twitch struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Twitch OAuth2 client ID. + ClientId string `json:"clientId"` + // Twitch OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Twitch) New(data []byte) *OAuth2Twitch { + model.data = data + return &model +} + +func (model *OAuth2Twitch) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Twitch_test.go b/models/oAuth2Twitch_test.go new file mode 100644 index 00000000..ba5c231b --- /dev/null +++ b/models/oAuth2Twitch_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2TwitchModel(t *testing.T) { + model := OAuth2Twitch{ Id: "github", Enabled: true, ClientId: "vvi0in000000000000000000ikmt9p", ClientSecret: "pmapue000000000000000000zylw3v", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Twitch + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2WordPress.go b/models/oAuth2WordPress.go new file mode 100644 index 00000000..7c0d6ea9 --- /dev/null +++ b/models/oAuth2WordPress.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2WordPress Model +type OAuth2WordPress struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // WordPress OAuth2 client ID. + ClientId string `json:"clientId"` + // WordPress OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2WordPress) New(data []byte) *OAuth2WordPress { + model.data = data + return &model +} + +func (model *OAuth2WordPress) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2WordPress_test.go b/models/oAuth2WordPress_test.go new file mode 100644 index 00000000..726a697f --- /dev/null +++ b/models/oAuth2WordPress_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2WordPressModel(t *testing.T) { + model := OAuth2WordPress{ Id: "github", Enabled: true, ClientId: "130005", ClientSecret: "PlBfJS0000000000000000000000000000000000000000000000000000EdUZJk", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2WordPress + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2X.go b/models/oAuth2X.go new file mode 100644 index 00000000..2bc3b856 --- /dev/null +++ b/models/oAuth2X.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2X Model +type OAuth2X struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // X OAuth2 customer key. + CustomerKey string `json:"customerKey"` + // X OAuth2 secret key. + SecretKey string `json:"secretKey"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2X) New(data []byte) *OAuth2X { + model.data = data + return &model +} + +func (model *OAuth2X) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2X_test.go b/models/oAuth2X_test.go new file mode 100644 index 00000000..e8b68fc1 --- /dev/null +++ b/models/oAuth2X_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2XModel(t *testing.T) { + model := OAuth2X{ Id: "github", Enabled: true, CustomerKey: "slzZV0000000000000NFLaWT", SecretKey: "tkEPkp00000000000000000000000000000000000000FTxbI9", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2X + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.CustomerKey != model.CustomerKey { + t.Errorf("Expected CustomerKey %v, got %v", model.CustomerKey, result.CustomerKey) + } + if result.SecretKey != model.SecretKey { + t.Errorf("Expected SecretKey %v, got %v", model.SecretKey, result.SecretKey) + }} diff --git a/models/oAuth2Yahoo.go b/models/oAuth2Yahoo.go new file mode 100644 index 00000000..63548e05 --- /dev/null +++ b/models/oAuth2Yahoo.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Yahoo Model +type OAuth2Yahoo struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Yahoo OAuth2 client ID. + ClientId string `json:"clientId"` + // Yahoo OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Yahoo) New(data []byte) *OAuth2Yahoo { + model.data = data + return &model +} + +func (model *OAuth2Yahoo) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Yahoo_test.go b/models/oAuth2Yahoo_test.go new file mode 100644 index 00000000..c0adc5e3 --- /dev/null +++ b/models/oAuth2Yahoo_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2YahooModel(t *testing.T) { + model := OAuth2Yahoo{ Id: "github", Enabled: true, ClientId: "dj0yJm000000000000000000000000000000000000000000000000000000000000000000000000000000000000Z4PWRm", ClientSecret: "cf978f0000000000000000000000000000c5e2e9", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Yahoo + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Yandex.go b/models/oAuth2Yandex.go new file mode 100644 index 00000000..d0a4e43e --- /dev/null +++ b/models/oAuth2Yandex.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Yandex Model +type OAuth2Yandex struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Yandex OAuth2 client ID. + ClientId string `json:"clientId"` + // Yandex OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Yandex) New(data []byte) *OAuth2Yandex { + model.data = data + return &model +} + +func (model *OAuth2Yandex) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Yandex_test.go b/models/oAuth2Yandex_test.go new file mode 100644 index 00000000..a6e15a7a --- /dev/null +++ b/models/oAuth2Yandex_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2YandexModel(t *testing.T) { + model := OAuth2Yandex{ Id: "github", Enabled: true, ClientId: "6a8a6a0000000000000000000091483c", ClientSecret: "bbf98500000000000000000000c75a63", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Yandex + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Zoho.go b/models/oAuth2Zoho.go new file mode 100644 index 00000000..ecf92618 --- /dev/null +++ b/models/oAuth2Zoho.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Zoho Model +type OAuth2Zoho struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Zoho OAuth2 client ID. + ClientId string `json:"clientId"` + // Zoho OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Zoho) New(data []byte) *OAuth2Zoho { + model.data = data + return &model +} + +func (model *OAuth2Zoho) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Zoho_test.go b/models/oAuth2Zoho_test.go new file mode 100644 index 00000000..8265b406 --- /dev/null +++ b/models/oAuth2Zoho_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2ZohoModel(t *testing.T) { + model := OAuth2Zoho{ Id: "github", Enabled: true, ClientId: "1000.83C178000000000000000000RPNX0B", ClientSecret: "fb5cac000000000000000000000000000000a68f6e", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Zoho + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/oAuth2Zoom.go b/models/oAuth2Zoom.go new file mode 100644 index 00000000..ea9a77d8 --- /dev/null +++ b/models/oAuth2Zoom.go @@ -0,0 +1,39 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// OAuth2Zoom Model +type OAuth2Zoom struct { + // OAuth2 provider ID. + Id string `json:"$id"` + // OAuth2 provider is active and can be used to create sessions. + Enabled bool `json:"enabled"` + // Zoom OAuth2 client ID. + ClientId string `json:"clientId"` + // Zoom OAuth2 client secret. + ClientSecret string `json:"clientSecret"` + + // Used by Decode() method + data []byte +} + +func (model OAuth2Zoom) New(data []byte) *OAuth2Zoom { + model.data = data + return &model +} + +func (model *OAuth2Zoom) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/oAuth2Zoom_test.go b/models/oAuth2Zoom_test.go new file mode 100644 index 00000000..fe4b7e35 --- /dev/null +++ b/models/oAuth2Zoom_test.go @@ -0,0 +1,32 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestOAuth2ZoomModel(t *testing.T) { + model := OAuth2Zoom{ Id: "github", Enabled: true, ClientId: "QMAC00000000000000w0AQ", ClientSecret: "GAWsG4000000000000000000007U01ON", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result OAuth2Zoom + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + } + if result.ClientId != model.ClientId { + t.Errorf("Expected ClientId %v, got %v", model.ClientId, result.ClientId) + } + if result.ClientSecret != model.ClientSecret { + t.Errorf("Expected ClientSecret %v, got %v", model.ClientSecret, result.ClientSecret) + }} diff --git a/models/policyList.go b/models/policyList.go new file mode 100644 index 00000000..a6ce6ac3 --- /dev/null +++ b/models/policyList.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PoliciesList Model +type PolicyList struct { + // Total number of policies in the given project. + Total int `json:"total"` + // List of policies. + Policies []interface{} `json:"policies"` + + // Used by Decode() method + data []byte +} + +func (model PolicyList) New(data []byte) *PolicyList { + model.data = data + return &model +} + +func (model *PolicyList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/policyList_test.go b/models/policyList_test.go new file mode 100644 index 00000000..d030db26 --- /dev/null +++ b/models/policyList_test.go @@ -0,0 +1,23 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPolicyListModel(t *testing.T) { + model := PolicyList{ Total: 9, Policies: []interface{}{}, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PolicyList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/policyMembershipPrivacy.go b/models/policyMembershipPrivacy.go new file mode 100644 index 00000000..73bdc8e3 --- /dev/null +++ b/models/policyMembershipPrivacy.go @@ -0,0 +1,43 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PolicyMembershipPrivacy Model +type PolicyMembershipPrivacy struct { + // Policy ID. + Id string `json:"$id"` + // Whether user ID is visible in memberships. + UserId bool `json:"userId"` + // Whether user email is visible in memberships. + UserEmail bool `json:"userEmail"` + // Whether user phone is visible in memberships. + UserPhone bool `json:"userPhone"` + // Whether user name is visible in memberships. + UserName bool `json:"userName"` + // Whether user MFA status is visible in memberships. + UserMFA bool `json:"userMFA"` + + // Used by Decode() method + data []byte +} + +func (model PolicyMembershipPrivacy) New(data []byte) *PolicyMembershipPrivacy { + model.data = data + return &model +} + +func (model *PolicyMembershipPrivacy) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/policyMembershipPrivacy_test.go b/models/policyMembershipPrivacy_test.go new file mode 100644 index 00000000..a3d48a16 --- /dev/null +++ b/models/policyMembershipPrivacy_test.go @@ -0,0 +1,38 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPolicyMembershipPrivacyModel(t *testing.T) { + model := PolicyMembershipPrivacy{ Id: "password-dictionary", UserId: true, UserEmail: true, UserPhone: true, UserName: true, UserMFA: true, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PolicyMembershipPrivacy + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.UserEmail != model.UserEmail { + t.Errorf("Expected UserEmail %v, got %v", model.UserEmail, result.UserEmail) + } + if result.UserPhone != model.UserPhone { + t.Errorf("Expected UserPhone %v, got %v", model.UserPhone, result.UserPhone) + } + if result.UserName != model.UserName { + t.Errorf("Expected UserName %v, got %v", model.UserName, result.UserName) + } + if result.UserMFA != model.UserMFA { + t.Errorf("Expected UserMFA %v, got %v", model.UserMFA, result.UserMFA) + }} diff --git a/models/policyPasswordDictionary.go b/models/policyPasswordDictionary.go new file mode 100644 index 00000000..016f0ecd --- /dev/null +++ b/models/policyPasswordDictionary.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PolicyPasswordDictionary Model +type PolicyPasswordDictionary struct { + // Policy ID. + Id string `json:"$id"` + // Whether password dictionary policy is enabled. + Enabled bool `json:"enabled"` + + // Used by Decode() method + data []byte +} + +func (model PolicyPasswordDictionary) New(data []byte) *PolicyPasswordDictionary { + model.data = data + return &model +} + +func (model *PolicyPasswordDictionary) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/policyPasswordDictionary_test.go b/models/policyPasswordDictionary_test.go new file mode 100644 index 00000000..50fd1386 --- /dev/null +++ b/models/policyPasswordDictionary_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPolicyPasswordDictionaryModel(t *testing.T) { + model := PolicyPasswordDictionary{ Id: "password-dictionary", Enabled: true, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PolicyPasswordDictionary + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + }} diff --git a/models/policyPasswordHistory.go b/models/policyPasswordHistory.go new file mode 100644 index 00000000..b715fc0a --- /dev/null +++ b/models/policyPasswordHistory.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PolicyPasswordHistory Model +type PolicyPasswordHistory struct { + // Policy ID. + Id string `json:"$id"` + // Password history length. A value of 0 means the policy is disabled. + Total int `json:"total"` + + // Used by Decode() method + data []byte +} + +func (model PolicyPasswordHistory) New(data []byte) *PolicyPasswordHistory { + model.data = data + return &model +} + +func (model *PolicyPasswordHistory) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/policyPasswordHistory_test.go b/models/policyPasswordHistory_test.go new file mode 100644 index 00000000..686b01d5 --- /dev/null +++ b/models/policyPasswordHistory_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPolicyPasswordHistoryModel(t *testing.T) { + model := PolicyPasswordHistory{ Id: "password-dictionary", Total: 5, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PolicyPasswordHistory + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/policyPasswordPersonalData.go b/models/policyPasswordPersonalData.go new file mode 100644 index 00000000..9a5ee2a1 --- /dev/null +++ b/models/policyPasswordPersonalData.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PolicyPasswordPersonalData Model +type PolicyPasswordPersonalData struct { + // Policy ID. + Id string `json:"$id"` + // Whether password personal data policy is enabled. + Enabled bool `json:"enabled"` + + // Used by Decode() method + data []byte +} + +func (model PolicyPasswordPersonalData) New(data []byte) *PolicyPasswordPersonalData { + model.data = data + return &model +} + +func (model *PolicyPasswordPersonalData) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/policyPasswordPersonalData_test.go b/models/policyPasswordPersonalData_test.go new file mode 100644 index 00000000..654213ac --- /dev/null +++ b/models/policyPasswordPersonalData_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPolicyPasswordPersonalDataModel(t *testing.T) { + model := PolicyPasswordPersonalData{ Id: "password-dictionary", Enabled: true, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PolicyPasswordPersonalData + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + }} diff --git a/models/policySessionAlert.go b/models/policySessionAlert.go new file mode 100644 index 00000000..768dc1ec --- /dev/null +++ b/models/policySessionAlert.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PolicySessionAlert Model +type PolicySessionAlert struct { + // Policy ID. + Id string `json:"$id"` + // Whether session alert policy is enabled. + Enabled bool `json:"enabled"` + + // Used by Decode() method + data []byte +} + +func (model PolicySessionAlert) New(data []byte) *PolicySessionAlert { + model.data = data + return &model +} + +func (model *PolicySessionAlert) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/policySessionAlert_test.go b/models/policySessionAlert_test.go new file mode 100644 index 00000000..f0b936f4 --- /dev/null +++ b/models/policySessionAlert_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPolicySessionAlertModel(t *testing.T) { + model := PolicySessionAlert{ Id: "password-dictionary", Enabled: true, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PolicySessionAlert + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + }} diff --git a/models/policySessionDuration.go b/models/policySessionDuration.go new file mode 100644 index 00000000..c25521b7 --- /dev/null +++ b/models/policySessionDuration.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PolicySessionDuration Model +type PolicySessionDuration struct { + // Policy ID. + Id string `json:"$id"` + // Session duration in seconds. + Duration int `json:"duration"` + + // Used by Decode() method + data []byte +} + +func (model PolicySessionDuration) New(data []byte) *PolicySessionDuration { + model.data = data + return &model +} + +func (model *PolicySessionDuration) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/policySessionDuration_test.go b/models/policySessionDuration_test.go new file mode 100644 index 00000000..4305f60b --- /dev/null +++ b/models/policySessionDuration_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPolicySessionDurationModel(t *testing.T) { + model := PolicySessionDuration{ Id: "password-dictionary", Duration: 3600, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PolicySessionDuration + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Duration != model.Duration { + t.Errorf("Expected Duration %v, got %v", model.Duration, result.Duration) + }} diff --git a/models/policySessionInvalidation.go b/models/policySessionInvalidation.go new file mode 100644 index 00000000..f3af573f --- /dev/null +++ b/models/policySessionInvalidation.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PolicySessionInvalidation Model +type PolicySessionInvalidation struct { + // Policy ID. + Id string `json:"$id"` + // Whether session invalidation policy is enabled. + Enabled bool `json:"enabled"` + + // Used by Decode() method + data []byte +} + +func (model PolicySessionInvalidation) New(data []byte) *PolicySessionInvalidation { + model.data = data + return &model +} + +func (model *PolicySessionInvalidation) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/policySessionInvalidation_test.go b/models/policySessionInvalidation_test.go new file mode 100644 index 00000000..21b688b9 --- /dev/null +++ b/models/policySessionInvalidation_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPolicySessionInvalidationModel(t *testing.T) { + model := PolicySessionInvalidation{ Id: "password-dictionary", Enabled: true, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PolicySessionInvalidation + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Enabled != model.Enabled { + t.Errorf("Expected Enabled %v, got %v", model.Enabled, result.Enabled) + }} diff --git a/models/policySessionLimit.go b/models/policySessionLimit.go new file mode 100644 index 00000000..f5893c78 --- /dev/null +++ b/models/policySessionLimit.go @@ -0,0 +1,36 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PolicySessionLimit Model +type PolicySessionLimit struct { + // Policy ID. + Id string `json:"$id"` + // Maximum number of sessions allowed per user. A value of 0 means the policy + // is disabled. + Total int `json:"total"` + + // Used by Decode() method + data []byte +} + +func (model PolicySessionLimit) New(data []byte) *PolicySessionLimit { + model.data = data + return &model +} + +func (model *PolicySessionLimit) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/policySessionLimit_test.go b/models/policySessionLimit_test.go new file mode 100644 index 00000000..2f9985ed --- /dev/null +++ b/models/policySessionLimit_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPolicySessionLimitModel(t *testing.T) { + model := PolicySessionLimit{ Id: "password-dictionary", Total: 10, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PolicySessionLimit + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/policyUserLimit.go b/models/policyUserLimit.go new file mode 100644 index 00000000..e61e5455 --- /dev/null +++ b/models/policyUserLimit.go @@ -0,0 +1,36 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PolicyUserLimit Model +type PolicyUserLimit struct { + // Policy ID. + Id string `json:"$id"` + // Maximum number of users allowed in the project. A value of 0 means the + // policy is disabled. + Total int `json:"total"` + + // Used by Decode() method + data []byte +} + +func (model PolicyUserLimit) New(data []byte) *PolicyUserLimit { + model.data = data + return &model +} + +func (model *PolicyUserLimit) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/policyUserLimit_test.go b/models/policyUserLimit_test.go new file mode 100644 index 00000000..8cc33415 --- /dev/null +++ b/models/policyUserLimit_test.go @@ -0,0 +1,26 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPolicyUserLimitModel(t *testing.T) { + model := PolicyUserLimit{ Id: "password-dictionary", Total: 100, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PolicyUserLimit + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/project.go b/models/project.go index 82f2d3f7..f1740cc0 100644 --- a/models/project.go +++ b/models/project.go @@ -70,6 +70,10 @@ type Project struct { AuthMembershipsUserEmail bool `json:"authMembershipsUserEmail"` // Whether or not to show user MFA status in the teams membership response. AuthMembershipsMfa bool `json:"authMembershipsMfa"` + // Whether or not to show user IDs in the teams membership response. + AuthMembershipsUserId bool `json:"authMembershipsUserId"` + // Whether or not to show user phone numbers in the teams membership response. + AuthMembershipsUserPhone bool `json:"authMembershipsUserPhone"` // Whether or not all existing sessions should be invalidated on password // change AuthInvalidateSessions bool `json:"authInvalidateSessions"` @@ -89,15 +93,18 @@ type Project struct { SmtpSenderName string `json:"smtpSenderName"` // SMTP sender email SmtpSenderEmail string `json:"smtpSenderEmail"` + // SMTP reply to name + SmtpReplyToName string `json:"smtpReplyToName"` // SMTP reply to email - SmtpReplyTo string `json:"smtpReplyTo"` + SmtpReplyToEmail string `json:"smtpReplyToEmail"` // SMTP server host name SmtpHost string `json:"smtpHost"` // SMTP server port SmtpPort int `json:"smtpPort"` // SMTP server username SmtpUsername string `json:"smtpUsername"` - // SMTP server password + // SMTP server password. This property is write-only and always returned + // empty. SmtpPassword string `json:"smtpPassword"` // SMTP server secure protocol SmtpSecure string `json:"smtpSecure"` diff --git a/models/project_test.go b/models/project_test.go index 80a75cee..7b0e2040 100644 --- a/models/project_test.go +++ b/models/project_test.go @@ -6,12 +6,12 @@ import ( ) func TestProjectModel(t *testing.T) { - model := Project{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "New Project", Description: "This is a new project.", TeamId: "1592981250", Logo: "5f5c451b403cb", Url: "5f5c451b403cb", LegalName: "Company LTD.", LegalCountry: "US", LegalState: "New York", LegalCity: "New York City.", LegalAddress: "620 Eighth Avenue, New York, NY 10018", LegalTaxId: "131102020", AuthDuration: 60, AuthLimit: 100, AuthSessionsLimit: 10, AuthPasswordHistory: 5, AuthPasswordDictionary: true, AuthPersonalDataCheck: true, AuthDisposableEmails: true, AuthCanonicalEmails: true, AuthFreeEmails: true, AuthMockNumbers: []MockNumber{MockNumber{ Phone: "+1612842323", Otp: "123456", }, - }, AuthSessionAlerts: true, AuthMembershipsUserName: true, AuthMembershipsUserEmail: true, AuthMembershipsMfa: true, AuthInvalidateSessions: true, OAuthProviders: []AuthProvider{AuthProvider{ Key: "github", Name: "GitHub", AppId: "259125845563242502", Secret: "Bpw_g9c2TGXxfgLshDbSaL8tsCcqgczQ", Enabled: true, }, + model := Project{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "New Project", Description: "This is a new project.", TeamId: "1592981250", Logo: "5f5c451b403cb", Url: "5f5c451b403cb", LegalName: "Company LTD.", LegalCountry: "US", LegalState: "New York", LegalCity: "New York City.", LegalAddress: "620 Eighth Avenue, New York, NY 10018", LegalTaxId: "131102020", AuthDuration: 60, AuthLimit: 100, AuthSessionsLimit: 10, AuthPasswordHistory: 5, AuthPasswordDictionary: true, AuthPersonalDataCheck: true, AuthDisposableEmails: true, AuthCanonicalEmails: true, AuthFreeEmails: true, AuthMockNumbers: []MockNumber{MockNumber{ Number: "+1612842323", Otp: "123456", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", }, + }, AuthSessionAlerts: true, AuthMembershipsUserName: true, AuthMembershipsUserEmail: true, AuthMembershipsMfa: true, AuthMembershipsUserId: true, AuthMembershipsUserPhone: true, AuthInvalidateSessions: true, OAuthProviders: []AuthProvider{AuthProvider{ Key: "github", Name: "GitHub", AppId: "259125845563242502", Secret: "string", Enabled: true, }, }, Platforms: []interface{}{}, Webhooks: []Webhook{Webhook{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "My Webhook", Url: "https://example.com/webhook", Events: []string{"test"}, Tls: true, AuthUsername: "username", AuthPassword: "password", Secret: "ad3d581ca230e2b7059c545e5a", Enabled: true, Logs: "Failed to connect to remote server.", Attempts: 10, }, }, Keys: []Key{Key{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "My API Key", Expire: "2020-10-15T06:38:00.000+00:00", Scopes: []string{"test"}, Secret: "919c2d18fb5d4...a2ae413da83346ad2", AccessedAt: "2020-10-15T06:38:00.000+00:00", Sdks: []string{"test"}, }, }, DevKeys: []DevKey{DevKey{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Name: "Dev API Key", Expire: "2020-10-15T06:38:00.000+00:00", Secret: "919c2d18fb5d4...a2ae413da83346ad2", AccessedAt: "2020-10-15T06:38:00.000+00:00", Sdks: []string{"test"}, }, - }, SmtpEnabled: true, SmtpSenderName: "John Appwrite", SmtpSenderEmail: "john@appwrite.io", SmtpReplyTo: "support@appwrite.io", SmtpHost: "mail.appwrite.io", SmtpPort: 25, SmtpUsername: "emailuser", SmtpPassword: "securepassword", SmtpSecure: "tls", PingCount: 1, PingedAt: "2020-10-15T06:38:00.000+00:00", Labels: []string{"test"}, Status: "active", AuthEmailPassword: true, AuthUsersAuthMagicURL: true, AuthEmailOtp: true, AuthAnonymous: true, AuthInvites: true, AuthJWT: true, AuthPhone: true, ServiceStatusForAccount: true, ServiceStatusForAvatars: true, ServiceStatusForDatabases: true, ServiceStatusForTablesdb: true, ServiceStatusForLocale: true, ServiceStatusForHealth: true, ServiceStatusForProject: true, ServiceStatusForStorage: true, ServiceStatusForTeams: true, ServiceStatusForUsers: true, ServiceStatusForVcs: true, ServiceStatusForSites: true, ServiceStatusForFunctions: true, ServiceStatusForProxy: true, ServiceStatusForGraphql: true, ServiceStatusForMigrations: true, ServiceStatusForMessaging: true, ProtocolStatusForRest: true, ProtocolStatusForGraphql: true, ProtocolStatusForWebsocket: true, Region: "fra", BillingLimits: BillingLimits{ Bandwidth: 5, Storage: 150, Users: 200000, Executions: 750000, GBHours: 100, ImageTransformations: 100, AuthPhone: 10, BudgetLimit: 100, }, Blocks: []Block{Block{ CreatedAt: "2020-10-15T06:38:00.000+00:00", ResourceType: "project", ResourceId: "5e5ea5c16897e", }, + }, SmtpEnabled: true, SmtpSenderName: "John Appwrite", SmtpSenderEmail: "john@appwrite.io", SmtpReplyToName: "Support Team", SmtpReplyToEmail: "support@appwrite.io", SmtpHost: "mail.appwrite.io", SmtpPort: 25, SmtpUsername: "emailuser", SmtpPassword: "string", SmtpSecure: "tls", PingCount: 1, PingedAt: "2020-10-15T06:38:00.000+00:00", Labels: []string{"test"}, Status: "active", AuthEmailPassword: true, AuthUsersAuthMagicURL: true, AuthEmailOtp: true, AuthAnonymous: true, AuthInvites: true, AuthJWT: true, AuthPhone: true, ServiceStatusForAccount: true, ServiceStatusForAvatars: true, ServiceStatusForDatabases: true, ServiceStatusForTablesdb: true, ServiceStatusForLocale: true, ServiceStatusForHealth: true, ServiceStatusForProject: true, ServiceStatusForStorage: true, ServiceStatusForTeams: true, ServiceStatusForUsers: true, ServiceStatusForVcs: true, ServiceStatusForSites: true, ServiceStatusForFunctions: true, ServiceStatusForProxy: true, ServiceStatusForGraphql: true, ServiceStatusForMigrations: true, ServiceStatusForMessaging: true, ProtocolStatusForRest: true, ProtocolStatusForGraphql: true, ProtocolStatusForWebsocket: true, Region: "fra", BillingLimits: BillingLimits{ Bandwidth: 5, Storage: 150, Users: 200000, Executions: 750000, GBHours: 100, ImageTransformations: 100, AuthPhone: 10, BudgetLimit: 100, }, Blocks: []Block{Block{ CreatedAt: "2020-10-15T06:38:00.000+00:00", ResourceType: "project", ResourceId: "5e5ea5c16897e", ProjectName: "My Project", Region: "fra", OrganizationName: "Acme Inc.", OrganizationId: "5e5ea5c16897e", BillingPlan: "pro", }, }, ConsoleAccessedAt: "2020-10-15T06:38:00.000+00:00", } data, err := json.Marshal(model) @@ -105,6 +105,12 @@ func TestProjectModel(t *testing.T) { if result.AuthMembershipsMfa != model.AuthMembershipsMfa { t.Errorf("Expected AuthMembershipsMfa %v, got %v", model.AuthMembershipsMfa, result.AuthMembershipsMfa) } + if result.AuthMembershipsUserId != model.AuthMembershipsUserId { + t.Errorf("Expected AuthMembershipsUserId %v, got %v", model.AuthMembershipsUserId, result.AuthMembershipsUserId) + } + if result.AuthMembershipsUserPhone != model.AuthMembershipsUserPhone { + t.Errorf("Expected AuthMembershipsUserPhone %v, got %v", model.AuthMembershipsUserPhone, result.AuthMembershipsUserPhone) + } if result.AuthInvalidateSessions != model.AuthInvalidateSessions { t.Errorf("Expected AuthInvalidateSessions %v, got %v", model.AuthInvalidateSessions, result.AuthInvalidateSessions) } @@ -117,8 +123,11 @@ func TestProjectModel(t *testing.T) { if result.SmtpSenderEmail != model.SmtpSenderEmail { t.Errorf("Expected SmtpSenderEmail %v, got %v", model.SmtpSenderEmail, result.SmtpSenderEmail) } - if result.SmtpReplyTo != model.SmtpReplyTo { - t.Errorf("Expected SmtpReplyTo %v, got %v", model.SmtpReplyTo, result.SmtpReplyTo) + if result.SmtpReplyToName != model.SmtpReplyToName { + t.Errorf("Expected SmtpReplyToName %v, got %v", model.SmtpReplyToName, result.SmtpReplyToName) + } + if result.SmtpReplyToEmail != model.SmtpReplyToEmail { + t.Errorf("Expected SmtpReplyToEmail %v, got %v", model.SmtpReplyToEmail, result.SmtpReplyToEmail) } if result.SmtpHost != model.SmtpHost { t.Errorf("Expected SmtpHost %v, got %v", model.SmtpHost, result.SmtpHost) diff --git a/models/proxyRule.go b/models/proxyRule.go new file mode 100644 index 00000000..e80f24b9 --- /dev/null +++ b/models/proxyRule.go @@ -0,0 +1,67 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// Rule Model +type ProxyRule struct { + // Rule ID. + Id string `json:"$id"` + // Rule creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Rule update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Domain name. + Domain string `json:"domain"` + // Action definition for the rule. Possible values are "api", "deployment", or + // "redirect" + Type string `json:"type"` + // Defines how the rule was created. Possible values are "manual" or + // "deployment" + Trigger string `json:"trigger"` + // URL to redirect to. Used if type is "redirect" + RedirectUrl string `json:"redirectUrl"` + // Status code to apply during redirect. Used if type is "redirect" + RedirectStatusCode int `json:"redirectStatusCode"` + // ID of deployment. Used if type is "deployment" + DeploymentId string `json:"deploymentId"` + // Type of deployment. Possible values are "function", "site". Used if rule's + // type is "deployment". + DeploymentResourceType string `json:"deploymentResourceType"` + // ID of deployment's resource (site or function ID). Used if type is + // "deployment" + DeploymentResourceId string `json:"deploymentResourceId"` + // Name of Git branch that updates rule. Used if type is "deployment" + DeploymentVcsProviderBranch string `json:"deploymentVcsProviderBranch"` + // Domain verification status. Possible values are "unverified", "verifying", + // "verified" + Status string `json:"status"` + // Logs from rule verification or certificate generation. Certificate + // generation logs are prioritized if both are available. + Logs string `json:"logs"` + // Certificate auto-renewal date in ISO 8601 format. + RenewAt string `json:"renewAt"` + + // Used by Decode() method + data []byte +} + +func (model ProxyRule) New(data []byte) *ProxyRule { + model.data = data + return &model +} + +func (model *ProxyRule) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/proxyRuleList.go b/models/proxyRuleList.go new file mode 100644 index 00000000..93bffdcb --- /dev/null +++ b/models/proxyRuleList.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// RuleList Model +type ProxyRuleList struct { + // Total number of rules that matched your query. + Total int `json:"total"` + // List of rules. + Rules []ProxyRule `json:"rules"` + + // Used by Decode() method + data []byte +} + +func (model ProxyRuleList) New(data []byte) *ProxyRuleList { + model.data = data + return &model +} + +func (model *ProxyRuleList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/proxyRuleList_test.go b/models/proxyRuleList_test.go new file mode 100644 index 00000000..d5e348d4 --- /dev/null +++ b/models/proxyRuleList_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestProxyRuleListModel(t *testing.T) { + model := ProxyRuleList{ Total: 5, Rules: []ProxyRule{ProxyRule{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Domain: "appwrite.company.com", Type: "deployment", Trigger: "manual", RedirectUrl: "https://appwrite.io/docs", RedirectStatusCode: 301, DeploymentId: "n3u9feiwmf", DeploymentResourceId: "n3u9feiwmf", DeploymentVcsProviderBranch: "main", Status: "verified", Logs: "Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.", RenewAt: "datetime", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ProxyRuleList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/proxyRule_test.go b/models/proxyRule_test.go new file mode 100644 index 00000000..55745cc0 --- /dev/null +++ b/models/proxyRule_test.go @@ -0,0 +1,62 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestProxyRuleModel(t *testing.T) { + model := ProxyRule{ Id: "5e5ea5c16897e", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Domain: "appwrite.company.com", Type: "deployment", Trigger: "manual", RedirectUrl: "https://appwrite.io/docs", RedirectStatusCode: 301, DeploymentId: "n3u9feiwmf", DeploymentResourceId: "n3u9feiwmf", DeploymentVcsProviderBranch: "main", Status: "verified", Logs: "Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.", RenewAt: "datetime", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result ProxyRule + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.Domain != model.Domain { + t.Errorf("Expected Domain %v, got %v", model.Domain, result.Domain) + } + if result.Type != model.Type { + t.Errorf("Expected Type %v, got %v", model.Type, result.Type) + } + if result.Trigger != model.Trigger { + t.Errorf("Expected Trigger %v, got %v", model.Trigger, result.Trigger) + } + if result.RedirectUrl != model.RedirectUrl { + t.Errorf("Expected RedirectUrl %v, got %v", model.RedirectUrl, result.RedirectUrl) + } + if result.RedirectStatusCode != model.RedirectStatusCode { + t.Errorf("Expected RedirectStatusCode %v, got %v", model.RedirectStatusCode, result.RedirectStatusCode) + } + if result.DeploymentId != model.DeploymentId { + t.Errorf("Expected DeploymentId %v, got %v", model.DeploymentId, result.DeploymentId) + } + if result.DeploymentResourceId != model.DeploymentResourceId { + t.Errorf("Expected DeploymentResourceId %v, got %v", model.DeploymentResourceId, result.DeploymentResourceId) + } + if result.DeploymentVcsProviderBranch != model.DeploymentVcsProviderBranch { + t.Errorf("Expected DeploymentVcsProviderBranch %v, got %v", model.DeploymentVcsProviderBranch, result.DeploymentVcsProviderBranch) + } + if result.Status != model.Status { + t.Errorf("Expected Status %v, got %v", model.Status, result.Status) + } + if result.Logs != model.Logs { + t.Errorf("Expected Logs %v, got %v", model.Logs, result.Logs) + } + if result.RenewAt != model.RenewAt { + t.Errorf("Expected RenewAt %v, got %v", model.RenewAt, result.RenewAt) + }} diff --git a/project/project.go b/project/project.go index bf75d61f..dc57708a 100644 --- a/project/project.go +++ b/project/project.go @@ -20,6 +20,75 @@ func New(clt client.Client) *Project { } } + +// Delete delete a project. +func (srv *Project) Delete()(*interface{}, error) { + path := "/project" + params := map[string]interface{}{} + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateAuthMethod update properties of a specific auth method. Use this +// endpoint to enable or disable a method in your project. +func (srv *Project) UpdateAuthMethod(MethodId string, Enabled bool)(*models.Project, error) { + r := strings.NewReplacer("{methodId}", MethodId) + path := r.Replace("/project/auth-methods/{methodId}") + params := map[string]interface{}{} + params["methodId"] = MethodId + params["enabled"] = Enabled + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Project{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Project + parsed, ok := resp.Result.(models.Project) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} type ListKeysOptions struct { Queries []string Total bool @@ -107,6 +176,9 @@ func (srv *Project) WithCreateKeyExpire(v string) CreateKeyOption { // CreateKey create a new API key. It's recommended to have multiple API keys // with strict scopes for separate functions within your project. +// +// You can also create an ephemeral API key if you need a short-lived key +// instead. func (srv *Project) CreateKey(KeyId string, Name string, Scopes []string, optionalSetters ...CreateKeyOption)(*models.Key, error) { path := "/project/keys" options := CreateKeyOptions{}.New() @@ -148,6 +220,46 @@ func (srv *Project) CreateKey(KeyId string, Name string, Scopes []string, option return &parsed, nil } + +// CreateEphemeralKey create a new ephemeral API key. It's recommended to have +// multiple API keys with strict scopes for separate functions within your +// project. +// +// You can also create a standard API key if you need a longer-lived key +// instead. +func (srv *Project) CreateEphemeralKey(Scopes []string, Duration int)(*models.EphemeralKey, error) { + path := "/project/keys/ephemeral" + params := map[string]interface{}{} + params["scopes"] = Scopes + params["duration"] = Duration + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.EphemeralKey{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.EphemeralKey + parsed, ok := resp.Result.(models.EphemeralKey) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} // GetKey get a key by its unique ID. func (srv *Project) GetKey(KeyId string)(*models.Key, error) { @@ -314,37 +426,37 @@ func (srv *Project) UpdateLabels(Labels []string)(*models.Project, error) { return &parsed, nil } -type ListPlatformsOptions struct { +type ListMockPhonesOptions struct { Queries []string Total bool enabledSetters map[string]bool } -func (options ListPlatformsOptions) New() *ListPlatformsOptions { +func (options ListMockPhonesOptions) New() *ListMockPhonesOptions { options.enabledSetters = map[string]bool{ "Queries": false, "Total": false, } return &options } -type ListPlatformsOption func(*ListPlatformsOptions) -func (srv *Project) WithListPlatformsQueries(v []string) ListPlatformsOption { - return func(o *ListPlatformsOptions) { +type ListMockPhonesOption func(*ListMockPhonesOptions) +func (srv *Project) WithListMockPhonesQueries(v []string) ListMockPhonesOption { + return func(o *ListMockPhonesOptions) { o.Queries = v o.enabledSetters["Queries"] = true } } -func (srv *Project) WithListPlatformsTotal(v bool) ListPlatformsOption { - return func(o *ListPlatformsOptions) { +func (srv *Project) WithListMockPhonesTotal(v bool) ListMockPhonesOption { + return func(o *ListMockPhonesOptions) { o.Total = v o.enabledSetters["Total"] = true } } -// ListPlatforms get a list of all platforms in the project. This endpoint -// returns an array of all platforms and their configurations. -func (srv *Project) ListPlatforms(optionalSetters ...ListPlatformsOption)(*models.PlatformList, error) { - path := "/project/platforms" - options := ListPlatformsOptions{}.New() +// ListMockPhones get a list of all mock phones in the project. This endpoint +// returns an array of all mock phones and their OTPs. +func (srv *Project) ListMockPhones(optionalSetters ...ListMockPhonesOption)(*models.MockNumberList, error) { + path := "/project/mock-phones" + options := ListMockPhonesOptions{}.New() for _, opt := range optionalSetters { opt(options) } @@ -365,7 +477,7 @@ func (srv *Project) ListPlatforms(optionalSetters ...ListPlatformsOption)(*model if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.PlatformList{}.New(bytes) + parsed := models.MockNumberList{}.New(bytes) err = json.Unmarshal(bytes, parsed) if err != nil { @@ -374,24 +486,22 @@ func (srv *Project) ListPlatforms(optionalSetters ...ListPlatformsOption)(*model return parsed, nil } - var parsed models.PlatformList - parsed, ok := resp.Result.(models.PlatformList) + var parsed models.MockNumberList + parsed, ok := resp.Result.(models.MockNumberList) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } - -// CreateAndroidPlatform create a new Android platform for your project. Use -// this endpoint to register a new Android platform where your users will run -// your application which will interact with the Appwrite API. -func (srv *Project) CreateAndroidPlatform(PlatformId string, Name string, ApplicationId string)(*models.PlatformAndroid, error) { - path := "/project/platforms/android" + +// CreateMockPhone create a new mock phone for your project. Use this endpoint +// to register a mock phone number and its sign-in OTP for your testers. +func (srv *Project) CreateMockPhone(Number string, Otp string)(*models.MockNumber, error) { + path := "/project/mock-phones" params := map[string]interface{}{} - params["platformId"] = PlatformId - params["name"] = Name - params["applicationId"] = ApplicationId + params["number"] = Number + params["otp"] = Otp headers := map[string]interface{}{ "content-type": "application/json", } @@ -403,7 +513,7 @@ func (srv *Project) CreateAndroidPlatform(PlatformId string, Name string, Applic if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.PlatformAndroid{}.New(bytes) + parsed := models.MockNumber{}.New(bytes) err = json.Unmarshal(bytes, parsed) if err != nil { @@ -412,36 +522,33 @@ func (srv *Project) CreateAndroidPlatform(PlatformId string, Name string, Applic return parsed, nil } - var parsed models.PlatformAndroid - parsed, ok := resp.Result.(models.PlatformAndroid) + var parsed models.MockNumber + parsed, ok := resp.Result.(models.MockNumber) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } - -// UpdateAndroidPlatform update an Android platform by its unique ID. Use this -// endpoint to update the platform's name or application ID. -func (srv *Project) UpdateAndroidPlatform(PlatformId string, Name string, ApplicationId string)(*models.PlatformAndroid, error) { - r := strings.NewReplacer("{platformId}", PlatformId) - path := r.Replace("/project/platforms/android/{platformId}") + +// GetMockPhone get a mock phone by its unique number. This endpoint returns +// the mock phone's OTP. +func (srv *Project) GetMockPhone(Number string)(*models.MockNumber, error) { + r := strings.NewReplacer("{number}", Number) + path := r.Replace("/project/mock-phones/{number}") params := map[string]interface{}{} - params["platformId"] = PlatformId - params["name"] = Name - params["applicationId"] = ApplicationId + params["number"] = Number headers := map[string]interface{}{ - "content-type": "application/json", } - resp, err := srv.client.Call("PUT", path, headers, params) + resp, err := srv.client.Call("GET", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.PlatformAndroid{}.New(bytes) + parsed := models.MockNumber{}.New(bytes) err = json.Unmarshal(bytes, parsed) if err != nil { @@ -450,36 +557,35 @@ func (srv *Project) UpdateAndroidPlatform(PlatformId string, Name string, Applic return parsed, nil } - var parsed models.PlatformAndroid - parsed, ok := resp.Result.(models.PlatformAndroid) + var parsed models.MockNumber + parsed, ok := resp.Result.(models.MockNumber) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } - -// CreateApplePlatform create a new Apple platform for your project. Use this -// endpoint to register a new Apple platform where your users will run your -// application which will interact with the Appwrite API. -func (srv *Project) CreateApplePlatform(PlatformId string, Name string, BundleIdentifier string)(*models.PlatformApple, error) { - path := "/project/platforms/apple" + +// UpdateMockPhone update a mock phone by its unique number. Use this endpoint +// to update the mock phone's OTP. +func (srv *Project) UpdateMockPhone(Number string, Otp string)(*models.MockNumber, error) { + r := strings.NewReplacer("{number}", Number) + path := r.Replace("/project/mock-phones/{number}") params := map[string]interface{}{} - params["platformId"] = PlatformId - params["name"] = Name - params["bundleIdentifier"] = BundleIdentifier + params["number"] = Number + params["otp"] = Otp headers := map[string]interface{}{ "content-type": "application/json", } - resp, err := srv.client.Call("POST", path, headers, params) + resp, err := srv.client.Call("PUT", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.PlatformApple{}.New(bytes) + parsed := models.MockNumber{}.New(bytes) err = json.Unmarshal(bytes, parsed) if err != nil { @@ -488,112 +594,102 @@ func (srv *Project) CreateApplePlatform(PlatformId string, Name string, BundleId return parsed, nil } - var parsed models.PlatformApple - parsed, ok := resp.Result.(models.PlatformApple) + var parsed models.MockNumber + parsed, ok := resp.Result.(models.MockNumber) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } - -// UpdateApplePlatform update an Apple platform by its unique ID. Use this -// endpoint to update the platform's name or bundle identifier. -func (srv *Project) UpdateApplePlatform(PlatformId string, Name string, BundleIdentifier string)(*models.PlatformApple, error) { - r := strings.NewReplacer("{platformId}", PlatformId) - path := r.Replace("/project/platforms/apple/{platformId}") + +// DeleteMockPhone delete a mock phone by its unique number. This endpoint +// removes the mock phone and its OTP configuration from the project. +func (srv *Project) DeleteMockPhone(Number string)(*interface{}, error) { + r := strings.NewReplacer("{number}", Number) + path := r.Replace("/project/mock-phones/{number}") params := map[string]interface{}{} - params["platformId"] = PlatformId - params["name"] = Name - params["bundleIdentifier"] = BundleIdentifier + params["number"] = Number headers := map[string]interface{}{ "content-type": "application/json", } - resp, err := srv.client.Call("PUT", path, headers, params) + resp, err := srv.client.Call("DELETE", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.PlatformApple{}.New(bytes) + var parsed interface{} - err = json.Unmarshal(bytes, parsed) + err = json.Unmarshal(bytes, &parsed) if err != nil { return nil, err } - - return parsed, nil + return &parsed, nil } - var parsed models.PlatformApple - parsed, ok := resp.Result.(models.PlatformApple) + var parsed interface{} + parsed, ok := resp.Result.(interface{}) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } - -// CreateLinuxPlatform create a new Linux platform for your project. Use this -// endpoint to register a new Linux platform where your users will run your -// application which will interact with the Appwrite API. -func (srv *Project) CreateLinuxPlatform(PlatformId string, Name string, PackageName string)(*models.PlatformLinux, error) { - path := "/project/platforms/linux" - params := map[string]interface{}{} - params["platformId"] = PlatformId - params["name"] = Name - params["packageName"] = PackageName - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("POST", path, headers, params) - if err != nil { - return nil, err +type ListOAuth2ProvidersOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListOAuth2ProvidersOptions) New() *ListOAuth2ProvidersOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.PlatformLinux{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil + return &options +} +type ListOAuth2ProvidersOption func(*ListOAuth2ProvidersOptions) +func (srv *Project) WithListOAuth2ProvidersQueries(v []string) ListOAuth2ProvidersOption { + return func(o *ListOAuth2ProvidersOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true } - var parsed models.PlatformLinux - parsed, ok := resp.Result.(models.PlatformLinux) - if !ok { - return nil, errors.New("unexpected response type") +} +func (srv *Project) WithListOAuth2ProvidersTotal(v bool) ListOAuth2ProvidersOption { + return func(o *ListOAuth2ProvidersOptions) { + o.Total = v + o.enabledSetters["Total"] = true } - return &parsed, nil - } - -// UpdateLinuxPlatform update a Linux platform by its unique ID. Use this -// endpoint to update the platform's name or package name. -func (srv *Project) UpdateLinuxPlatform(PlatformId string, Name string, PackageName string)(*models.PlatformLinux, error) { - r := strings.NewReplacer("{platformId}", PlatformId) - path := r.Replace("/project/platforms/linux/{platformId}") + +// ListOAuth2Providers get a list of all OAuth2 providers supported by the +// server, along with the project's configuration for each. Credential fields +// are write-only and always returned empty. +func (srv *Project) ListOAuth2Providers(optionalSetters ...ListOAuth2ProvidersOption)(*models.OAuth2ProviderList, error) { + path := "/project/oauth2" + options := ListOAuth2ProvidersOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } params := map[string]interface{}{} - params["platformId"] = PlatformId - params["name"] = Name - params["packageName"] = PackageName + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } headers := map[string]interface{}{ - "content-type": "application/json", } - resp, err := srv.client.Call("PUT", path, headers, params) + resp, err := srv.client.Call("GET", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.PlatformLinux{}.New(bytes) + parsed := models.OAuth2ProviderList{}.New(bytes) err = json.Unmarshal(bytes, parsed) if err != nil { @@ -602,29 +698,4201 @@ func (srv *Project) UpdateLinuxPlatform(PlatformId string, Name string, PackageN return parsed, nil } - var parsed models.PlatformLinux - parsed, ok := resp.Result.(models.PlatformLinux) + var parsed models.OAuth2ProviderList + parsed, ok := resp.Result.(models.OAuth2ProviderList) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } - -// CreateWebPlatform create a new web platform for your project. Use this -// endpoint to register a new platform where your users will run your -// application which will interact with the Appwrite API. -func (srv *Project) CreateWebPlatform(PlatformId string, Name string, Hostname string)(*models.PlatformWeb, error) { - path := "/project/platforms/web" + +// GetOAuth2Provider get a single OAuth2 provider configuration. Credential +// fields (client secret, p8 file, key/team IDs) are write-only and always +// returned empty. +func (srv *Project) GetOAuth2Provider(ProviderId string)(models.Model, error) { + path := "/project/oauth2/:provider" params := map[string]interface{}{} - params["platformId"] = PlatformId - params["name"] = Name - params["hostname"] = Hostname + params["providerId"] = ProviderId headers := map[string]interface{}{ - "content-type": "application/json", } - resp, err := srv.client.Call("POST", path, headers, params) + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var response map[string]interface{} + if err := json.Unmarshal(bytes, &response); err != nil { + return nil, err + } + if fmt.Sprint(response["$id"]) == "github" { + parsed := models.OAuth2Github{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "discord" { + parsed := models.OAuth2Discord{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "figma" { + parsed := models.OAuth2Figma{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "dropbox" { + parsed := models.OAuth2Dropbox{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "dailymotion" { + parsed := models.OAuth2Dailymotion{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "bitbucket" { + parsed := models.OAuth2Bitbucket{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "bitly" { + parsed := models.OAuth2Bitly{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "box" { + parsed := models.OAuth2Box{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "autodesk" { + parsed := models.OAuth2Autodesk{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "google" { + parsed := models.OAuth2Google{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "zoom" { + parsed := models.OAuth2Zoom{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "zoho" { + parsed := models.OAuth2Zoho{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "yandex" { + parsed := models.OAuth2Yandex{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "x" { + parsed := models.OAuth2X{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "wordpress" { + parsed := models.OAuth2WordPress{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "twitch" { + parsed := models.OAuth2Twitch{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "stripe" { + parsed := models.OAuth2Stripe{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "spotify" { + parsed := models.OAuth2Spotify{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "slack" { + parsed := models.OAuth2Slack{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "podio" { + parsed := models.OAuth2Podio{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "notion" { + parsed := models.OAuth2Notion{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "salesforce" { + parsed := models.OAuth2Salesforce{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "yahoo" { + parsed := models.OAuth2Yahoo{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "linkedin" { + parsed := models.OAuth2Linkedin{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "disqus" { + parsed := models.OAuth2Disqus{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "amazon" { + parsed := models.OAuth2Amazon{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "etsy" { + parsed := models.OAuth2Etsy{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "facebook" { + parsed := models.OAuth2Facebook{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "tradeshiftBox" { + parsed := models.OAuth2Tradeshift{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "paypalSandbox" { + parsed := models.OAuth2Paypal{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "gitlab" { + parsed := models.OAuth2Gitlab{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "authentik" { + parsed := models.OAuth2Authentik{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "auth0" { + parsed := models.OAuth2Auth0{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "fusionauth" { + parsed := models.OAuth2FusionAuth{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "keycloak" { + parsed := models.OAuth2Keycloak{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "oidc" { + parsed := models.OAuth2Oidc{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "apple" { + parsed := models.OAuth2Apple{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "okta" { + parsed := models.OAuth2Okta{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "kick" { + parsed := models.OAuth2Kick{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "microsoft" { + parsed := models.OAuth2Microsoft{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + + return nil, errors.New("unable to match response to any expected response model") + } + parsed, ok := resp.Result.(models.Model) + if !ok { + return nil, errors.New("unexpected response type") + } + return parsed, nil + +} +type UpdateOAuth2AmazonOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2AmazonOptions) New() *UpdateOAuth2AmazonOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2AmazonOption func(*UpdateOAuth2AmazonOptions) +func (srv *Project) WithUpdateOAuth2AmazonClientId(v string) UpdateOAuth2AmazonOption { + return func(o *UpdateOAuth2AmazonOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2AmazonClientSecret(v string) UpdateOAuth2AmazonOption { + return func(o *UpdateOAuth2AmazonOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2AmazonEnabled(v bool) UpdateOAuth2AmazonOption { + return func(o *UpdateOAuth2AmazonOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Amazon update the project OAuth2 Amazon configuration. +func (srv *Project) UpdateOAuth2Amazon(optionalSetters ...UpdateOAuth2AmazonOption)(*models.OAuth2Amazon, error) { + path := "/project/oauth2/amazon" + options := UpdateOAuth2AmazonOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Amazon{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Amazon + parsed, ok := resp.Result.(models.OAuth2Amazon) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2AppleOptions struct { + ServiceId string + KeyId string + TeamId string + P8File string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2AppleOptions) New() *UpdateOAuth2AppleOptions { + options.enabledSetters = map[string]bool{ + "ServiceId": false, + "KeyId": false, + "TeamId": false, + "P8File": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2AppleOption func(*UpdateOAuth2AppleOptions) +func (srv *Project) WithUpdateOAuth2AppleServiceId(v string) UpdateOAuth2AppleOption { + return func(o *UpdateOAuth2AppleOptions) { + o.ServiceId = v + o.enabledSetters["ServiceId"] = true + } +} +func (srv *Project) WithUpdateOAuth2AppleKeyId(v string) UpdateOAuth2AppleOption { + return func(o *UpdateOAuth2AppleOptions) { + o.KeyId = v + o.enabledSetters["KeyId"] = true + } +} +func (srv *Project) WithUpdateOAuth2AppleTeamId(v string) UpdateOAuth2AppleOption { + return func(o *UpdateOAuth2AppleOptions) { + o.TeamId = v + o.enabledSetters["TeamId"] = true + } +} +func (srv *Project) WithUpdateOAuth2AppleP8File(v string) UpdateOAuth2AppleOption { + return func(o *UpdateOAuth2AppleOptions) { + o.P8File = v + o.enabledSetters["P8File"] = true + } +} +func (srv *Project) WithUpdateOAuth2AppleEnabled(v bool) UpdateOAuth2AppleOption { + return func(o *UpdateOAuth2AppleOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Apple update the project OAuth2 Apple configuration. +func (srv *Project) UpdateOAuth2Apple(optionalSetters ...UpdateOAuth2AppleOption)(*models.OAuth2Apple, error) { + path := "/project/oauth2/apple" + options := UpdateOAuth2AppleOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ServiceId"] { + params["serviceId"] = options.ServiceId + } + if options.enabledSetters["KeyId"] { + params["keyId"] = options.KeyId + } + if options.enabledSetters["TeamId"] { + params["teamId"] = options.TeamId + } + if options.enabledSetters["P8File"] { + params["p8File"] = options.P8File + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Apple{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Apple + parsed, ok := resp.Result.(models.OAuth2Apple) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2Auth0Options struct { + ClientId string + ClientSecret string + Endpoint string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2Auth0Options) New() *UpdateOAuth2Auth0Options { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Endpoint": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2Auth0Option func(*UpdateOAuth2Auth0Options) +func (srv *Project) WithUpdateOAuth2Auth0ClientId(v string) UpdateOAuth2Auth0Option { + return func(o *UpdateOAuth2Auth0Options) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2Auth0ClientSecret(v string) UpdateOAuth2Auth0Option { + return func(o *UpdateOAuth2Auth0Options) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2Auth0Endpoint(v string) UpdateOAuth2Auth0Option { + return func(o *UpdateOAuth2Auth0Options) { + o.Endpoint = v + o.enabledSetters["Endpoint"] = true + } +} +func (srv *Project) WithUpdateOAuth2Auth0Enabled(v bool) UpdateOAuth2Auth0Option { + return func(o *UpdateOAuth2Auth0Options) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Auth0 update the project OAuth2 Auth0 configuration. +func (srv *Project) UpdateOAuth2Auth0(optionalSetters ...UpdateOAuth2Auth0Option)(*models.OAuth2Auth0, error) { + path := "/project/oauth2/auth0" + options := UpdateOAuth2Auth0Options{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Endpoint"] { + params["endpoint"] = options.Endpoint + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Auth0{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Auth0 + parsed, ok := resp.Result.(models.OAuth2Auth0) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2AuthentikOptions struct { + ClientId string + ClientSecret string + Endpoint string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2AuthentikOptions) New() *UpdateOAuth2AuthentikOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Endpoint": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2AuthentikOption func(*UpdateOAuth2AuthentikOptions) +func (srv *Project) WithUpdateOAuth2AuthentikClientId(v string) UpdateOAuth2AuthentikOption { + return func(o *UpdateOAuth2AuthentikOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2AuthentikClientSecret(v string) UpdateOAuth2AuthentikOption { + return func(o *UpdateOAuth2AuthentikOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2AuthentikEndpoint(v string) UpdateOAuth2AuthentikOption { + return func(o *UpdateOAuth2AuthentikOptions) { + o.Endpoint = v + o.enabledSetters["Endpoint"] = true + } +} +func (srv *Project) WithUpdateOAuth2AuthentikEnabled(v bool) UpdateOAuth2AuthentikOption { + return func(o *UpdateOAuth2AuthentikOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Authentik update the project OAuth2 Authentik configuration. +func (srv *Project) UpdateOAuth2Authentik(optionalSetters ...UpdateOAuth2AuthentikOption)(*models.OAuth2Authentik, error) { + path := "/project/oauth2/authentik" + options := UpdateOAuth2AuthentikOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Endpoint"] { + params["endpoint"] = options.Endpoint + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Authentik{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Authentik + parsed, ok := resp.Result.(models.OAuth2Authentik) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2AutodeskOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2AutodeskOptions) New() *UpdateOAuth2AutodeskOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2AutodeskOption func(*UpdateOAuth2AutodeskOptions) +func (srv *Project) WithUpdateOAuth2AutodeskClientId(v string) UpdateOAuth2AutodeskOption { + return func(o *UpdateOAuth2AutodeskOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2AutodeskClientSecret(v string) UpdateOAuth2AutodeskOption { + return func(o *UpdateOAuth2AutodeskOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2AutodeskEnabled(v bool) UpdateOAuth2AutodeskOption { + return func(o *UpdateOAuth2AutodeskOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Autodesk update the project OAuth2 Autodesk configuration. +func (srv *Project) UpdateOAuth2Autodesk(optionalSetters ...UpdateOAuth2AutodeskOption)(*models.OAuth2Autodesk, error) { + path := "/project/oauth2/autodesk" + options := UpdateOAuth2AutodeskOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Autodesk{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Autodesk + parsed, ok := resp.Result.(models.OAuth2Autodesk) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2BitbucketOptions struct { + Key string + Secret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2BitbucketOptions) New() *UpdateOAuth2BitbucketOptions { + options.enabledSetters = map[string]bool{ + "Key": false, + "Secret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2BitbucketOption func(*UpdateOAuth2BitbucketOptions) +func (srv *Project) WithUpdateOAuth2BitbucketKey(v string) UpdateOAuth2BitbucketOption { + return func(o *UpdateOAuth2BitbucketOptions) { + o.Key = v + o.enabledSetters["Key"] = true + } +} +func (srv *Project) WithUpdateOAuth2BitbucketSecret(v string) UpdateOAuth2BitbucketOption { + return func(o *UpdateOAuth2BitbucketOptions) { + o.Secret = v + o.enabledSetters["Secret"] = true + } +} +func (srv *Project) WithUpdateOAuth2BitbucketEnabled(v bool) UpdateOAuth2BitbucketOption { + return func(o *UpdateOAuth2BitbucketOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Bitbucket update the project OAuth2 Bitbucket configuration. +func (srv *Project) UpdateOAuth2Bitbucket(optionalSetters ...UpdateOAuth2BitbucketOption)(*models.OAuth2Bitbucket, error) { + path := "/project/oauth2/bitbucket" + options := UpdateOAuth2BitbucketOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Key"] { + params["key"] = options.Key + } + if options.enabledSetters["Secret"] { + params["secret"] = options.Secret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Bitbucket{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Bitbucket + parsed, ok := resp.Result.(models.OAuth2Bitbucket) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2BitlyOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2BitlyOptions) New() *UpdateOAuth2BitlyOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2BitlyOption func(*UpdateOAuth2BitlyOptions) +func (srv *Project) WithUpdateOAuth2BitlyClientId(v string) UpdateOAuth2BitlyOption { + return func(o *UpdateOAuth2BitlyOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2BitlyClientSecret(v string) UpdateOAuth2BitlyOption { + return func(o *UpdateOAuth2BitlyOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2BitlyEnabled(v bool) UpdateOAuth2BitlyOption { + return func(o *UpdateOAuth2BitlyOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Bitly update the project OAuth2 Bitly configuration. +func (srv *Project) UpdateOAuth2Bitly(optionalSetters ...UpdateOAuth2BitlyOption)(*models.OAuth2Bitly, error) { + path := "/project/oauth2/bitly" + options := UpdateOAuth2BitlyOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Bitly{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Bitly + parsed, ok := resp.Result.(models.OAuth2Bitly) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2BoxOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2BoxOptions) New() *UpdateOAuth2BoxOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2BoxOption func(*UpdateOAuth2BoxOptions) +func (srv *Project) WithUpdateOAuth2BoxClientId(v string) UpdateOAuth2BoxOption { + return func(o *UpdateOAuth2BoxOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2BoxClientSecret(v string) UpdateOAuth2BoxOption { + return func(o *UpdateOAuth2BoxOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2BoxEnabled(v bool) UpdateOAuth2BoxOption { + return func(o *UpdateOAuth2BoxOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Box update the project OAuth2 Box configuration. +func (srv *Project) UpdateOAuth2Box(optionalSetters ...UpdateOAuth2BoxOption)(*models.OAuth2Box, error) { + path := "/project/oauth2/box" + options := UpdateOAuth2BoxOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Box{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Box + parsed, ok := resp.Result.(models.OAuth2Box) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2DailymotionOptions struct { + ApiKey string + ApiSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2DailymotionOptions) New() *UpdateOAuth2DailymotionOptions { + options.enabledSetters = map[string]bool{ + "ApiKey": false, + "ApiSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2DailymotionOption func(*UpdateOAuth2DailymotionOptions) +func (srv *Project) WithUpdateOAuth2DailymotionApiKey(v string) UpdateOAuth2DailymotionOption { + return func(o *UpdateOAuth2DailymotionOptions) { + o.ApiKey = v + o.enabledSetters["ApiKey"] = true + } +} +func (srv *Project) WithUpdateOAuth2DailymotionApiSecret(v string) UpdateOAuth2DailymotionOption { + return func(o *UpdateOAuth2DailymotionOptions) { + o.ApiSecret = v + o.enabledSetters["ApiSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2DailymotionEnabled(v bool) UpdateOAuth2DailymotionOption { + return func(o *UpdateOAuth2DailymotionOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Dailymotion update the project OAuth2 Dailymotion +// configuration. +func (srv *Project) UpdateOAuth2Dailymotion(optionalSetters ...UpdateOAuth2DailymotionOption)(*models.OAuth2Dailymotion, error) { + path := "/project/oauth2/dailymotion" + options := UpdateOAuth2DailymotionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ApiKey"] { + params["apiKey"] = options.ApiKey + } + if options.enabledSetters["ApiSecret"] { + params["apiSecret"] = options.ApiSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Dailymotion{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Dailymotion + parsed, ok := resp.Result.(models.OAuth2Dailymotion) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2DiscordOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2DiscordOptions) New() *UpdateOAuth2DiscordOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2DiscordOption func(*UpdateOAuth2DiscordOptions) +func (srv *Project) WithUpdateOAuth2DiscordClientId(v string) UpdateOAuth2DiscordOption { + return func(o *UpdateOAuth2DiscordOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2DiscordClientSecret(v string) UpdateOAuth2DiscordOption { + return func(o *UpdateOAuth2DiscordOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2DiscordEnabled(v bool) UpdateOAuth2DiscordOption { + return func(o *UpdateOAuth2DiscordOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Discord update the project OAuth2 Discord configuration. +func (srv *Project) UpdateOAuth2Discord(optionalSetters ...UpdateOAuth2DiscordOption)(*models.OAuth2Discord, error) { + path := "/project/oauth2/discord" + options := UpdateOAuth2DiscordOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Discord{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Discord + parsed, ok := resp.Result.(models.OAuth2Discord) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2DisqusOptions struct { + PublicKey string + SecretKey string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2DisqusOptions) New() *UpdateOAuth2DisqusOptions { + options.enabledSetters = map[string]bool{ + "PublicKey": false, + "SecretKey": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2DisqusOption func(*UpdateOAuth2DisqusOptions) +func (srv *Project) WithUpdateOAuth2DisqusPublicKey(v string) UpdateOAuth2DisqusOption { + return func(o *UpdateOAuth2DisqusOptions) { + o.PublicKey = v + o.enabledSetters["PublicKey"] = true + } +} +func (srv *Project) WithUpdateOAuth2DisqusSecretKey(v string) UpdateOAuth2DisqusOption { + return func(o *UpdateOAuth2DisqusOptions) { + o.SecretKey = v + o.enabledSetters["SecretKey"] = true + } +} +func (srv *Project) WithUpdateOAuth2DisqusEnabled(v bool) UpdateOAuth2DisqusOption { + return func(o *UpdateOAuth2DisqusOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Disqus update the project OAuth2 Disqus configuration. +func (srv *Project) UpdateOAuth2Disqus(optionalSetters ...UpdateOAuth2DisqusOption)(*models.OAuth2Disqus, error) { + path := "/project/oauth2/disqus" + options := UpdateOAuth2DisqusOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["PublicKey"] { + params["publicKey"] = options.PublicKey + } + if options.enabledSetters["SecretKey"] { + params["secretKey"] = options.SecretKey + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Disqus{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Disqus + parsed, ok := resp.Result.(models.OAuth2Disqus) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2DropboxOptions struct { + AppKey string + AppSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2DropboxOptions) New() *UpdateOAuth2DropboxOptions { + options.enabledSetters = map[string]bool{ + "AppKey": false, + "AppSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2DropboxOption func(*UpdateOAuth2DropboxOptions) +func (srv *Project) WithUpdateOAuth2DropboxAppKey(v string) UpdateOAuth2DropboxOption { + return func(o *UpdateOAuth2DropboxOptions) { + o.AppKey = v + o.enabledSetters["AppKey"] = true + } +} +func (srv *Project) WithUpdateOAuth2DropboxAppSecret(v string) UpdateOAuth2DropboxOption { + return func(o *UpdateOAuth2DropboxOptions) { + o.AppSecret = v + o.enabledSetters["AppSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2DropboxEnabled(v bool) UpdateOAuth2DropboxOption { + return func(o *UpdateOAuth2DropboxOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Dropbox update the project OAuth2 Dropbox configuration. +func (srv *Project) UpdateOAuth2Dropbox(optionalSetters ...UpdateOAuth2DropboxOption)(*models.OAuth2Dropbox, error) { + path := "/project/oauth2/dropbox" + options := UpdateOAuth2DropboxOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["AppKey"] { + params["appKey"] = options.AppKey + } + if options.enabledSetters["AppSecret"] { + params["appSecret"] = options.AppSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Dropbox{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Dropbox + parsed, ok := resp.Result.(models.OAuth2Dropbox) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2EtsyOptions struct { + KeyString string + SharedSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2EtsyOptions) New() *UpdateOAuth2EtsyOptions { + options.enabledSetters = map[string]bool{ + "KeyString": false, + "SharedSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2EtsyOption func(*UpdateOAuth2EtsyOptions) +func (srv *Project) WithUpdateOAuth2EtsyKeyString(v string) UpdateOAuth2EtsyOption { + return func(o *UpdateOAuth2EtsyOptions) { + o.KeyString = v + o.enabledSetters["KeyString"] = true + } +} +func (srv *Project) WithUpdateOAuth2EtsySharedSecret(v string) UpdateOAuth2EtsyOption { + return func(o *UpdateOAuth2EtsyOptions) { + o.SharedSecret = v + o.enabledSetters["SharedSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2EtsyEnabled(v bool) UpdateOAuth2EtsyOption { + return func(o *UpdateOAuth2EtsyOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Etsy update the project OAuth2 Etsy configuration. +func (srv *Project) UpdateOAuth2Etsy(optionalSetters ...UpdateOAuth2EtsyOption)(*models.OAuth2Etsy, error) { + path := "/project/oauth2/etsy" + options := UpdateOAuth2EtsyOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["KeyString"] { + params["keyString"] = options.KeyString + } + if options.enabledSetters["SharedSecret"] { + params["sharedSecret"] = options.SharedSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Etsy{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Etsy + parsed, ok := resp.Result.(models.OAuth2Etsy) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2FacebookOptions struct { + AppId string + AppSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2FacebookOptions) New() *UpdateOAuth2FacebookOptions { + options.enabledSetters = map[string]bool{ + "AppId": false, + "AppSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2FacebookOption func(*UpdateOAuth2FacebookOptions) +func (srv *Project) WithUpdateOAuth2FacebookAppId(v string) UpdateOAuth2FacebookOption { + return func(o *UpdateOAuth2FacebookOptions) { + o.AppId = v + o.enabledSetters["AppId"] = true + } +} +func (srv *Project) WithUpdateOAuth2FacebookAppSecret(v string) UpdateOAuth2FacebookOption { + return func(o *UpdateOAuth2FacebookOptions) { + o.AppSecret = v + o.enabledSetters["AppSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2FacebookEnabled(v bool) UpdateOAuth2FacebookOption { + return func(o *UpdateOAuth2FacebookOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Facebook update the project OAuth2 Facebook configuration. +func (srv *Project) UpdateOAuth2Facebook(optionalSetters ...UpdateOAuth2FacebookOption)(*models.OAuth2Facebook, error) { + path := "/project/oauth2/facebook" + options := UpdateOAuth2FacebookOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["AppId"] { + params["appId"] = options.AppId + } + if options.enabledSetters["AppSecret"] { + params["appSecret"] = options.AppSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Facebook{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Facebook + parsed, ok := resp.Result.(models.OAuth2Facebook) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2FigmaOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2FigmaOptions) New() *UpdateOAuth2FigmaOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2FigmaOption func(*UpdateOAuth2FigmaOptions) +func (srv *Project) WithUpdateOAuth2FigmaClientId(v string) UpdateOAuth2FigmaOption { + return func(o *UpdateOAuth2FigmaOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2FigmaClientSecret(v string) UpdateOAuth2FigmaOption { + return func(o *UpdateOAuth2FigmaOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2FigmaEnabled(v bool) UpdateOAuth2FigmaOption { + return func(o *UpdateOAuth2FigmaOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Figma update the project OAuth2 Figma configuration. +func (srv *Project) UpdateOAuth2Figma(optionalSetters ...UpdateOAuth2FigmaOption)(*models.OAuth2Figma, error) { + path := "/project/oauth2/figma" + options := UpdateOAuth2FigmaOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Figma{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Figma + parsed, ok := resp.Result.(models.OAuth2Figma) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2FusionAuthOptions struct { + ClientId string + ClientSecret string + Endpoint string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2FusionAuthOptions) New() *UpdateOAuth2FusionAuthOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Endpoint": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2FusionAuthOption func(*UpdateOAuth2FusionAuthOptions) +func (srv *Project) WithUpdateOAuth2FusionAuthClientId(v string) UpdateOAuth2FusionAuthOption { + return func(o *UpdateOAuth2FusionAuthOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2FusionAuthClientSecret(v string) UpdateOAuth2FusionAuthOption { + return func(o *UpdateOAuth2FusionAuthOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2FusionAuthEndpoint(v string) UpdateOAuth2FusionAuthOption { + return func(o *UpdateOAuth2FusionAuthOptions) { + o.Endpoint = v + o.enabledSetters["Endpoint"] = true + } +} +func (srv *Project) WithUpdateOAuth2FusionAuthEnabled(v bool) UpdateOAuth2FusionAuthOption { + return func(o *UpdateOAuth2FusionAuthOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2FusionAuth update the project OAuth2 FusionAuth configuration. +func (srv *Project) UpdateOAuth2FusionAuth(optionalSetters ...UpdateOAuth2FusionAuthOption)(*models.OAuth2FusionAuth, error) { + path := "/project/oauth2/fusionauth" + options := UpdateOAuth2FusionAuthOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Endpoint"] { + params["endpoint"] = options.Endpoint + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2FusionAuth{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2FusionAuth + parsed, ok := resp.Result.(models.OAuth2FusionAuth) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2GitHubOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2GitHubOptions) New() *UpdateOAuth2GitHubOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2GitHubOption func(*UpdateOAuth2GitHubOptions) +func (srv *Project) WithUpdateOAuth2GitHubClientId(v string) UpdateOAuth2GitHubOption { + return func(o *UpdateOAuth2GitHubOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2GitHubClientSecret(v string) UpdateOAuth2GitHubOption { + return func(o *UpdateOAuth2GitHubOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2GitHubEnabled(v bool) UpdateOAuth2GitHubOption { + return func(o *UpdateOAuth2GitHubOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2GitHub update the project OAuth2 GitHub configuration. +func (srv *Project) UpdateOAuth2GitHub(optionalSetters ...UpdateOAuth2GitHubOption)(*models.OAuth2Github, error) { + path := "/project/oauth2/github" + options := UpdateOAuth2GitHubOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Github{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Github + parsed, ok := resp.Result.(models.OAuth2Github) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2GitlabOptions struct { + ApplicationId string + Secret string + Endpoint string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2GitlabOptions) New() *UpdateOAuth2GitlabOptions { + options.enabledSetters = map[string]bool{ + "ApplicationId": false, + "Secret": false, + "Endpoint": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2GitlabOption func(*UpdateOAuth2GitlabOptions) +func (srv *Project) WithUpdateOAuth2GitlabApplicationId(v string) UpdateOAuth2GitlabOption { + return func(o *UpdateOAuth2GitlabOptions) { + o.ApplicationId = v + o.enabledSetters["ApplicationId"] = true + } +} +func (srv *Project) WithUpdateOAuth2GitlabSecret(v string) UpdateOAuth2GitlabOption { + return func(o *UpdateOAuth2GitlabOptions) { + o.Secret = v + o.enabledSetters["Secret"] = true + } +} +func (srv *Project) WithUpdateOAuth2GitlabEndpoint(v string) UpdateOAuth2GitlabOption { + return func(o *UpdateOAuth2GitlabOptions) { + o.Endpoint = v + o.enabledSetters["Endpoint"] = true + } +} +func (srv *Project) WithUpdateOAuth2GitlabEnabled(v bool) UpdateOAuth2GitlabOption { + return func(o *UpdateOAuth2GitlabOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Gitlab update the project OAuth2 Gitlab configuration. +func (srv *Project) UpdateOAuth2Gitlab(optionalSetters ...UpdateOAuth2GitlabOption)(*models.OAuth2Gitlab, error) { + path := "/project/oauth2/gitlab" + options := UpdateOAuth2GitlabOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ApplicationId"] { + params["applicationId"] = options.ApplicationId + } + if options.enabledSetters["Secret"] { + params["secret"] = options.Secret + } + if options.enabledSetters["Endpoint"] { + params["endpoint"] = options.Endpoint + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Gitlab{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Gitlab + parsed, ok := resp.Result.(models.OAuth2Gitlab) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2GoogleOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2GoogleOptions) New() *UpdateOAuth2GoogleOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2GoogleOption func(*UpdateOAuth2GoogleOptions) +func (srv *Project) WithUpdateOAuth2GoogleClientId(v string) UpdateOAuth2GoogleOption { + return func(o *UpdateOAuth2GoogleOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2GoogleClientSecret(v string) UpdateOAuth2GoogleOption { + return func(o *UpdateOAuth2GoogleOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2GoogleEnabled(v bool) UpdateOAuth2GoogleOption { + return func(o *UpdateOAuth2GoogleOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Google update the project OAuth2 Google configuration. +func (srv *Project) UpdateOAuth2Google(optionalSetters ...UpdateOAuth2GoogleOption)(*models.OAuth2Google, error) { + path := "/project/oauth2/google" + options := UpdateOAuth2GoogleOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Google{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Google + parsed, ok := resp.Result.(models.OAuth2Google) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2KeycloakOptions struct { + ClientId string + ClientSecret string + Endpoint string + RealmName string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2KeycloakOptions) New() *UpdateOAuth2KeycloakOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Endpoint": false, + "RealmName": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2KeycloakOption func(*UpdateOAuth2KeycloakOptions) +func (srv *Project) WithUpdateOAuth2KeycloakClientId(v string) UpdateOAuth2KeycloakOption { + return func(o *UpdateOAuth2KeycloakOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2KeycloakClientSecret(v string) UpdateOAuth2KeycloakOption { + return func(o *UpdateOAuth2KeycloakOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2KeycloakEndpoint(v string) UpdateOAuth2KeycloakOption { + return func(o *UpdateOAuth2KeycloakOptions) { + o.Endpoint = v + o.enabledSetters["Endpoint"] = true + } +} +func (srv *Project) WithUpdateOAuth2KeycloakRealmName(v string) UpdateOAuth2KeycloakOption { + return func(o *UpdateOAuth2KeycloakOptions) { + o.RealmName = v + o.enabledSetters["RealmName"] = true + } +} +func (srv *Project) WithUpdateOAuth2KeycloakEnabled(v bool) UpdateOAuth2KeycloakOption { + return func(o *UpdateOAuth2KeycloakOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Keycloak update the project OAuth2 Keycloak configuration. +func (srv *Project) UpdateOAuth2Keycloak(optionalSetters ...UpdateOAuth2KeycloakOption)(*models.OAuth2Keycloak, error) { + path := "/project/oauth2/keycloak" + options := UpdateOAuth2KeycloakOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Endpoint"] { + params["endpoint"] = options.Endpoint + } + if options.enabledSetters["RealmName"] { + params["realmName"] = options.RealmName + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Keycloak{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Keycloak + parsed, ok := resp.Result.(models.OAuth2Keycloak) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2KickOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2KickOptions) New() *UpdateOAuth2KickOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2KickOption func(*UpdateOAuth2KickOptions) +func (srv *Project) WithUpdateOAuth2KickClientId(v string) UpdateOAuth2KickOption { + return func(o *UpdateOAuth2KickOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2KickClientSecret(v string) UpdateOAuth2KickOption { + return func(o *UpdateOAuth2KickOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2KickEnabled(v bool) UpdateOAuth2KickOption { + return func(o *UpdateOAuth2KickOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Kick update the project OAuth2 Kick configuration. +func (srv *Project) UpdateOAuth2Kick(optionalSetters ...UpdateOAuth2KickOption)(*models.OAuth2Kick, error) { + path := "/project/oauth2/kick" + options := UpdateOAuth2KickOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Kick{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Kick + parsed, ok := resp.Result.(models.OAuth2Kick) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2LinkedinOptions struct { + ClientId string + PrimaryClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2LinkedinOptions) New() *UpdateOAuth2LinkedinOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "PrimaryClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2LinkedinOption func(*UpdateOAuth2LinkedinOptions) +func (srv *Project) WithUpdateOAuth2LinkedinClientId(v string) UpdateOAuth2LinkedinOption { + return func(o *UpdateOAuth2LinkedinOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2LinkedinPrimaryClientSecret(v string) UpdateOAuth2LinkedinOption { + return func(o *UpdateOAuth2LinkedinOptions) { + o.PrimaryClientSecret = v + o.enabledSetters["PrimaryClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2LinkedinEnabled(v bool) UpdateOAuth2LinkedinOption { + return func(o *UpdateOAuth2LinkedinOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Linkedin update the project OAuth2 Linkedin configuration. +func (srv *Project) UpdateOAuth2Linkedin(optionalSetters ...UpdateOAuth2LinkedinOption)(*models.OAuth2Linkedin, error) { + path := "/project/oauth2/linkedin" + options := UpdateOAuth2LinkedinOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["PrimaryClientSecret"] { + params["primaryClientSecret"] = options.PrimaryClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Linkedin{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Linkedin + parsed, ok := resp.Result.(models.OAuth2Linkedin) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2MicrosoftOptions struct { + ApplicationId string + ApplicationSecret string + Tenant string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2MicrosoftOptions) New() *UpdateOAuth2MicrosoftOptions { + options.enabledSetters = map[string]bool{ + "ApplicationId": false, + "ApplicationSecret": false, + "Tenant": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2MicrosoftOption func(*UpdateOAuth2MicrosoftOptions) +func (srv *Project) WithUpdateOAuth2MicrosoftApplicationId(v string) UpdateOAuth2MicrosoftOption { + return func(o *UpdateOAuth2MicrosoftOptions) { + o.ApplicationId = v + o.enabledSetters["ApplicationId"] = true + } +} +func (srv *Project) WithUpdateOAuth2MicrosoftApplicationSecret(v string) UpdateOAuth2MicrosoftOption { + return func(o *UpdateOAuth2MicrosoftOptions) { + o.ApplicationSecret = v + o.enabledSetters["ApplicationSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2MicrosoftTenant(v string) UpdateOAuth2MicrosoftOption { + return func(o *UpdateOAuth2MicrosoftOptions) { + o.Tenant = v + o.enabledSetters["Tenant"] = true + } +} +func (srv *Project) WithUpdateOAuth2MicrosoftEnabled(v bool) UpdateOAuth2MicrosoftOption { + return func(o *UpdateOAuth2MicrosoftOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Microsoft update the project OAuth2 Microsoft configuration. +func (srv *Project) UpdateOAuth2Microsoft(optionalSetters ...UpdateOAuth2MicrosoftOption)(*models.OAuth2Microsoft, error) { + path := "/project/oauth2/microsoft" + options := UpdateOAuth2MicrosoftOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ApplicationId"] { + params["applicationId"] = options.ApplicationId + } + if options.enabledSetters["ApplicationSecret"] { + params["applicationSecret"] = options.ApplicationSecret + } + if options.enabledSetters["Tenant"] { + params["tenant"] = options.Tenant + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Microsoft{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Microsoft + parsed, ok := resp.Result.(models.OAuth2Microsoft) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2NotionOptions struct { + OauthClientId string + OauthClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2NotionOptions) New() *UpdateOAuth2NotionOptions { + options.enabledSetters = map[string]bool{ + "OauthClientId": false, + "OauthClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2NotionOption func(*UpdateOAuth2NotionOptions) +func (srv *Project) WithUpdateOAuth2NotionOauthClientId(v string) UpdateOAuth2NotionOption { + return func(o *UpdateOAuth2NotionOptions) { + o.OauthClientId = v + o.enabledSetters["OauthClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2NotionOauthClientSecret(v string) UpdateOAuth2NotionOption { + return func(o *UpdateOAuth2NotionOptions) { + o.OauthClientSecret = v + o.enabledSetters["OauthClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2NotionEnabled(v bool) UpdateOAuth2NotionOption { + return func(o *UpdateOAuth2NotionOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Notion update the project OAuth2 Notion configuration. +func (srv *Project) UpdateOAuth2Notion(optionalSetters ...UpdateOAuth2NotionOption)(*models.OAuth2Notion, error) { + path := "/project/oauth2/notion" + options := UpdateOAuth2NotionOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["OauthClientId"] { + params["oauthClientId"] = options.OauthClientId + } + if options.enabledSetters["OauthClientSecret"] { + params["oauthClientSecret"] = options.OauthClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Notion{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Notion + parsed, ok := resp.Result.(models.OAuth2Notion) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2OidcOptions struct { + ClientId string + ClientSecret string + WellKnownURL string + AuthorizationURL string + TokenURL string + UserInfoURL string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2OidcOptions) New() *UpdateOAuth2OidcOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "WellKnownURL": false, + "AuthorizationURL": false, + "TokenURL": false, + "UserInfoURL": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2OidcOption func(*UpdateOAuth2OidcOptions) +func (srv *Project) WithUpdateOAuth2OidcClientId(v string) UpdateOAuth2OidcOption { + return func(o *UpdateOAuth2OidcOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2OidcClientSecret(v string) UpdateOAuth2OidcOption { + return func(o *UpdateOAuth2OidcOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2OidcWellKnownURL(v string) UpdateOAuth2OidcOption { + return func(o *UpdateOAuth2OidcOptions) { + o.WellKnownURL = v + o.enabledSetters["WellKnownURL"] = true + } +} +func (srv *Project) WithUpdateOAuth2OidcAuthorizationURL(v string) UpdateOAuth2OidcOption { + return func(o *UpdateOAuth2OidcOptions) { + o.AuthorizationURL = v + o.enabledSetters["AuthorizationURL"] = true + } +} +func (srv *Project) WithUpdateOAuth2OidcTokenURL(v string) UpdateOAuth2OidcOption { + return func(o *UpdateOAuth2OidcOptions) { + o.TokenURL = v + o.enabledSetters["TokenURL"] = true + } +} +func (srv *Project) WithUpdateOAuth2OidcUserInfoURL(v string) UpdateOAuth2OidcOption { + return func(o *UpdateOAuth2OidcOptions) { + o.UserInfoURL = v + o.enabledSetters["UserInfoURL"] = true + } +} +func (srv *Project) WithUpdateOAuth2OidcEnabled(v bool) UpdateOAuth2OidcOption { + return func(o *UpdateOAuth2OidcOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Oidc update the project OAuth2 Oidc configuration. +func (srv *Project) UpdateOAuth2Oidc(optionalSetters ...UpdateOAuth2OidcOption)(*models.OAuth2Oidc, error) { + path := "/project/oauth2/oidc" + options := UpdateOAuth2OidcOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["WellKnownURL"] { + params["wellKnownURL"] = options.WellKnownURL + } + if options.enabledSetters["AuthorizationURL"] { + params["authorizationURL"] = options.AuthorizationURL + } + if options.enabledSetters["TokenURL"] { + params["tokenURL"] = options.TokenURL + } + if options.enabledSetters["UserInfoURL"] { + params["userInfoURL"] = options.UserInfoURL + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Oidc{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Oidc + parsed, ok := resp.Result.(models.OAuth2Oidc) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2OktaOptions struct { + ClientId string + ClientSecret string + Domain string + AuthorizationServerId string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2OktaOptions) New() *UpdateOAuth2OktaOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Domain": false, + "AuthorizationServerId": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2OktaOption func(*UpdateOAuth2OktaOptions) +func (srv *Project) WithUpdateOAuth2OktaClientId(v string) UpdateOAuth2OktaOption { + return func(o *UpdateOAuth2OktaOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2OktaClientSecret(v string) UpdateOAuth2OktaOption { + return func(o *UpdateOAuth2OktaOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2OktaDomain(v string) UpdateOAuth2OktaOption { + return func(o *UpdateOAuth2OktaOptions) { + o.Domain = v + o.enabledSetters["Domain"] = true + } +} +func (srv *Project) WithUpdateOAuth2OktaAuthorizationServerId(v string) UpdateOAuth2OktaOption { + return func(o *UpdateOAuth2OktaOptions) { + o.AuthorizationServerId = v + o.enabledSetters["AuthorizationServerId"] = true + } +} +func (srv *Project) WithUpdateOAuth2OktaEnabled(v bool) UpdateOAuth2OktaOption { + return func(o *UpdateOAuth2OktaOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Okta update the project OAuth2 Okta configuration. +func (srv *Project) UpdateOAuth2Okta(optionalSetters ...UpdateOAuth2OktaOption)(*models.OAuth2Okta, error) { + path := "/project/oauth2/okta" + options := UpdateOAuth2OktaOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Domain"] { + params["domain"] = options.Domain + } + if options.enabledSetters["AuthorizationServerId"] { + params["authorizationServerId"] = options.AuthorizationServerId + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Okta{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Okta + parsed, ok := resp.Result.(models.OAuth2Okta) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2PaypalOptions struct { + ClientId string + SecretKey string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2PaypalOptions) New() *UpdateOAuth2PaypalOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "SecretKey": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2PaypalOption func(*UpdateOAuth2PaypalOptions) +func (srv *Project) WithUpdateOAuth2PaypalClientId(v string) UpdateOAuth2PaypalOption { + return func(o *UpdateOAuth2PaypalOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2PaypalSecretKey(v string) UpdateOAuth2PaypalOption { + return func(o *UpdateOAuth2PaypalOptions) { + o.SecretKey = v + o.enabledSetters["SecretKey"] = true + } +} +func (srv *Project) WithUpdateOAuth2PaypalEnabled(v bool) UpdateOAuth2PaypalOption { + return func(o *UpdateOAuth2PaypalOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Paypal update the project OAuth2 Paypal configuration. +func (srv *Project) UpdateOAuth2Paypal(optionalSetters ...UpdateOAuth2PaypalOption)(*models.OAuth2Paypal, error) { + path := "/project/oauth2/paypal" + options := UpdateOAuth2PaypalOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["SecretKey"] { + params["secretKey"] = options.SecretKey + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Paypal{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Paypal + parsed, ok := resp.Result.(models.OAuth2Paypal) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2PaypalSandboxOptions struct { + ClientId string + SecretKey string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2PaypalSandboxOptions) New() *UpdateOAuth2PaypalSandboxOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "SecretKey": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2PaypalSandboxOption func(*UpdateOAuth2PaypalSandboxOptions) +func (srv *Project) WithUpdateOAuth2PaypalSandboxClientId(v string) UpdateOAuth2PaypalSandboxOption { + return func(o *UpdateOAuth2PaypalSandboxOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2PaypalSandboxSecretKey(v string) UpdateOAuth2PaypalSandboxOption { + return func(o *UpdateOAuth2PaypalSandboxOptions) { + o.SecretKey = v + o.enabledSetters["SecretKey"] = true + } +} +func (srv *Project) WithUpdateOAuth2PaypalSandboxEnabled(v bool) UpdateOAuth2PaypalSandboxOption { + return func(o *UpdateOAuth2PaypalSandboxOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2PaypalSandbox update the project OAuth2 PaypalSandbox +// configuration. +func (srv *Project) UpdateOAuth2PaypalSandbox(optionalSetters ...UpdateOAuth2PaypalSandboxOption)(*models.OAuth2Paypal, error) { + path := "/project/oauth2/paypalSandbox" + options := UpdateOAuth2PaypalSandboxOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["SecretKey"] { + params["secretKey"] = options.SecretKey + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Paypal{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Paypal + parsed, ok := resp.Result.(models.OAuth2Paypal) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2PodioOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2PodioOptions) New() *UpdateOAuth2PodioOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2PodioOption func(*UpdateOAuth2PodioOptions) +func (srv *Project) WithUpdateOAuth2PodioClientId(v string) UpdateOAuth2PodioOption { + return func(o *UpdateOAuth2PodioOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2PodioClientSecret(v string) UpdateOAuth2PodioOption { + return func(o *UpdateOAuth2PodioOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2PodioEnabled(v bool) UpdateOAuth2PodioOption { + return func(o *UpdateOAuth2PodioOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Podio update the project OAuth2 Podio configuration. +func (srv *Project) UpdateOAuth2Podio(optionalSetters ...UpdateOAuth2PodioOption)(*models.OAuth2Podio, error) { + path := "/project/oauth2/podio" + options := UpdateOAuth2PodioOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Podio{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Podio + parsed, ok := resp.Result.(models.OAuth2Podio) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2SalesforceOptions struct { + CustomerKey string + CustomerSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2SalesforceOptions) New() *UpdateOAuth2SalesforceOptions { + options.enabledSetters = map[string]bool{ + "CustomerKey": false, + "CustomerSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2SalesforceOption func(*UpdateOAuth2SalesforceOptions) +func (srv *Project) WithUpdateOAuth2SalesforceCustomerKey(v string) UpdateOAuth2SalesforceOption { + return func(o *UpdateOAuth2SalesforceOptions) { + o.CustomerKey = v + o.enabledSetters["CustomerKey"] = true + } +} +func (srv *Project) WithUpdateOAuth2SalesforceCustomerSecret(v string) UpdateOAuth2SalesforceOption { + return func(o *UpdateOAuth2SalesforceOptions) { + o.CustomerSecret = v + o.enabledSetters["CustomerSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2SalesforceEnabled(v bool) UpdateOAuth2SalesforceOption { + return func(o *UpdateOAuth2SalesforceOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Salesforce update the project OAuth2 Salesforce configuration. +func (srv *Project) UpdateOAuth2Salesforce(optionalSetters ...UpdateOAuth2SalesforceOption)(*models.OAuth2Salesforce, error) { + path := "/project/oauth2/salesforce" + options := UpdateOAuth2SalesforceOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["CustomerKey"] { + params["customerKey"] = options.CustomerKey + } + if options.enabledSetters["CustomerSecret"] { + params["customerSecret"] = options.CustomerSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Salesforce{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Salesforce + parsed, ok := resp.Result.(models.OAuth2Salesforce) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2SlackOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2SlackOptions) New() *UpdateOAuth2SlackOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2SlackOption func(*UpdateOAuth2SlackOptions) +func (srv *Project) WithUpdateOAuth2SlackClientId(v string) UpdateOAuth2SlackOption { + return func(o *UpdateOAuth2SlackOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2SlackClientSecret(v string) UpdateOAuth2SlackOption { + return func(o *UpdateOAuth2SlackOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2SlackEnabled(v bool) UpdateOAuth2SlackOption { + return func(o *UpdateOAuth2SlackOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Slack update the project OAuth2 Slack configuration. +func (srv *Project) UpdateOAuth2Slack(optionalSetters ...UpdateOAuth2SlackOption)(*models.OAuth2Slack, error) { + path := "/project/oauth2/slack" + options := UpdateOAuth2SlackOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Slack{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Slack + parsed, ok := resp.Result.(models.OAuth2Slack) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2SpotifyOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2SpotifyOptions) New() *UpdateOAuth2SpotifyOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2SpotifyOption func(*UpdateOAuth2SpotifyOptions) +func (srv *Project) WithUpdateOAuth2SpotifyClientId(v string) UpdateOAuth2SpotifyOption { + return func(o *UpdateOAuth2SpotifyOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2SpotifyClientSecret(v string) UpdateOAuth2SpotifyOption { + return func(o *UpdateOAuth2SpotifyOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2SpotifyEnabled(v bool) UpdateOAuth2SpotifyOption { + return func(o *UpdateOAuth2SpotifyOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Spotify update the project OAuth2 Spotify configuration. +func (srv *Project) UpdateOAuth2Spotify(optionalSetters ...UpdateOAuth2SpotifyOption)(*models.OAuth2Spotify, error) { + path := "/project/oauth2/spotify" + options := UpdateOAuth2SpotifyOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Spotify{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Spotify + parsed, ok := resp.Result.(models.OAuth2Spotify) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2StripeOptions struct { + ClientId string + ApiSecretKey string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2StripeOptions) New() *UpdateOAuth2StripeOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ApiSecretKey": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2StripeOption func(*UpdateOAuth2StripeOptions) +func (srv *Project) WithUpdateOAuth2StripeClientId(v string) UpdateOAuth2StripeOption { + return func(o *UpdateOAuth2StripeOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2StripeApiSecretKey(v string) UpdateOAuth2StripeOption { + return func(o *UpdateOAuth2StripeOptions) { + o.ApiSecretKey = v + o.enabledSetters["ApiSecretKey"] = true + } +} +func (srv *Project) WithUpdateOAuth2StripeEnabled(v bool) UpdateOAuth2StripeOption { + return func(o *UpdateOAuth2StripeOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Stripe update the project OAuth2 Stripe configuration. +func (srv *Project) UpdateOAuth2Stripe(optionalSetters ...UpdateOAuth2StripeOption)(*models.OAuth2Stripe, error) { + path := "/project/oauth2/stripe" + options := UpdateOAuth2StripeOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ApiSecretKey"] { + params["apiSecretKey"] = options.ApiSecretKey + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Stripe{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Stripe + parsed, ok := resp.Result.(models.OAuth2Stripe) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2TradeshiftOptions struct { + Oauth2ClientId string + Oauth2ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2TradeshiftOptions) New() *UpdateOAuth2TradeshiftOptions { + options.enabledSetters = map[string]bool{ + "Oauth2ClientId": false, + "Oauth2ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2TradeshiftOption func(*UpdateOAuth2TradeshiftOptions) +func (srv *Project) WithUpdateOAuth2TradeshiftOauth2ClientId(v string) UpdateOAuth2TradeshiftOption { + return func(o *UpdateOAuth2TradeshiftOptions) { + o.Oauth2ClientId = v + o.enabledSetters["Oauth2ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2TradeshiftOauth2ClientSecret(v string) UpdateOAuth2TradeshiftOption { + return func(o *UpdateOAuth2TradeshiftOptions) { + o.Oauth2ClientSecret = v + o.enabledSetters["Oauth2ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2TradeshiftEnabled(v bool) UpdateOAuth2TradeshiftOption { + return func(o *UpdateOAuth2TradeshiftOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Tradeshift update the project OAuth2 Tradeshift configuration. +func (srv *Project) UpdateOAuth2Tradeshift(optionalSetters ...UpdateOAuth2TradeshiftOption)(*models.OAuth2Tradeshift, error) { + path := "/project/oauth2/tradeshift" + options := UpdateOAuth2TradeshiftOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Oauth2ClientId"] { + params["oauth2ClientId"] = options.Oauth2ClientId + } + if options.enabledSetters["Oauth2ClientSecret"] { + params["oauth2ClientSecret"] = options.Oauth2ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Tradeshift{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Tradeshift + parsed, ok := resp.Result.(models.OAuth2Tradeshift) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2TradeshiftSandboxOptions struct { + Oauth2ClientId string + Oauth2ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2TradeshiftSandboxOptions) New() *UpdateOAuth2TradeshiftSandboxOptions { + options.enabledSetters = map[string]bool{ + "Oauth2ClientId": false, + "Oauth2ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2TradeshiftSandboxOption func(*UpdateOAuth2TradeshiftSandboxOptions) +func (srv *Project) WithUpdateOAuth2TradeshiftSandboxOauth2ClientId(v string) UpdateOAuth2TradeshiftSandboxOption { + return func(o *UpdateOAuth2TradeshiftSandboxOptions) { + o.Oauth2ClientId = v + o.enabledSetters["Oauth2ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2TradeshiftSandboxOauth2ClientSecret(v string) UpdateOAuth2TradeshiftSandboxOption { + return func(o *UpdateOAuth2TradeshiftSandboxOptions) { + o.Oauth2ClientSecret = v + o.enabledSetters["Oauth2ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2TradeshiftSandboxEnabled(v bool) UpdateOAuth2TradeshiftSandboxOption { + return func(o *UpdateOAuth2TradeshiftSandboxOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2TradeshiftSandbox update the project OAuth2 Tradeshift Sandbox +// configuration. +func (srv *Project) UpdateOAuth2TradeshiftSandbox(optionalSetters ...UpdateOAuth2TradeshiftSandboxOption)(*models.OAuth2Tradeshift, error) { + path := "/project/oauth2/tradeshiftBox" + options := UpdateOAuth2TradeshiftSandboxOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Oauth2ClientId"] { + params["oauth2ClientId"] = options.Oauth2ClientId + } + if options.enabledSetters["Oauth2ClientSecret"] { + params["oauth2ClientSecret"] = options.Oauth2ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Tradeshift{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Tradeshift + parsed, ok := resp.Result.(models.OAuth2Tradeshift) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2TwitchOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2TwitchOptions) New() *UpdateOAuth2TwitchOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2TwitchOption func(*UpdateOAuth2TwitchOptions) +func (srv *Project) WithUpdateOAuth2TwitchClientId(v string) UpdateOAuth2TwitchOption { + return func(o *UpdateOAuth2TwitchOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2TwitchClientSecret(v string) UpdateOAuth2TwitchOption { + return func(o *UpdateOAuth2TwitchOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2TwitchEnabled(v bool) UpdateOAuth2TwitchOption { + return func(o *UpdateOAuth2TwitchOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Twitch update the project OAuth2 Twitch configuration. +func (srv *Project) UpdateOAuth2Twitch(optionalSetters ...UpdateOAuth2TwitchOption)(*models.OAuth2Twitch, error) { + path := "/project/oauth2/twitch" + options := UpdateOAuth2TwitchOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Twitch{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Twitch + parsed, ok := resp.Result.(models.OAuth2Twitch) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2WordPressOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2WordPressOptions) New() *UpdateOAuth2WordPressOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2WordPressOption func(*UpdateOAuth2WordPressOptions) +func (srv *Project) WithUpdateOAuth2WordPressClientId(v string) UpdateOAuth2WordPressOption { + return func(o *UpdateOAuth2WordPressOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2WordPressClientSecret(v string) UpdateOAuth2WordPressOption { + return func(o *UpdateOAuth2WordPressOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2WordPressEnabled(v bool) UpdateOAuth2WordPressOption { + return func(o *UpdateOAuth2WordPressOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2WordPress update the project OAuth2 WordPress configuration. +func (srv *Project) UpdateOAuth2WordPress(optionalSetters ...UpdateOAuth2WordPressOption)(*models.OAuth2WordPress, error) { + path := "/project/oauth2/wordpress" + options := UpdateOAuth2WordPressOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2WordPress{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2WordPress + parsed, ok := resp.Result.(models.OAuth2WordPress) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2XOptions struct { + CustomerKey string + SecretKey string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2XOptions) New() *UpdateOAuth2XOptions { + options.enabledSetters = map[string]bool{ + "CustomerKey": false, + "SecretKey": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2XOption func(*UpdateOAuth2XOptions) +func (srv *Project) WithUpdateOAuth2XCustomerKey(v string) UpdateOAuth2XOption { + return func(o *UpdateOAuth2XOptions) { + o.CustomerKey = v + o.enabledSetters["CustomerKey"] = true + } +} +func (srv *Project) WithUpdateOAuth2XSecretKey(v string) UpdateOAuth2XOption { + return func(o *UpdateOAuth2XOptions) { + o.SecretKey = v + o.enabledSetters["SecretKey"] = true + } +} +func (srv *Project) WithUpdateOAuth2XEnabled(v bool) UpdateOAuth2XOption { + return func(o *UpdateOAuth2XOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2X update the project OAuth2 X configuration. +func (srv *Project) UpdateOAuth2X(optionalSetters ...UpdateOAuth2XOption)(*models.OAuth2X, error) { + path := "/project/oauth2/x" + options := UpdateOAuth2XOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["CustomerKey"] { + params["customerKey"] = options.CustomerKey + } + if options.enabledSetters["SecretKey"] { + params["secretKey"] = options.SecretKey + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2X{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2X + parsed, ok := resp.Result.(models.OAuth2X) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2YahooOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2YahooOptions) New() *UpdateOAuth2YahooOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2YahooOption func(*UpdateOAuth2YahooOptions) +func (srv *Project) WithUpdateOAuth2YahooClientId(v string) UpdateOAuth2YahooOption { + return func(o *UpdateOAuth2YahooOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2YahooClientSecret(v string) UpdateOAuth2YahooOption { + return func(o *UpdateOAuth2YahooOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2YahooEnabled(v bool) UpdateOAuth2YahooOption { + return func(o *UpdateOAuth2YahooOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Yahoo update the project OAuth2 Yahoo configuration. +func (srv *Project) UpdateOAuth2Yahoo(optionalSetters ...UpdateOAuth2YahooOption)(*models.OAuth2Yahoo, error) { + path := "/project/oauth2/yahoo" + options := UpdateOAuth2YahooOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Yahoo{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Yahoo + parsed, ok := resp.Result.(models.OAuth2Yahoo) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2YandexOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2YandexOptions) New() *UpdateOAuth2YandexOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2YandexOption func(*UpdateOAuth2YandexOptions) +func (srv *Project) WithUpdateOAuth2YandexClientId(v string) UpdateOAuth2YandexOption { + return func(o *UpdateOAuth2YandexOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2YandexClientSecret(v string) UpdateOAuth2YandexOption { + return func(o *UpdateOAuth2YandexOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2YandexEnabled(v bool) UpdateOAuth2YandexOption { + return func(o *UpdateOAuth2YandexOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Yandex update the project OAuth2 Yandex configuration. +func (srv *Project) UpdateOAuth2Yandex(optionalSetters ...UpdateOAuth2YandexOption)(*models.OAuth2Yandex, error) { + path := "/project/oauth2/yandex" + options := UpdateOAuth2YandexOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Yandex{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Yandex + parsed, ok := resp.Result.(models.OAuth2Yandex) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2ZohoOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2ZohoOptions) New() *UpdateOAuth2ZohoOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2ZohoOption func(*UpdateOAuth2ZohoOptions) +func (srv *Project) WithUpdateOAuth2ZohoClientId(v string) UpdateOAuth2ZohoOption { + return func(o *UpdateOAuth2ZohoOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2ZohoClientSecret(v string) UpdateOAuth2ZohoOption { + return func(o *UpdateOAuth2ZohoOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2ZohoEnabled(v bool) UpdateOAuth2ZohoOption { + return func(o *UpdateOAuth2ZohoOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Zoho update the project OAuth2 Zoho configuration. +func (srv *Project) UpdateOAuth2Zoho(optionalSetters ...UpdateOAuth2ZohoOption)(*models.OAuth2Zoho, error) { + path := "/project/oauth2/zoho" + options := UpdateOAuth2ZohoOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Zoho{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Zoho + parsed, ok := resp.Result.(models.OAuth2Zoho) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2ZoomOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2ZoomOptions) New() *UpdateOAuth2ZoomOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2ZoomOption func(*UpdateOAuth2ZoomOptions) +func (srv *Project) WithUpdateOAuth2ZoomClientId(v string) UpdateOAuth2ZoomOption { + return func(o *UpdateOAuth2ZoomOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2ZoomClientSecret(v string) UpdateOAuth2ZoomOption { + return func(o *UpdateOAuth2ZoomOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2ZoomEnabled(v bool) UpdateOAuth2ZoomOption { + return func(o *UpdateOAuth2ZoomOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Zoom update the project OAuth2 Zoom configuration. +func (srv *Project) UpdateOAuth2Zoom(optionalSetters ...UpdateOAuth2ZoomOption)(*models.OAuth2Zoom, error) { + path := "/project/oauth2/zoom" + options := UpdateOAuth2ZoomOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Zoom{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Zoom + parsed, ok := resp.Result.(models.OAuth2Zoom) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type ListPlatformsOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListPlatformsOptions) New() *ListPlatformsOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + } + return &options +} +type ListPlatformsOption func(*ListPlatformsOptions) +func (srv *Project) WithListPlatformsQueries(v []string) ListPlatformsOption { + return func(o *ListPlatformsOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *Project) WithListPlatformsTotal(v bool) ListPlatformsOption { + return func(o *ListPlatformsOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// ListPlatforms get a list of all platforms in the project. This endpoint +// returns an array of all platforms and their configurations. +func (srv *Project) ListPlatforms(optionalSetters ...ListPlatformsOption)(*models.PlatformList, error) { + path := "/project/platforms" + options := ListPlatformsOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PlatformList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PlatformList + parsed, ok := resp.Result.(models.PlatformList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateAndroidPlatform create a new Android platform for your project. Use +// this endpoint to register a new Android platform where your users will run +// your application which will interact with the Appwrite API. +func (srv *Project) CreateAndroidPlatform(PlatformId string, Name string, ApplicationId string)(*models.PlatformAndroid, error) { + path := "/project/platforms/android" + params := map[string]interface{}{} + params["platformId"] = PlatformId + params["name"] = Name + params["applicationId"] = ApplicationId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PlatformAndroid{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PlatformAndroid + parsed, ok := resp.Result.(models.PlatformAndroid) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateAndroidPlatform update an Android platform by its unique ID. Use this +// endpoint to update the platform's name or application ID. +func (srv *Project) UpdateAndroidPlatform(PlatformId string, Name string, ApplicationId string)(*models.PlatformAndroid, error) { + r := strings.NewReplacer("{platformId}", PlatformId) + path := r.Replace("/project/platforms/android/{platformId}") + params := map[string]interface{}{} + params["platformId"] = PlatformId + params["name"] = Name + params["applicationId"] = ApplicationId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PlatformAndroid{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PlatformAndroid + parsed, ok := resp.Result.(models.PlatformAndroid) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateApplePlatform create a new Apple platform for your project. Use this +// endpoint to register a new Apple platform where your users will run your +// application which will interact with the Appwrite API. +func (srv *Project) CreateApplePlatform(PlatformId string, Name string, BundleIdentifier string)(*models.PlatformApple, error) { + path := "/project/platforms/apple" + params := map[string]interface{}{} + params["platformId"] = PlatformId + params["name"] = Name + params["bundleIdentifier"] = BundleIdentifier + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PlatformApple{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PlatformApple + parsed, ok := resp.Result.(models.PlatformApple) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateApplePlatform update an Apple platform by its unique ID. Use this +// endpoint to update the platform's name or bundle identifier. +func (srv *Project) UpdateApplePlatform(PlatformId string, Name string, BundleIdentifier string)(*models.PlatformApple, error) { + r := strings.NewReplacer("{platformId}", PlatformId) + path := r.Replace("/project/platforms/apple/{platformId}") + params := map[string]interface{}{} + params["platformId"] = PlatformId + params["name"] = Name + params["bundleIdentifier"] = BundleIdentifier + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PlatformApple{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PlatformApple + parsed, ok := resp.Result.(models.PlatformApple) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateLinuxPlatform create a new Linux platform for your project. Use this +// endpoint to register a new Linux platform where your users will run your +// application which will interact with the Appwrite API. +func (srv *Project) CreateLinuxPlatform(PlatformId string, Name string, PackageName string)(*models.PlatformLinux, error) { + path := "/project/platforms/linux" + params := map[string]interface{}{} + params["platformId"] = PlatformId + params["name"] = Name + params["packageName"] = PackageName + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PlatformLinux{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PlatformLinux + parsed, ok := resp.Result.(models.PlatformLinux) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateLinuxPlatform update a Linux platform by its unique ID. Use this +// endpoint to update the platform's name or package name. +func (srv *Project) UpdateLinuxPlatform(PlatformId string, Name string, PackageName string)(*models.PlatformLinux, error) { + r := strings.NewReplacer("{platformId}", PlatformId) + path := r.Replace("/project/platforms/linux/{platformId}") + params := map[string]interface{}{} + params["platformId"] = PlatformId + params["name"] = Name + params["packageName"] = PackageName + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PlatformLinux{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PlatformLinux + parsed, ok := resp.Result.(models.PlatformLinux) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateWebPlatform create a new web platform for your project. Use this +// endpoint to register a new platform where your users will run your +// application which will interact with the Appwrite API. +func (srv *Project) CreateWebPlatform(PlatformId string, Name string, Hostname string)(*models.PlatformWeb, error) { + path := "/project/platforms/web" + params := map[string]interface{}{} + params["platformId"] = PlatformId + params["name"] = Name + params["hostname"] = Hostname + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PlatformWeb{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PlatformWeb + parsed, ok := resp.Result.(models.PlatformWeb) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateWebPlatform update a web platform by its unique ID. Use this endpoint +// to update the platform's name or hostname. +func (srv *Project) UpdateWebPlatform(PlatformId string, Name string, Hostname string)(*models.PlatformWeb, error) { + r := strings.NewReplacer("{platformId}", PlatformId) + path := r.Replace("/project/platforms/web/{platformId}") + params := map[string]interface{}{} + params["platformId"] = PlatformId + params["name"] = Name + params["hostname"] = Hostname + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) if err != nil { return nil, err } @@ -640,36 +4908,793 @@ func (srv *Project) CreateWebPlatform(PlatformId string, Name string, Hostname s return parsed, nil } - var parsed models.PlatformWeb - parsed, ok := resp.Result.(models.PlatformWeb) + var parsed models.PlatformWeb + parsed, ok := resp.Result.(models.PlatformWeb) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateWindowsPlatform create a new Windows platform for your project. Use +// this endpoint to register a new Windows platform where your users will run +// your application which will interact with the Appwrite API. +func (srv *Project) CreateWindowsPlatform(PlatformId string, Name string, PackageIdentifierName string)(*models.PlatformWindows, error) { + path := "/project/platforms/windows" + params := map[string]interface{}{} + params["platformId"] = PlatformId + params["name"] = Name + params["packageIdentifierName"] = PackageIdentifierName + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PlatformWindows{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PlatformWindows + parsed, ok := resp.Result.(models.PlatformWindows) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateWindowsPlatform update a Windows platform by its unique ID. Use this +// endpoint to update the platform's name or package identifier name. +func (srv *Project) UpdateWindowsPlatform(PlatformId string, Name string, PackageIdentifierName string)(*models.PlatformWindows, error) { + r := strings.NewReplacer("{platformId}", PlatformId) + path := r.Replace("/project/platforms/windows/{platformId}") + params := map[string]interface{}{} + params["platformId"] = PlatformId + params["name"] = Name + params["packageIdentifierName"] = PackageIdentifierName + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PlatformWindows{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PlatformWindows + parsed, ok := resp.Result.(models.PlatformWindows) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetPlatform get a platform by its unique ID. This endpoint returns the +// platform's details, including its name, type, and key configurations. +func (srv *Project) GetPlatform(PlatformId string)(models.Model, error) { + r := strings.NewReplacer("{platformId}", PlatformId) + path := r.Replace("/project/platforms/{platformId}") + params := map[string]interface{}{} + params["platformId"] = PlatformId + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var response map[string]interface{} + if err := json.Unmarshal(bytes, &response); err != nil { + return nil, err + } + if fmt.Sprint(response["type"]) == "web" { + parsed := models.PlatformWeb{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["type"]) == "apple" { + parsed := models.PlatformApple{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["type"]) == "android" { + parsed := models.PlatformAndroid{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["type"]) == "windows" { + parsed := models.PlatformWindows{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["type"]) == "linux" { + parsed := models.PlatformLinux{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + + return nil, errors.New("unable to match response to any expected response model") + } + parsed, ok := resp.Result.(models.Model) + if !ok { + return nil, errors.New("unexpected response type") + } + return parsed, nil + +} + +// DeletePlatform delete a platform by its unique ID. This endpoint removes +// the platform and all its configurations from the project. +func (srv *Project) DeletePlatform(PlatformId string)(*interface{}, error) { + r := strings.NewReplacer("{platformId}", PlatformId) + path := r.Replace("/project/platforms/{platformId}") + params := map[string]interface{}{} + params["platformId"] = PlatformId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type ListPoliciesOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListPoliciesOptions) New() *ListPoliciesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + } + return &options +} +type ListPoliciesOption func(*ListPoliciesOptions) +func (srv *Project) WithListPoliciesQueries(v []string) ListPoliciesOption { + return func(o *ListPoliciesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *Project) WithListPoliciesTotal(v bool) ListPoliciesOption { + return func(o *ListPoliciesOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// ListPolicies get a list of all project policies and their current +// configuration. +func (srv *Project) ListPolicies(optionalSetters ...ListPoliciesOption)(*models.PolicyList, error) { + path := "/project/policies" + options := ListPoliciesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PolicyList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PolicyList + parsed, ok := resp.Result.(models.PolicyList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateMembershipPrivacyPolicyOptions struct { + UserId bool + UserEmail bool + UserPhone bool + UserName bool + UserMFA bool + enabledSetters map[string]bool +} +func (options UpdateMembershipPrivacyPolicyOptions) New() *UpdateMembershipPrivacyPolicyOptions { + options.enabledSetters = map[string]bool{ + "UserId": false, + "UserEmail": false, + "UserPhone": false, + "UserName": false, + "UserMFA": false, + } + return &options +} +type UpdateMembershipPrivacyPolicyOption func(*UpdateMembershipPrivacyPolicyOptions) +func (srv *Project) WithUpdateMembershipPrivacyPolicyUserId(v bool) UpdateMembershipPrivacyPolicyOption { + return func(o *UpdateMembershipPrivacyPolicyOptions) { + o.UserId = v + o.enabledSetters["UserId"] = true + } +} +func (srv *Project) WithUpdateMembershipPrivacyPolicyUserEmail(v bool) UpdateMembershipPrivacyPolicyOption { + return func(o *UpdateMembershipPrivacyPolicyOptions) { + o.UserEmail = v + o.enabledSetters["UserEmail"] = true + } +} +func (srv *Project) WithUpdateMembershipPrivacyPolicyUserPhone(v bool) UpdateMembershipPrivacyPolicyOption { + return func(o *UpdateMembershipPrivacyPolicyOptions) { + o.UserPhone = v + o.enabledSetters["UserPhone"] = true + } +} +func (srv *Project) WithUpdateMembershipPrivacyPolicyUserName(v bool) UpdateMembershipPrivacyPolicyOption { + return func(o *UpdateMembershipPrivacyPolicyOptions) { + o.UserName = v + o.enabledSetters["UserName"] = true + } +} +func (srv *Project) WithUpdateMembershipPrivacyPolicyUserMFA(v bool) UpdateMembershipPrivacyPolicyOption { + return func(o *UpdateMembershipPrivacyPolicyOptions) { + o.UserMFA = v + o.enabledSetters["UserMFA"] = true + } +} + +// UpdateMembershipPrivacyPolicy updating this policy allows you to control if +// team members can see other members information. When enabled, all team +// members can see ID, name, email, phone number, and MFA status of other +// members.. +func (srv *Project) UpdateMembershipPrivacyPolicy(optionalSetters ...UpdateMembershipPrivacyPolicyOption)(*models.Project, error) { + path := "/project/policies/membership-privacy" + options := UpdateMembershipPrivacyPolicyOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["UserId"] { + params["userId"] = options.UserId + } + if options.enabledSetters["UserEmail"] { + params["userEmail"] = options.UserEmail + } + if options.enabledSetters["UserPhone"] { + params["userPhone"] = options.UserPhone + } + if options.enabledSetters["UserName"] { + params["userName"] = options.UserName + } + if options.enabledSetters["UserMFA"] { + params["userMFA"] = options.UserMFA + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Project{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Project + parsed, ok := resp.Result.(models.Project) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePasswordDictionaryPolicy updating this policy allows you to control +// if new passwords are checked against most common passwords dictionary. When +// enabled, and user changes their password, password must not be contained in +// the dictionary. +func (srv *Project) UpdatePasswordDictionaryPolicy(Enabled bool)(*models.Project, error) { + path := "/project/policies/password-dictionary" + params := map[string]interface{}{} + params["enabled"] = Enabled + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Project{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Project + parsed, ok := resp.Result.(models.Project) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePasswordHistoryPolicy updates one of password strength policies. +// Based on total length configured, previous password hashes are stored, and +// users cannot choose a new password that is already stored in the passwird +// history list, when updating an user password, or setting new one through +// password recovery. +// +// Keep in mind, while password history policy is disabled, the history is not +// being stored. Enabling the policy will not have any history on existing +// users, and it will only start to collect and enforce the policy on password +// changes since the policy is enabled. +func (srv *Project) UpdatePasswordHistoryPolicy(Total int)(*models.Project, error) { + path := "/project/policies/password-history" + params := map[string]interface{}{} + params["total"] = Total + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Project{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Project + parsed, ok := resp.Result.(models.Project) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdatePasswordPersonalDataPolicy updating this policy allows you to control +// if password strength is checked against personal data. When enabled, and +// user sets or changes their password, the password must not contain user ID, +// name, email or phone number. +func (srv *Project) UpdatePasswordPersonalDataPolicy(Enabled bool)(*models.Project, error) { + path := "/project/policies/password-personal-data" + params := map[string]interface{}{} + params["enabled"] = Enabled + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Project{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Project + parsed, ok := resp.Result.(models.Project) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } - -// UpdateWebPlatform update a web platform by its unique ID. Use this endpoint -// to update the platform's name or hostname. -func (srv *Project) UpdateWebPlatform(PlatformId string, Name string, Hostname string)(*models.PlatformWeb, error) { - r := strings.NewReplacer("{platformId}", PlatformId) - path := r.Replace("/project/platforms/web/{platformId}") + +// UpdateSessionAlertPolicy updating this policy allows you to control if +// email alert is sent upon session creation. When enabled, and user signs +// into their account, they will be sent an email notification. There is an +// exception, the first session after a new sign up does not trigger an alert, +// even if the policy is enabled. +func (srv *Project) UpdateSessionAlertPolicy(Enabled bool)(*models.Project, error) { + path := "/project/policies/session-alert" + params := map[string]interface{}{} + params["enabled"] = Enabled + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Project{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Project + parsed, ok := resp.Result.(models.Project) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateSessionDurationPolicy update maximum duration how long sessions +// created within a project should stay active for. +func (srv *Project) UpdateSessionDurationPolicy(Duration int)(*models.Project, error) { + path := "/project/policies/session-duration" + params := map[string]interface{}{} + params["duration"] = Duration + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Project{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Project + parsed, ok := resp.Result.(models.Project) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateSessionInvalidationPolicy updating this policy allows you to control +// if existing sessions should be invalidated when a password of a user is +// changed. When enabled, and user changes their password, they will be logged +// out of all their devices. +func (srv *Project) UpdateSessionInvalidationPolicy(Enabled bool)(*models.Project, error) { + path := "/project/policies/session-invalidation" + params := map[string]interface{}{} + params["enabled"] = Enabled + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Project{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Project + parsed, ok := resp.Result.(models.Project) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateSessionLimitPolicy update the maximum number of sessions allowed per +// user. When the limit is hit, the oldest session will be deleted to make +// room for new one. +func (srv *Project) UpdateSessionLimitPolicy(Total int)(*models.Project, error) { + path := "/project/policies/session-limit" + params := map[string]interface{}{} + params["total"] = Total + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Project{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Project + parsed, ok := resp.Result.(models.Project) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateUserLimitPolicy update the maximum number of users in the project. +// When the limit is hit or amount of existing users already exceeded the +// limit, all users remain active, but new user sign up will be prohibited. +func (srv *Project) UpdateUserLimitPolicy(Total int)(*models.Project, error) { + path := "/project/policies/user-limit" + params := map[string]interface{}{} + params["total"] = Total + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Project{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Project + parsed, ok := resp.Result.(models.Project) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetPolicy get a policy by its unique ID. This endpoint returns the current +// configuration for the requested project policy. +func (srv *Project) GetPolicy(PolicyId string)(models.Model, error) { + r := strings.NewReplacer("{policyId}", PolicyId) + path := r.Replace("/project/policies/{policyId}") + params := map[string]interface{}{} + params["policyId"] = PolicyId + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var response map[string]interface{} + if err := json.Unmarshal(bytes, &response); err != nil { + return nil, err + } + if fmt.Sprint(response["$id"]) == "password-dictionary" { + parsed := models.PolicyPasswordDictionary{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "password-history" { + parsed := models.PolicyPasswordHistory{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "password-personal-data" { + parsed := models.PolicyPasswordPersonalData{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "session-alert" { + parsed := models.PolicySessionAlert{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "session-duration" { + parsed := models.PolicySessionDuration{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "session-invalidation" { + parsed := models.PolicySessionInvalidation{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "session-limit" { + parsed := models.PolicySessionLimit{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "user-limit" { + parsed := models.PolicyUserLimit{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "membership-privacy" { + parsed := models.PolicyMembershipPrivacy{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + + return nil, errors.New("unable to match response to any expected response model") + } + parsed, ok := resp.Result.(models.Model) + if !ok { + return nil, errors.New("unexpected response type") + } + return parsed, nil + +} + +// UpdateProtocol update properties of a specific protocol. Use this endpoint +// to enable or disable a protocol in your project. +func (srv *Project) UpdateProtocol(ProtocolId string, Enabled bool)(*models.Project, error) { + r := strings.NewReplacer("{protocolId}", ProtocolId) + path := r.Replace("/project/protocols/{protocolId}") params := map[string]interface{}{} - params["platformId"] = PlatformId - params["name"] = Name - params["hostname"] = Hostname + params["protocolId"] = ProtocolId + params["enabled"] = Enabled headers := map[string]interface{}{ "content-type": "application/json", } - resp, err := srv.client.Call("PUT", path, headers, params) + resp, err := srv.client.Call("PATCH", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.PlatformWeb{}.New(bytes) + parsed := models.Project{}.New(bytes) err = json.Unmarshal(bytes, parsed) if err != nil { @@ -678,36 +5703,35 @@ func (srv *Project) UpdateWebPlatform(PlatformId string, Name string, Hostname s return parsed, nil } - var parsed models.PlatformWeb - parsed, ok := resp.Result.(models.PlatformWeb) + var parsed models.Project + parsed, ok := resp.Result.(models.Project) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } - -// CreateWindowsPlatform create a new Windows platform for your project. Use -// this endpoint to register a new Windows platform where your users will run -// your application which will interact with the Appwrite API. -func (srv *Project) CreateWindowsPlatform(PlatformId string, Name string, PackageIdentifierName string)(*models.PlatformWindows, error) { - path := "/project/platforms/windows" + +// UpdateService update properties of a specific service. Use this endpoint to +// enable or disable a service in your project. +func (srv *Project) UpdateService(ServiceId string, Enabled bool)(*models.Project, error) { + r := strings.NewReplacer("{serviceId}", ServiceId) + path := r.Replace("/project/services/{serviceId}") params := map[string]interface{}{} - params["platformId"] = PlatformId - params["name"] = Name - params["packageIdentifierName"] = PackageIdentifierName + params["serviceId"] = ServiceId + params["enabled"] = Enabled headers := map[string]interface{}{ "content-type": "application/json", } - resp, err := srv.client.Call("POST", path, headers, params) + resp, err := srv.client.Call("PATCH", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.PlatformWindows{}.New(bytes) + parsed := models.Project{}.New(bytes) err = json.Unmarshal(bytes, parsed) if err != nil { @@ -716,36 +5740,156 @@ func (srv *Project) CreateWindowsPlatform(PlatformId string, Name string, Packag return parsed, nil } - var parsed models.PlatformWindows - parsed, ok := resp.Result.(models.PlatformWindows) + var parsed models.Project + parsed, ok := resp.Result.(models.Project) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } - -// UpdateWindowsPlatform update a Windows platform by its unique ID. Use this -// endpoint to update the platform's name or package identifier name. -func (srv *Project) UpdateWindowsPlatform(PlatformId string, Name string, PackageIdentifierName string)(*models.PlatformWindows, error) { - r := strings.NewReplacer("{platformId}", PlatformId) - path := r.Replace("/project/platforms/windows/{platformId}") +type UpdateSMTPOptions struct { + Host string + Port int + Username string + Password string + SenderEmail string + SenderName string + ReplyToEmail string + ReplyToName string + Secure string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateSMTPOptions) New() *UpdateSMTPOptions { + options.enabledSetters = map[string]bool{ + "Host": false, + "Port": false, + "Username": false, + "Password": false, + "SenderEmail": false, + "SenderName": false, + "ReplyToEmail": false, + "ReplyToName": false, + "Secure": false, + "Enabled": false, + } + return &options +} +type UpdateSMTPOption func(*UpdateSMTPOptions) +func (srv *Project) WithUpdateSMTPHost(v string) UpdateSMTPOption { + return func(o *UpdateSMTPOptions) { + o.Host = v + o.enabledSetters["Host"] = true + } +} +func (srv *Project) WithUpdateSMTPPort(v int) UpdateSMTPOption { + return func(o *UpdateSMTPOptions) { + o.Port = v + o.enabledSetters["Port"] = true + } +} +func (srv *Project) WithUpdateSMTPUsername(v string) UpdateSMTPOption { + return func(o *UpdateSMTPOptions) { + o.Username = v + o.enabledSetters["Username"] = true + } +} +func (srv *Project) WithUpdateSMTPPassword(v string) UpdateSMTPOption { + return func(o *UpdateSMTPOptions) { + o.Password = v + o.enabledSetters["Password"] = true + } +} +func (srv *Project) WithUpdateSMTPSenderEmail(v string) UpdateSMTPOption { + return func(o *UpdateSMTPOptions) { + o.SenderEmail = v + o.enabledSetters["SenderEmail"] = true + } +} +func (srv *Project) WithUpdateSMTPSenderName(v string) UpdateSMTPOption { + return func(o *UpdateSMTPOptions) { + o.SenderName = v + o.enabledSetters["SenderName"] = true + } +} +func (srv *Project) WithUpdateSMTPReplyToEmail(v string) UpdateSMTPOption { + return func(o *UpdateSMTPOptions) { + o.ReplyToEmail = v + o.enabledSetters["ReplyToEmail"] = true + } +} +func (srv *Project) WithUpdateSMTPReplyToName(v string) UpdateSMTPOption { + return func(o *UpdateSMTPOptions) { + o.ReplyToName = v + o.enabledSetters["ReplyToName"] = true + } +} +func (srv *Project) WithUpdateSMTPSecure(v string) UpdateSMTPOption { + return func(o *UpdateSMTPOptions) { + o.Secure = v + o.enabledSetters["Secure"] = true + } +} +func (srv *Project) WithUpdateSMTPEnabled(v bool) UpdateSMTPOption { + return func(o *UpdateSMTPOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateSMTP update the SMTP configuration for your project. Use this +// endpoint to configure your project's SMTP provider with your custom +// settings for sending transactional emails. +func (srv *Project) UpdateSMTP(optionalSetters ...UpdateSMTPOption)(*models.Project, error) { + path := "/project/smtp" + options := UpdateSMTPOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } params := map[string]interface{}{} - params["platformId"] = PlatformId - params["name"] = Name - params["packageIdentifierName"] = PackageIdentifierName + if options.enabledSetters["Host"] { + params["host"] = options.Host + } + if options.enabledSetters["Port"] { + params["port"] = options.Port + } + if options.enabledSetters["Username"] { + params["username"] = options.Username + } + if options.enabledSetters["Password"] { + params["password"] = options.Password + } + if options.enabledSetters["SenderEmail"] { + params["senderEmail"] = options.SenderEmail + } + if options.enabledSetters["SenderName"] { + params["senderName"] = options.SenderName + } + if options.enabledSetters["ReplyToEmail"] { + params["replyToEmail"] = options.ReplyToEmail + } + if options.enabledSetters["ReplyToName"] { + params["replyToName"] = options.ReplyToName + } + if options.enabledSetters["Secure"] { + params["secure"] = options.Secure + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } headers := map[string]interface{}{ "content-type": "application/json", } - resp, err := srv.client.Call("PUT", path, headers, params) + resp, err := srv.client.Call("PATCH", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.PlatformWindows{}.New(bytes) + parsed := models.Project{}.New(bytes) err = json.Unmarshal(bytes, parsed) if err != nil { @@ -754,8 +5898,8 @@ func (srv *Project) UpdateWindowsPlatform(PlatformId string, Name string, Packag return parsed, nil } - var parsed models.PlatformWindows - parsed, ok := resp.Result.(models.PlatformWindows) + var parsed models.Project + parsed, ok := resp.Result.(models.Project) if !ok { return nil, errors.New("unexpected response type") } @@ -763,121 +5907,204 @@ func (srv *Project) UpdateWindowsPlatform(PlatformId string, Name string, Packag } -// GetPlatform get a platform by its unique ID. This endpoint returns the -// platform's details, including its name, type, and key configurations. -func (srv *Project) GetPlatform(PlatformId string)(models.Model, error) { - r := strings.NewReplacer("{platformId}", PlatformId) - path := r.Replace("/project/platforms/{platformId}") +// CreateSMTPTest send a test email to verify SMTP configuration. +func (srv *Project) CreateSMTPTest(Emails []string)(*interface{}, error) { + path := "/project/smtp/tests" params := map[string]interface{}{} - params["platformId"] = PlatformId + params["emails"] = Emails headers := map[string]interface{}{ + "content-type": "application/json", } - resp, err := srv.client.Call("GET", path, headers, params) + resp, err := srv.client.Call("POST", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - var response map[string]interface{} - if err := json.Unmarshal(bytes, &response); err != nil { - return nil, err - } - if fmt.Sprint(response["type"]) == "web" { - parsed := models.PlatformWeb{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["type"]) == "apple" { - parsed := models.PlatformApple{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["type"]) == "android" { - parsed := models.PlatformAndroid{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["type"]) == "windows" { - parsed := models.PlatformWindows{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["type"]) == "linux" { - parsed := models.PlatformLinux{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } + var parsed interface{} - return parsed, nil + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err } - - return nil, errors.New("unable to match response to any expected response model") + return &parsed, nil } - parsed, ok := resp.Result.(models.Model) + var parsed interface{} + parsed, ok := resp.Result.(interface{}) if !ok { return nil, errors.New("unexpected response type") } - return parsed, nil + return &parsed, nil } +type ListEmailTemplatesOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListEmailTemplatesOptions) New() *ListEmailTemplatesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + } + return &options +} +type ListEmailTemplatesOption func(*ListEmailTemplatesOptions) +func (srv *Project) WithListEmailTemplatesQueries(v []string) ListEmailTemplatesOption { + return func(o *ListEmailTemplatesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *Project) WithListEmailTemplatesTotal(v bool) ListEmailTemplatesOption { + return func(o *ListEmailTemplatesOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} -// DeletePlatform delete a platform by its unique ID. This endpoint removes -// the platform and all its configurations from the project. -func (srv *Project) DeletePlatform(PlatformId string)(*interface{}, error) { - r := strings.NewReplacer("{platformId}", PlatformId) - path := r.Replace("/project/platforms/{platformId}") +// ListEmailTemplates get a list of all custom email templates configured for +// the project. This endpoint returns an array of all configured email +// templates and their locales. +func (srv *Project) ListEmailTemplates(optionalSetters ...ListEmailTemplatesOption)(*models.EmailTemplateList, error) { + path := "/project/templates/email" + options := ListEmailTemplatesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } params := map[string]interface{}{} - params["platformId"] = PlatformId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } headers := map[string]interface{}{ - "content-type": "application/json", } - resp, err := srv.client.Call("DELETE", path, headers, params) + resp, err := srv.client.Call("GET", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - var parsed interface{} + parsed := models.EmailTemplateList{}.New(bytes) - err = json.Unmarshal(bytes, &parsed) + err = json.Unmarshal(bytes, parsed) if err != nil { return nil, err } - return &parsed, nil + + return parsed, nil } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) + var parsed models.EmailTemplateList + parsed, ok := resp.Result.(models.EmailTemplateList) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } +type UpdateEmailTemplateOptions struct { + Locale string + Subject string + Message string + SenderName string + SenderEmail string + ReplyToEmail string + ReplyToName string + enabledSetters map[string]bool +} +func (options UpdateEmailTemplateOptions) New() *UpdateEmailTemplateOptions { + options.enabledSetters = map[string]bool{ + "Locale": false, + "Subject": false, + "Message": false, + "SenderName": false, + "SenderEmail": false, + "ReplyToEmail": false, + "ReplyToName": false, + } + return &options +} +type UpdateEmailTemplateOption func(*UpdateEmailTemplateOptions) +func (srv *Project) WithUpdateEmailTemplateLocale(v string) UpdateEmailTemplateOption { + return func(o *UpdateEmailTemplateOptions) { + o.Locale = v + o.enabledSetters["Locale"] = true + } +} +func (srv *Project) WithUpdateEmailTemplateSubject(v string) UpdateEmailTemplateOption { + return func(o *UpdateEmailTemplateOptions) { + o.Subject = v + o.enabledSetters["Subject"] = true + } +} +func (srv *Project) WithUpdateEmailTemplateMessage(v string) UpdateEmailTemplateOption { + return func(o *UpdateEmailTemplateOptions) { + o.Message = v + o.enabledSetters["Message"] = true + } +} +func (srv *Project) WithUpdateEmailTemplateSenderName(v string) UpdateEmailTemplateOption { + return func(o *UpdateEmailTemplateOptions) { + o.SenderName = v + o.enabledSetters["SenderName"] = true + } +} +func (srv *Project) WithUpdateEmailTemplateSenderEmail(v string) UpdateEmailTemplateOption { + return func(o *UpdateEmailTemplateOptions) { + o.SenderEmail = v + o.enabledSetters["SenderEmail"] = true + } +} +func (srv *Project) WithUpdateEmailTemplateReplyToEmail(v string) UpdateEmailTemplateOption { + return func(o *UpdateEmailTemplateOptions) { + o.ReplyToEmail = v + o.enabledSetters["ReplyToEmail"] = true + } +} +func (srv *Project) WithUpdateEmailTemplateReplyToName(v string) UpdateEmailTemplateOption { + return func(o *UpdateEmailTemplateOptions) { + o.ReplyToName = v + o.enabledSetters["ReplyToName"] = true + } +} -// UpdateProtocolStatus update the status of a specific protocol. Use this -// endpoint to enable or disable a protocol in your project. -func (srv *Project) UpdateProtocolStatus(ProtocolId string, Enabled bool)(*models.Project, error) { - r := strings.NewReplacer("{protocolId}", ProtocolId) - path := r.Replace("/project/protocols/{protocolId}/status") +// UpdateEmailTemplate update a custom email template for the specified locale +// and type. Use this endpoint to modify the content of your email templates. +func (srv *Project) UpdateEmailTemplate(TemplateId string, optionalSetters ...UpdateEmailTemplateOption)(*models.EmailTemplate, error) { + path := "/project/templates/email" + options := UpdateEmailTemplateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } params := map[string]interface{}{} - params["protocolId"] = ProtocolId - params["enabled"] = Enabled + params["templateId"] = TemplateId + if options.enabledSetters["Locale"] { + params["locale"] = options.Locale + } + if options.enabledSetters["Subject"] { + params["subject"] = options.Subject + } + if options.enabledSetters["Message"] { + params["message"] = options.Message + } + if options.enabledSetters["SenderName"] { + params["senderName"] = options.SenderName + } + if options.enabledSetters["SenderEmail"] { + params["senderEmail"] = options.SenderEmail + } + if options.enabledSetters["ReplyToEmail"] { + params["replyToEmail"] = options.ReplyToEmail + } + if options.enabledSetters["ReplyToName"] { + params["replyToName"] = options.ReplyToName + } headers := map[string]interface{}{ "content-type": "application/json", } @@ -889,7 +6116,7 @@ func (srv *Project) UpdateProtocolStatus(ProtocolId string, Enabled bool)(*model if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.Project{}.New(bytes) + parsed := models.EmailTemplate{}.New(bytes) err = json.Unmarshal(bytes, parsed) if err != nil { @@ -898,35 +6125,58 @@ func (srv *Project) UpdateProtocolStatus(ProtocolId string, Enabled bool)(*model return parsed, nil } - var parsed models.Project - parsed, ok := resp.Result.(models.Project) + var parsed models.EmailTemplate + parsed, ok := resp.Result.(models.EmailTemplate) if !ok { return nil, errors.New("unexpected response type") } return &parsed, nil } +type GetEmailTemplateOptions struct { + Locale string + enabledSetters map[string]bool +} +func (options GetEmailTemplateOptions) New() *GetEmailTemplateOptions { + options.enabledSetters = map[string]bool{ + "Locale": false, + } + return &options +} +type GetEmailTemplateOption func(*GetEmailTemplateOptions) +func (srv *Project) WithGetEmailTemplateLocale(v string) GetEmailTemplateOption { + return func(o *GetEmailTemplateOptions) { + o.Locale = v + o.enabledSetters["Locale"] = true + } +} -// UpdateServiceStatus update the status of a specific service. Use this -// endpoint to enable or disable a service in your project. -func (srv *Project) UpdateServiceStatus(ServiceId string, Enabled bool)(*models.Project, error) { - r := strings.NewReplacer("{serviceId}", ServiceId) - path := r.Replace("/project/services/{serviceId}/status") +// GetEmailTemplate get a custom email template for the specified locale and +// type. This endpoint returns the template content, subject, and other +// configuration details. +func (srv *Project) GetEmailTemplate(TemplateId string, optionalSetters ...GetEmailTemplateOption)(*models.EmailTemplate, error) { + r := strings.NewReplacer("{templateId}", TemplateId) + path := r.Replace("/project/templates/email/{templateId}") + options := GetEmailTemplateOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } params := map[string]interface{}{} - params["serviceId"] = ServiceId - params["enabled"] = Enabled + params["templateId"] = TemplateId + if options.enabledSetters["Locale"] { + params["locale"] = options.Locale + } headers := map[string]interface{}{ - "content-type": "application/json", } - resp, err := srv.client.Call("PATCH", path, headers, params) + resp, err := srv.client.Call("GET", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - parsed := models.Project{}.New(bytes) + parsed := models.EmailTemplate{}.New(bytes) err = json.Unmarshal(bytes, parsed) if err != nil { @@ -935,8 +6185,8 @@ func (srv *Project) UpdateServiceStatus(ServiceId string, Enabled bool)(*models. return parsed, nil } - var parsed models.Project - parsed, ok := resp.Result.(models.Project) + var parsed models.EmailTemplate + parsed, ok := resp.Result.(models.EmailTemplate) if !ok { return nil, errors.New("unexpected response type") } diff --git a/project/project_test.go b/project/project_test.go index bdf9233f..f0fbb0eb 100644 --- a/project/project_test.go +++ b/project/project_test.go @@ -17,6 +17,212 @@ func TestProject(t *testing.T) { return c } + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete() + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) + + t.Run("Test UpdateAuthMethod", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateAuthMethod("email-password", true) + if err != nil { + t.Errorf("Method UpdateAuthMethod failed: %v", err) + } + }) + t.Run("Test ListKeys", func(t *testing.T) { mockResponse := ` { @@ -90,6 +296,40 @@ func TestProject(t *testing.T) { } }) + t.Run("Test CreateEphemeralKey", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateEphemeralKey([]string{}, 1) + if err != nil { + t.Errorf("Method CreateEphemeralKey failed: %v", err) + } + }) + t.Run("Test GetKey", func(t *testing.T) { mockResponse := ` { @@ -212,21 +452,25 @@ func TestProject(t *testing.T) { "authFreeEmails": true, "authMockNumbers": [ { - "phone": "+1612842323", - "otp": "123456" + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" } ], "authSessionAlerts": true, "authMembershipsUserName": true, "authMembershipsUserEmail": true, "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, "authInvalidateSessions": true, "oAuthProviders": [ { "key": "github", "name": "GitHub", "appId": "259125845563242502", - "secret": "Bpw_g9c2TGXxfgLshDbSaL8tsCcqgczQ", + "secret": "string", "enabled": true } ], @@ -276,11 +520,12 @@ func TestProject(t *testing.T) { "smtpEnabled": true, "smtpSenderName": "John Appwrite", "smtpSenderEmail": "john@appwrite.io", - "smtpReplyTo": "support@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", "smtpHost": "mail.appwrite.io", "smtpPort": 25, "smtpUsername": "emailuser", - "smtpPassword": "securepassword", + "smtpPassword": "string", "smtpSecure": "tls", "pingCount": 1, "pingedAt": "2020-10-15T06:38:00.000+00:00", @@ -328,7 +573,12 @@ func TestProject(t *testing.T) { { "$createdAt": "2020-10-15T06:38:00.000+00:00", "resourceType": "project", - "resourceId": "5e5ea5c16897e" + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" } ], "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" @@ -354,11 +604,18 @@ func TestProject(t *testing.T) { } }) - t.Run("Test ListPlatforms", func(t *testing.T) { + t.Run("Test ListMockPhones", func(t *testing.T) { mockResponse := ` { "total": 5, - "platforms": [] + "mockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ] } ` @@ -375,21 +632,19 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.ListPlatforms() + _, err := srv.ListMockPhones() if err != nil { - t.Errorf("Method ListPlatforms failed: %v", err) + t.Errorf("Method ListMockPhones failed: %v", err) } }) - t.Run("Test CreateAndroidPlatform", func(t *testing.T) { + t.Run("Test CreateMockPhone", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", + "number": "+1612842323", + "otp": "123456", "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "web", - "applicationId": "com.company.appname" + "$updatedAt": "2020-10-15T06:38:00.000+00:00" } ` @@ -406,27 +661,25 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.CreateAndroidPlatform("", "", "") + _, err := srv.CreateMockPhone("+12065550100", "") if err != nil { - t.Errorf("Method CreateAndroidPlatform failed: %v", err) + t.Errorf("Method CreateMockPhone failed: %v", err) } }) - t.Run("Test UpdateAndroidPlatform", func(t *testing.T) { + t.Run("Test GetMockPhone", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", + "number": "+1612842323", + "otp": "123456", "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "web", - "applicationId": "com.company.appname" + "$updatedAt": "2020-10-15T06:38:00.000+00:00" } ` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "PUT" { - t.Errorf("Expected method PUT, got %s", r.Method) + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) } w.Header().Set("Content-Type", "application/json") @@ -437,27 +690,25 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.UpdateAndroidPlatform("", "", "") + _, err := srv.GetMockPhone("+12065550100") if err != nil { - t.Errorf("Method UpdateAndroidPlatform failed: %v", err) + t.Errorf("Method GetMockPhone failed: %v", err) } }) - t.Run("Test CreateApplePlatform", func(t *testing.T) { + t.Run("Test UpdateMockPhone", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", + "number": "+1612842323", + "otp": "123456", "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "web", - "bundleIdentifier": "com.company.appname" + "$updatedAt": "2020-10-15T06:38:00.000+00:00" } ` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - t.Errorf("Expected method POST, got %s", r.Method) + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) } w.Header().Set("Content-Type", "application/json") @@ -468,27 +719,22 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.CreateApplePlatform("", "", "") + _, err := srv.UpdateMockPhone("+12065550100", "") if err != nil { - t.Errorf("Method CreateApplePlatform failed: %v", err) + t.Errorf("Method UpdateMockPhone failed: %v", err) } }) - t.Run("Test UpdateApplePlatform", func(t *testing.T) { + t.Run("Test DeleteMockPhone", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "web", - "bundleIdentifier": "com.company.appname" + "message": "success" } ` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "PUT" { - t.Errorf("Expected method PUT, got %s", r.Method) + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) } w.Header().Set("Content-Type", "application/json") @@ -499,27 +745,23 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.UpdateApplePlatform("", "", "") + _, err := srv.DeleteMockPhone("+12065550100") if err != nil { - t.Errorf("Method UpdateApplePlatform failed: %v", err) + t.Errorf("Method DeleteMockPhone failed: %v", err) } }) - t.Run("Test CreateLinuxPlatform", func(t *testing.T) { + t.Run("Test ListOAuth2Providers", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "web", - "packageName": "com.company.appname" + "total": 5, + "providers": [] } ` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - t.Errorf("Expected method POST, got %s", r.Method) + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) } w.Header().Set("Content-Type", "application/json") @@ -530,27 +772,26 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.CreateLinuxPlatform("", "", "") + _, err := srv.ListOAuth2Providers() if err != nil { - t.Errorf("Method CreateLinuxPlatform failed: %v", err) + t.Errorf("Method ListOAuth2Providers failed: %v", err) } }) - t.Run("Test UpdateLinuxPlatform", func(t *testing.T) { + t.Run("Test GetOAuth2Provider", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "web", - "packageName": "com.company.appname" + "$id": "microsoft", + "enabled": true, + "applicationId": "00001111-aaaa-2222-bbbb-3333cccc4444", + "applicationSecret": "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u", + "tenant": "common" } ` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "PUT" { - t.Errorf("Expected method PUT, got %s", r.Method) + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) } w.Header().Set("Content-Type", "application/json") @@ -561,27 +802,28 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.UpdateLinuxPlatform("", "", "") + response, err := srv.GetOAuth2Provider("amazon") if err != nil { - t.Errorf("Method UpdateLinuxPlatform failed: %v", err) + t.Errorf("Method GetOAuth2Provider failed: %v", err) + } + if _, ok := response.(*models.OAuth2Microsoft); !ok { + t.Errorf("Expected response type *models.OAuth2Microsoft, got %T", response) } }) - t.Run("Test CreateWebPlatform", func(t *testing.T) { + t.Run("Test UpdateOAuth2Amazon", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "web", - "hostname": "app.example.com" + "$id": "github", + "enabled": true, + "clientId": "amzn1.application-oa2-client.87400c00000000000000000000063d5b2", + "clientSecret": "79ffe4000000000000000000000000000000000000000000000000000002de55" } ` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - t.Errorf("Expected method POST, got %s", r.Method) + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) } w.Header().Set("Content-Type", "application/json") @@ -592,27 +834,27 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.CreateWebPlatform("", "", "app.example.com") + _, err := srv.UpdateOAuth2Amazon() if err != nil { - t.Errorf("Method CreateWebPlatform failed: %v", err) + t.Errorf("Method UpdateOAuth2Amazon failed: %v", err) } }) - t.Run("Test UpdateWebPlatform", func(t *testing.T) { + t.Run("Test UpdateOAuth2Apple", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "web", - "hostname": "app.example.com" + "$id": "apple", + "enabled": true, + "serviceId": "ip.appwrite.app.web", + "keyId": "P4000000N8", + "teamId": "D4000000R6", + "p8File": "-----BEGIN PRIVATE KEY-----MIGTAg...jy2Xbna-----END PRIVATE KEY-----" } ` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "PUT" { - t.Errorf("Expected method PUT, got %s", r.Method) + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) } w.Header().Set("Content-Type", "application/json") @@ -623,27 +865,26 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.UpdateWebPlatform("", "", "app.example.com") + _, err := srv.UpdateOAuth2Apple() if err != nil { - t.Errorf("Method UpdateWebPlatform failed: %v", err) + t.Errorf("Method UpdateOAuth2Apple failed: %v", err) } }) - t.Run("Test CreateWindowsPlatform", func(t *testing.T) { + t.Run("Test UpdateOAuth2Auth0", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "web", - "packageIdentifierName": "com.company.appname" + "$id": "github", + "enabled": true, + "clientId": "OaOkIA000000000000000000005KLSYq", + "clientSecret": "zXz0000-00000000000000000000000000000-00000000000000000000PJafnF", + "endpoint": "example.us.auth0.com" } ` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - t.Errorf("Expected method POST, got %s", r.Method) + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) } w.Header().Set("Content-Type", "application/json") @@ -654,27 +895,3183 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.CreateWindowsPlatform("", "", "") + _, err := srv.UpdateOAuth2Auth0() if err != nil { - t.Errorf("Method CreateWindowsPlatform failed: %v", err) + t.Errorf("Method UpdateOAuth2Auth0 failed: %v", err) } }) - t.Run("Test UpdateWindowsPlatform", func(t *testing.T) { + t.Run("Test UpdateOAuth2Authentik", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "web", - "packageIdentifierName": "com.company.appname" + "$id": "github", + "enabled": true, + "clientId": "dTKOPa0000000000000000000000000000e7G8hv", + "clientSecret": "ntQadq000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000Hp5WK", + "endpoint": "example.authentik.com" } ` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "PUT" { - t.Errorf("Expected method PUT, got %s", r.Method) + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Authentik() + if err != nil { + t.Errorf("Method UpdateOAuth2Authentik failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Autodesk", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "5zw90v00000000000000000000kVYXN7", + "clientSecret": "7I000000000000MW" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Autodesk() + if err != nil { + t.Errorf("Method UpdateOAuth2Autodesk failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Bitbucket", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "key": "Knt70000000000ByRc", + "secret": "NMfLZJ00000000000000000000TLQdDx" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Bitbucket() + if err != nil { + t.Errorf("Method UpdateOAuth2Bitbucket failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Bitly", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "d95151000000000000000000000000000067af9b", + "clientSecret": "a13e250000000000000000000000000000d73095" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Bitly() + if err != nil { + t.Errorf("Method UpdateOAuth2Bitly failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Box", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "deglcs00000000000000000000x2og6y", + "clientSecret": "OKM1f100000000000000000000eshEif" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Box() + if err != nil { + t.Errorf("Method UpdateOAuth2Box failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Dailymotion", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "apiKey": "07a9000000000000067f", + "apiSecret": "a399a90000000000000000000000000000d90639" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Dailymotion() + if err != nil { + t.Errorf("Method UpdateOAuth2Dailymotion failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Discord", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "950722000000343754", + "clientSecret": "YmPXnM000000000000000000002zFg5D" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Discord() + if err != nil { + t.Errorf("Method UpdateOAuth2Discord failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Disqus", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "publicKey": "cgegH70000000000000000000000000000000000000000000000000000Hr1nYX", + "secretKey": "W7Bykj00000000000000000000000000000000000000000000000000003o43w9" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Disqus() + if err != nil { + t.Errorf("Method UpdateOAuth2Disqus failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Dropbox", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "appKey": "jl000000000009t", + "appSecret": "g200000000000vw" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Dropbox() + if err != nil { + t.Errorf("Method UpdateOAuth2Dropbox failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Etsy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "keyString": "nsgzxh0000000000008j85a2", + "sharedSecret": "tp000000ru" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Etsy() + if err != nil { + t.Errorf("Method UpdateOAuth2Etsy failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Facebook", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "appId": "260600000007694", + "appSecret": "2d0b2800000000000000000000d38af4" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Facebook() + if err != nil { + t.Errorf("Method UpdateOAuth2Facebook failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Figma", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "byay5H0000000000VtiI40", + "clientSecret": "yEpOYn0000000000000000004iIsU5" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Figma() + if err != nil { + t.Errorf("Method UpdateOAuth2Figma failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2FusionAuth", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "b2222c00-0000-0000-0000-000000862097", + "clientSecret": "Jx4s0C0000000000000000000000000000000wGqLsc", + "endpoint": "example.fusionauth.io" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2FusionAuth() + if err != nil { + t.Errorf("Method UpdateOAuth2FusionAuth failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2GitHub", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "e4d87900000000540733", + "clientSecret": "5e07c00000000000000000000000000000198bcc" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2GitHub() + if err != nil { + t.Errorf("Method UpdateOAuth2GitHub failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Gitlab", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "applicationId": "d41ffe0000000000000000000000000000000000000000000000000000d5e252", + "secret": "gloas-838cfa0000000000000000000000000000000000000000000000000000ecbb38", + "endpoint": "https://gitlab.com" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Gitlab() + if err != nil { + t.Errorf("Method UpdateOAuth2Gitlab failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Google", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "your-google-client-id.apps.googleusercontent.com", + "clientSecret": "your-google-client-secret" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Google() + if err != nil { + t.Errorf("Method UpdateOAuth2Google failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Keycloak", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "appwrite-o0000000st-app", + "clientSecret": "jdjrJd00000000000000000000HUsaZO", + "endpoint": "keycloak.example.com", + "realmName": "appwrite-realm" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Keycloak() + if err != nil { + t.Errorf("Method UpdateOAuth2Keycloak failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Kick", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "01KQ7C00000000000001MFHS32", + "clientSecret": "34ac5600000000000000000000000000000000000000000000000000e830c8b" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Kick() + if err != nil { + t.Errorf("Method UpdateOAuth2Kick failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Linkedin", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "770000000000dv", + "primaryClientSecret": "your-linkedin-client-secret" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Linkedin() + if err != nil { + t.Errorf("Method UpdateOAuth2Linkedin failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Microsoft", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "applicationId": "00001111-aaaa-2222-bbbb-3333cccc4444", + "applicationSecret": "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u", + "tenant": "common" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Microsoft() + if err != nil { + t.Errorf("Method UpdateOAuth2Microsoft failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Notion", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "oauthClientId": "341d8700-0000-0000-0000-000000446ee3", + "oauthClientSecret": "secret_dLUr4b000000000000000000000000000000lFHAa9" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Notion() + if err != nil { + t.Errorf("Method UpdateOAuth2Notion failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Oidc", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "qibI2x0000000000000000000000000006L2YFoG", + "clientSecret": "Ah68ed000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003qpcHV", + "wellKnownURL": "https://myoauth.com/.well-known/openid-configuration", + "authorizationURL": "https://myoauth.com/oauth2/authorize", + "tokenURL": "https://myoauth.com/oauth2/token", + "userInfoURL": "https://myoauth.com/oauth2/userinfo" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Oidc() + if err != nil { + t.Errorf("Method UpdateOAuth2Oidc failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Okta", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "0oa00000000000000698", + "clientSecret": "Kiq0000000000000000000000000000000000000-00000000000H2L5-3SJ-vRV", + "domain": "trial-6400025.okta.com", + "authorizationServerId": "aus000000000000000h7z" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Okta() + if err != nil { + t.Errorf("Method UpdateOAuth2Okta failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Paypal", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "AdhIEG7-000000000000-0000000000000000000000000000000-0000000000000000000000-2pyB", + "secretKey": "EH8KCXtew--000000000000000000000000000000000000000_C-1_5UP_000000000000000CB7KDp" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Paypal() + if err != nil { + t.Errorf("Method UpdateOAuth2Paypal failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2PaypalSandbox", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "AdhIEG7-000000000000-0000000000000000000000000000000-0000000000000000000000-2pyB", + "secretKey": "EH8KCXtew--000000000000000000000000000000000000000_C-1_5UP_000000000000000CB7KDp" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2PaypalSandbox() + if err != nil { + t.Errorf("Method UpdateOAuth2PaypalSandbox failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Podio", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "appwrite-oauth-test-app", + "clientSecret": "Rn247T0000000000000000000000000000000000000000000000000000W2zWTN" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Podio() + if err != nil { + t.Errorf("Method UpdateOAuth2Podio failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Salesforce", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "customerKey": "3MVG9I0000000000000000000000000000000000000000000000000000000000000000000000000C5Aejq", + "customerSecret": "3w000000000000e2" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Salesforce() + if err != nil { + t.Errorf("Method UpdateOAuth2Salesforce failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Slack", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "23000000089.15000000000023", + "clientSecret": "81656000000000000000000000f3d2fd" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Slack() + if err != nil { + t.Errorf("Method UpdateOAuth2Slack failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Spotify", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "6ec271000000000000000000009beace", + "clientSecret": "db068a000000000000000000008b5b9f" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Spotify() + if err != nil { + t.Errorf("Method UpdateOAuth2Spotify failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Stripe", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "ca_UKibXX0000000000000000000006byvR", + "apiSecretKey": "sk_51SfOd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000QGWYfp" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Stripe() + if err != nil { + t.Errorf("Method UpdateOAuth2Stripe failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Tradeshift", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "oauth2ClientId": "appwrite-test-org.appwrite-test-app", + "oauth2ClientSecret": "7cb52700-0000-0000-0000-000000ca5b83" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Tradeshift() + if err != nil { + t.Errorf("Method UpdateOAuth2Tradeshift failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2TradeshiftSandbox", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "oauth2ClientId": "appwrite-test-org.appwrite-test-app", + "oauth2ClientSecret": "7cb52700-0000-0000-0000-000000ca5b83" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2TradeshiftSandbox() + if err != nil { + t.Errorf("Method UpdateOAuth2TradeshiftSandbox failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Twitch", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "vvi0in000000000000000000ikmt9p", + "clientSecret": "pmapue000000000000000000zylw3v" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Twitch() + if err != nil { + t.Errorf("Method UpdateOAuth2Twitch failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2WordPress", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "130005", + "clientSecret": "PlBfJS0000000000000000000000000000000000000000000000000000EdUZJk" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2WordPress() + if err != nil { + t.Errorf("Method UpdateOAuth2WordPress failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2X", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "customerKey": "slzZV0000000000000NFLaWT", + "secretKey": "tkEPkp00000000000000000000000000000000000000FTxbI9" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2X() + if err != nil { + t.Errorf("Method UpdateOAuth2X failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Yahoo", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "dj0yJm000000000000000000000000000000000000000000000000000000000000000000000000000000000000Z4PWRm", + "clientSecret": "cf978f0000000000000000000000000000c5e2e9" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Yahoo() + if err != nil { + t.Errorf("Method UpdateOAuth2Yahoo failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Yandex", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "6a8a6a0000000000000000000091483c", + "clientSecret": "bbf98500000000000000000000c75a63" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Yandex() + if err != nil { + t.Errorf("Method UpdateOAuth2Yandex failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Zoho", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "1000.83C178000000000000000000RPNX0B", + "clientSecret": "fb5cac000000000000000000000000000000a68f6e" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Zoho() + if err != nil { + t.Errorf("Method UpdateOAuth2Zoho failed: %v", err) + } + }) + + t.Run("Test UpdateOAuth2Zoom", func(t *testing.T) { + mockResponse := ` +{ + "$id": "github", + "enabled": true, + "clientId": "QMAC00000000000000w0AQ", + "clientSecret": "GAWsG4000000000000000000007U01ON" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateOAuth2Zoom() + if err != nil { + t.Errorf("Method UpdateOAuth2Zoom failed: %v", err) + } + }) + + t.Run("Test ListPlatforms", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "platforms": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListPlatforms() + if err != nil { + t.Errorf("Method ListPlatforms failed: %v", err) + } + }) + + t.Run("Test CreateAndroidPlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "web", + "applicationId": "com.company.appname" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateAndroidPlatform("", "", "") + if err != nil { + t.Errorf("Method CreateAndroidPlatform failed: %v", err) + } + }) + + t.Run("Test UpdateAndroidPlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "web", + "applicationId": "com.company.appname" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateAndroidPlatform("", "", "") + if err != nil { + t.Errorf("Method UpdateAndroidPlatform failed: %v", err) + } + }) + + t.Run("Test CreateApplePlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "web", + "bundleIdentifier": "com.company.appname" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateApplePlatform("", "", "") + if err != nil { + t.Errorf("Method CreateApplePlatform failed: %v", err) + } + }) + + t.Run("Test UpdateApplePlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "web", + "bundleIdentifier": "com.company.appname" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateApplePlatform("", "", "") + if err != nil { + t.Errorf("Method UpdateApplePlatform failed: %v", err) + } + }) + + t.Run("Test CreateLinuxPlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "web", + "packageName": "com.company.appname" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateLinuxPlatform("", "", "") + if err != nil { + t.Errorf("Method CreateLinuxPlatform failed: %v", err) + } + }) + + t.Run("Test UpdateLinuxPlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "web", + "packageName": "com.company.appname" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateLinuxPlatform("", "", "") + if err != nil { + t.Errorf("Method UpdateLinuxPlatform failed: %v", err) + } + }) + + t.Run("Test CreateWebPlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "web", + "hostname": "app.example.com" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateWebPlatform("", "", "app.example.com") + if err != nil { + t.Errorf("Method CreateWebPlatform failed: %v", err) + } + }) + + t.Run("Test UpdateWebPlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "web", + "hostname": "app.example.com" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateWebPlatform("", "", "app.example.com") + if err != nil { + t.Errorf("Method UpdateWebPlatform failed: %v", err) + } + }) + + t.Run("Test CreateWindowsPlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "web", + "packageIdentifierName": "com.company.appname" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateWindowsPlatform("", "", "") + if err != nil { + t.Errorf("Method CreateWindowsPlatform failed: %v", err) + } + }) + + t.Run("Test UpdateWindowsPlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "web", + "packageIdentifierName": "com.company.appname" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateWindowsPlatform("", "", "") + if err != nil { + t.Errorf("Method UpdateWindowsPlatform failed: %v", err) + } + }) + + t.Run("Test GetPlatform", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Web App", + "type": "linux", + "packageName": "com.company.appname" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + response, err := srv.GetPlatform("") + if err != nil { + t.Errorf("Method GetPlatform failed: %v", err) + } + if _, ok := response.(*models.PlatformLinux); !ok { + t.Errorf("Expected response type *models.PlatformLinux, got %T", response) + } + }) + + t.Run("Test DeletePlatform", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeletePlatform("") + if err != nil { + t.Errorf("Method DeletePlatform failed: %v", err) + } + }) + + t.Run("Test ListPolicies", func(t *testing.T) { + mockResponse := ` +{ + "total": 9, + "policies": [] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListPolicies() + if err != nil { + t.Errorf("Method ListPolicies failed: %v", err) + } + }) + + t.Run("Test UpdateMembershipPrivacyPolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateMembershipPrivacyPolicy() + if err != nil { + t.Errorf("Method UpdateMembershipPrivacyPolicy failed: %v", err) + } + }) + + t.Run("Test UpdatePasswordDictionaryPolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePasswordDictionaryPolicy(true) + if err != nil { + t.Errorf("Method UpdatePasswordDictionaryPolicy failed: %v", err) + } + }) + + t.Run("Test UpdatePasswordHistoryPolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePasswordHistoryPolicy(1) + if err != nil { + t.Errorf("Method UpdatePasswordHistoryPolicy failed: %v", err) + } + }) + + t.Run("Test UpdatePasswordPersonalDataPolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePasswordPersonalDataPolicy(true) + if err != nil { + t.Errorf("Method UpdatePasswordPersonalDataPolicy failed: %v", err) + } + }) + + t.Run("Test UpdateSessionAlertPolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSessionAlertPolicy(true) + if err != nil { + t.Errorf("Method UpdateSessionAlertPolicy failed: %v", err) + } + }) + + t.Run("Test UpdateSessionDurationPolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSessionDurationPolicy(1) + if err != nil { + t.Errorf("Method UpdateSessionDurationPolicy failed: %v", err) + } + }) + + t.Run("Test UpdateSessionInvalidationPolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSessionInvalidationPolicy(true) + if err != nil { + t.Errorf("Method UpdateSessionInvalidationPolicy failed: %v", err) + } + }) + + t.Run("Test UpdateSessionLimitPolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateSessionLimitPolicy(1) + if err != nil { + t.Errorf("Method UpdateSessionLimitPolicy failed: %v", err) + } + }) + + t.Run("Test UpdateUserLimitPolicy", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) } w.Header().Set("Content-Type", "application/json") @@ -685,21 +4082,21 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.UpdateWindowsPlatform("", "", "") + _, err := srv.UpdateUserLimitPolicy(1) if err != nil { - t.Errorf("Method UpdateWindowsPlatform failed: %v", err) + t.Errorf("Method UpdateUserLimitPolicy failed: %v", err) } }) - t.Run("Test GetPlatform", func(t *testing.T) { + t.Run("Test GetPolicy", func(t *testing.T) { mockResponse := ` { - "$id": "5e5ea5c16897e", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "name": "My Web App", - "type": "linux", - "packageName": "com.company.appname" + "$id": "membership-privacy", + "userId": true, + "userEmail": true, + "userPhone": true, + "userName": true, + "userMFA": true } ` @@ -716,25 +4113,179 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - response, err := srv.GetPlatform("") + response, err := srv.GetPolicy("password-dictionary") if err != nil { - t.Errorf("Method GetPlatform failed: %v", err) + t.Errorf("Method GetPolicy failed: %v", err) } - if _, ok := response.(*models.PlatformLinux); !ok { - t.Errorf("Expected response type *models.PlatformLinux, got %T", response) + if _, ok := response.(*models.PolicyMembershipPrivacy); !ok { + t.Errorf("Expected response type *models.PolicyMembershipPrivacy, got %T", response) } }) - t.Run("Test DeletePlatform", func(t *testing.T) { + t.Run("Test UpdateProtocol", func(t *testing.T) { mockResponse := ` { - "message": "success" + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "New Project", + "description": "This is a new project.", + "teamId": "1592981250", + "logo": "5f5c451b403cb", + "url": "5f5c451b403cb", + "legalName": "Company LTD.", + "legalCountry": "US", + "legalState": "New York", + "legalCity": "New York City.", + "legalAddress": "620 Eighth Avenue, New York, NY 10018", + "legalTaxId": "131102020", + "authDuration": 60, + "authLimit": 100, + "authSessionsLimit": 10, + "authPasswordHistory": 5, + "authPasswordDictionary": true, + "authPersonalDataCheck": true, + "authDisposableEmails": true, + "authCanonicalEmails": true, + "authFreeEmails": true, + "authMockNumbers": [ + { + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" + } + ], + "authSessionAlerts": true, + "authMembershipsUserName": true, + "authMembershipsUserEmail": true, + "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, + "authInvalidateSessions": true, + "oAuthProviders": [ + { + "key": "github", + "name": "GitHub", + "appId": "259125845563242502", + "secret": "string", + "enabled": true + } + ], + "platforms": [], + "webhooks": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My Webhook", + "url": "https://example.com/webhook", + "events": [], + "tls": true, + "authUsername": "username", + "authPassword": "password", + "secret": "ad3d581ca230e2b7059c545e5a", + "enabled": true, + "logs": "Failed to connect to remote server.", + "attempts": 10 + } + ], + "keys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "My API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "scopes": [], + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "devKeys": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "name": "Dev API Key", + "expire": "2020-10-15T06:38:00.000+00:00", + "secret": "919c2d18fb5d4...a2ae413da83346ad2", + "accessedAt": "2020-10-15T06:38:00.000+00:00", + "sdks": [] + } + ], + "smtpEnabled": true, + "smtpSenderName": "John Appwrite", + "smtpSenderEmail": "john@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", + "smtpHost": "mail.appwrite.io", + "smtpPort": 25, + "smtpUsername": "emailuser", + "smtpPassword": "string", + "smtpSecure": "tls", + "pingCount": 1, + "pingedAt": "2020-10-15T06:38:00.000+00:00", + "labels": [], + "status": "active", + "authEmailPassword": true, + "authUsersAuthMagicURL": true, + "authEmailOtp": true, + "authAnonymous": true, + "authInvites": true, + "authJWT": true, + "authPhone": true, + "serviceStatusForAccount": true, + "serviceStatusForAvatars": true, + "serviceStatusForDatabases": true, + "serviceStatusForTablesdb": true, + "serviceStatusForLocale": true, + "serviceStatusForHealth": true, + "serviceStatusForProject": true, + "serviceStatusForStorage": true, + "serviceStatusForTeams": true, + "serviceStatusForUsers": true, + "serviceStatusForVcs": true, + "serviceStatusForSites": true, + "serviceStatusForFunctions": true, + "serviceStatusForProxy": true, + "serviceStatusForGraphql": true, + "serviceStatusForMigrations": true, + "serviceStatusForMessaging": true, + "protocolStatusForRest": true, + "protocolStatusForGraphql": true, + "protocolStatusForWebsocket": true, + "region": "fra", + "billingLimits": { + "bandwidth": 5, + "storage": 150, + "users": 200000, + "executions": 750000, + "GBHours": 100, + "imageTransformations": 100, + "authPhone": 10, + "budgetLimit": 100 + }, + "blocks": [ + { + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "resourceType": "project", + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" + } + ], + "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" } ` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "DELETE" { - t.Errorf("Expected method DELETE, got %s", r.Method) + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) } w.Header().Set("Content-Type", "application/json") @@ -745,13 +4296,13 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.DeletePlatform("") + _, err := srv.UpdateProtocol("rest", true) if err != nil { - t.Errorf("Method DeletePlatform failed: %v", err) + t.Errorf("Method UpdateProtocol failed: %v", err) } }) - t.Run("Test UpdateProtocolStatus", func(t *testing.T) { + t.Run("Test UpdateService", func(t *testing.T) { mockResponse := ` { "$id": "5e5ea5c16897e", @@ -779,21 +4330,25 @@ func TestProject(t *testing.T) { "authFreeEmails": true, "authMockNumbers": [ { - "phone": "+1612842323", - "otp": "123456" + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" } ], "authSessionAlerts": true, "authMembershipsUserName": true, "authMembershipsUserEmail": true, "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, "authInvalidateSessions": true, "oAuthProviders": [ { "key": "github", "name": "GitHub", "appId": "259125845563242502", - "secret": "Bpw_g9c2TGXxfgLshDbSaL8tsCcqgczQ", + "secret": "string", "enabled": true } ], @@ -843,11 +4398,12 @@ func TestProject(t *testing.T) { "smtpEnabled": true, "smtpSenderName": "John Appwrite", "smtpSenderEmail": "john@appwrite.io", - "smtpReplyTo": "support@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", "smtpHost": "mail.appwrite.io", "smtpPort": 25, "smtpUsername": "emailuser", - "smtpPassword": "securepassword", + "smtpPassword": "string", "smtpSecure": "tls", "pingCount": 1, "pingedAt": "2020-10-15T06:38:00.000+00:00", @@ -895,7 +4451,12 @@ func TestProject(t *testing.T) { { "$createdAt": "2020-10-15T06:38:00.000+00:00", "resourceType": "project", - "resourceId": "5e5ea5c16897e" + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" } ], "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" @@ -915,13 +4476,13 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.UpdateProtocolStatus("rest", true) + _, err := srv.UpdateService("account", true) if err != nil { - t.Errorf("Method UpdateProtocolStatus failed: %v", err) + t.Errorf("Method UpdateService failed: %v", err) } }) - t.Run("Test UpdateServiceStatus", func(t *testing.T) { + t.Run("Test UpdateSMTP", func(t *testing.T) { mockResponse := ` { "$id": "5e5ea5c16897e", @@ -949,21 +4510,25 @@ func TestProject(t *testing.T) { "authFreeEmails": true, "authMockNumbers": [ { - "phone": "+1612842323", - "otp": "123456" + "number": "+1612842323", + "otp": "123456", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" } ], "authSessionAlerts": true, "authMembershipsUserName": true, "authMembershipsUserEmail": true, "authMembershipsMfa": true, + "authMembershipsUserId": true, + "authMembershipsUserPhone": true, "authInvalidateSessions": true, "oAuthProviders": [ { "key": "github", "name": "GitHub", "appId": "259125845563242502", - "secret": "Bpw_g9c2TGXxfgLshDbSaL8tsCcqgczQ", + "secret": "string", "enabled": true } ], @@ -1013,11 +4578,12 @@ func TestProject(t *testing.T) { "smtpEnabled": true, "smtpSenderName": "John Appwrite", "smtpSenderEmail": "john@appwrite.io", - "smtpReplyTo": "support@appwrite.io", + "smtpReplyToName": "Support Team", + "smtpReplyToEmail": "support@appwrite.io", "smtpHost": "mail.appwrite.io", "smtpPort": 25, "smtpUsername": "emailuser", - "smtpPassword": "securepassword", + "smtpPassword": "string", "smtpSecure": "tls", "pingCount": 1, "pingedAt": "2020-10-15T06:38:00.000+00:00", @@ -1065,7 +4631,12 @@ func TestProject(t *testing.T) { { "$createdAt": "2020-10-15T06:38:00.000+00:00", "resourceType": "project", - "resourceId": "5e5ea5c16897e" + "resourceId": "5e5ea5c16897e", + "projectName": "My Project", + "region": "fra", + "organizationName": "Acme Inc.", + "organizationId": "5e5ea5c16897e", + "billingPlan": "pro" } ], "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00" @@ -1085,9 +4656,139 @@ func TestProject(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.UpdateServiceStatus("account", true) + _, err := srv.UpdateSMTP() + if err != nil { + t.Errorf("Method UpdateSMTP failed: %v", err) + } + }) + + t.Run("Test CreateSMTPTest", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSMTPTest([]string{}) + if err != nil { + t.Errorf("Method CreateSMTPTest failed: %v", err) + } + }) + + t.Run("Test ListEmailTemplates", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "templates": [ + { + "templateId": "verification", + "locale": "en_us", + "message": "Click on the link to verify your account.", + "senderName": "My User", + "senderEmail": "mail@appwrite.io", + "replyToEmail": "emails@appwrite.io", + "replyToName": "Support Team", + "subject": "Please verify your email address" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListEmailTemplates() + if err != nil { + t.Errorf("Method ListEmailTemplates failed: %v", err) + } + }) + + t.Run("Test UpdateEmailTemplate", func(t *testing.T) { + mockResponse := ` +{ + "templateId": "verification", + "locale": "en_us", + "message": "Click on the link to verify your account.", + "senderName": "My User", + "senderEmail": "mail@appwrite.io", + "replyToEmail": "emails@appwrite.io", + "replyToName": "Support Team", + "subject": "Please verify your email address" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateEmailTemplate("verification") + if err != nil { + t.Errorf("Method UpdateEmailTemplate failed: %v", err) + } + }) + + t.Run("Test GetEmailTemplate", func(t *testing.T) { + mockResponse := ` +{ + "templateId": "verification", + "locale": "en_us", + "message": "Click on the link to verify your account.", + "senderName": "My User", + "senderEmail": "mail@appwrite.io", + "replyToEmail": "emails@appwrite.io", + "replyToName": "Support Team", + "subject": "Please verify your email address" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetEmailTemplate("verification") if err != nil { - t.Errorf("Method UpdateServiceStatus failed: %v", err) + t.Errorf("Method GetEmailTemplate failed: %v", err) } }) diff --git a/proxy/proxy.go b/proxy/proxy.go new file mode 100644 index 00000000..e785e62e --- /dev/null +++ b/proxy/proxy.go @@ -0,0 +1,401 @@ +package proxy + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/models" + "strings" +) + +// Proxy service +type Proxy struct { + client client.Client +} + +func New(clt client.Client) *Proxy { + return &Proxy{ + client: clt, + } +} + +type ListRulesOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListRulesOptions) New() *ListRulesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + } + return &options +} +type ListRulesOption func(*ListRulesOptions) +func (srv *Proxy) WithListRulesQueries(v []string) ListRulesOption { + return func(o *ListRulesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *Proxy) WithListRulesTotal(v bool) ListRulesOption { + return func(o *ListRulesOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + +// ListRules get a list of all the proxy rules. You can use the query params +// to filter your results. +func (srv *Proxy) ListRules(optionalSetters ...ListRulesOption)(*models.ProxyRuleList, error) { + path := "/proxy/rules" + options := ListRulesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.ProxyRuleList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.ProxyRuleList + parsed, ok := resp.Result.(models.ProxyRuleList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateAPIRule create a new proxy rule for serving Appwrite's API on custom +// domain. +// +// Rule ID is automatically generated as MD5 hash of a rule domain for +// performance purposes. +func (srv *Proxy) CreateAPIRule(Domain string)(*models.ProxyRule, error) { + path := "/proxy/rules/api" + params := map[string]interface{}{} + params["domain"] = Domain + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.ProxyRule{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.ProxyRule + parsed, ok := resp.Result.(models.ProxyRule) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateFunctionRuleOptions struct { + Branch string + enabledSetters map[string]bool +} +func (options CreateFunctionRuleOptions) New() *CreateFunctionRuleOptions { + options.enabledSetters = map[string]bool{ + "Branch": false, + } + return &options +} +type CreateFunctionRuleOption func(*CreateFunctionRuleOptions) +func (srv *Proxy) WithCreateFunctionRuleBranch(v string) CreateFunctionRuleOption { + return func(o *CreateFunctionRuleOptions) { + o.Branch = v + o.enabledSetters["Branch"] = true + } +} + +// CreateFunctionRule create a new proxy rule for executing Appwrite Function +// on custom domain. +// +// Rule ID is automatically generated as MD5 hash of a rule domain for +// performance purposes. +func (srv *Proxy) CreateFunctionRule(Domain string, FunctionId string, optionalSetters ...CreateFunctionRuleOption)(*models.ProxyRule, error) { + path := "/proxy/rules/function" + options := CreateFunctionRuleOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["domain"] = Domain + params["functionId"] = FunctionId + if options.enabledSetters["Branch"] { + params["branch"] = options.Branch + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.ProxyRule{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.ProxyRule + parsed, ok := resp.Result.(models.ProxyRule) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// CreateRedirectRule create a new proxy rule for to redirect from custom +// domain to another domain. +// +// Rule ID is automatically generated as MD5 hash of a rule domain for +// performance purposes. +func (srv *Proxy) CreateRedirectRule(Domain string, Url string, StatusCode string, ResourceId string, ResourceType string)(*models.ProxyRule, error) { + path := "/proxy/rules/redirect" + params := map[string]interface{}{} + params["domain"] = Domain + params["url"] = Url + params["statusCode"] = StatusCode + params["resourceId"] = ResourceId + params["resourceType"] = ResourceType + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.ProxyRule{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.ProxyRule + parsed, ok := resp.Result.(models.ProxyRule) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type CreateSiteRuleOptions struct { + Branch string + enabledSetters map[string]bool +} +func (options CreateSiteRuleOptions) New() *CreateSiteRuleOptions { + options.enabledSetters = map[string]bool{ + "Branch": false, + } + return &options +} +type CreateSiteRuleOption func(*CreateSiteRuleOptions) +func (srv *Proxy) WithCreateSiteRuleBranch(v string) CreateSiteRuleOption { + return func(o *CreateSiteRuleOptions) { + o.Branch = v + o.enabledSetters["Branch"] = true + } +} + +// CreateSiteRule create a new proxy rule for serving Appwrite Site on custom +// domain. +// +// Rule ID is automatically generated as MD5 hash of a rule domain for +// performance purposes. +func (srv *Proxy) CreateSiteRule(Domain string, SiteId string, optionalSetters ...CreateSiteRuleOption)(*models.ProxyRule, error) { + path := "/proxy/rules/site" + options := CreateSiteRuleOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["domain"] = Domain + params["siteId"] = SiteId + if options.enabledSetters["Branch"] { + params["branch"] = options.Branch + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.ProxyRule{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.ProxyRule + parsed, ok := resp.Result.(models.ProxyRule) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetRule get a proxy rule by its unique ID. +func (srv *Proxy) GetRule(RuleId string)(*models.ProxyRule, error) { + r := strings.NewReplacer("{ruleId}", RuleId) + path := r.Replace("/proxy/rules/{ruleId}") + params := map[string]interface{}{} + params["ruleId"] = RuleId + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.ProxyRule{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.ProxyRule + parsed, ok := resp.Result.(models.ProxyRule) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// DeleteRule delete a proxy rule by its unique ID. +func (srv *Proxy) DeleteRule(RuleId string)(*interface{}, error) { + r := strings.NewReplacer("{ruleId}", RuleId) + path := r.Replace("/proxy/rules/{ruleId}") + params := map[string]interface{}{} + params["ruleId"] = RuleId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// UpdateRuleStatus if not succeeded yet, retry verification process of a +// proxy rule domain. This endpoint triggers domain verification by checking +// DNS records. If verification is successful, a TLS certificate will be +// automatically provisioned for the domain asynchronously in the background. +func (srv *Proxy) UpdateRuleStatus(RuleId string)(*models.ProxyRule, error) { + r := strings.NewReplacer("{ruleId}", RuleId) + path := r.Replace("/proxy/rules/{ruleId}/status") + params := map[string]interface{}{} + params["ruleId"] = RuleId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.ProxyRule{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.ProxyRule + parsed, ok := resp.Result.(models.ProxyRule) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/proxy/proxy_test.go b/proxy/proxy_test.go new file mode 100644 index 00000000..bcc38160 --- /dev/null +++ b/proxy/proxy_test.go @@ -0,0 +1,322 @@ +package proxy + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v3/client" +) + +func TestProxy(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test ListRules", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "rules": [ + { + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "domain": "appwrite.company.com", + "type": "deployment", + "trigger": "manual", + "redirectUrl": "https://appwrite.io/docs", + "redirectStatusCode": 301, + "deploymentId": "n3u9feiwmf", + "deploymentResourceId": "n3u9feiwmf", + "deploymentVcsProviderBranch": "main", + "status": "verified", + "logs": "Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.", + "renewAt": "datetime" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.ListRules() + if err != nil { + t.Errorf("Method ListRules failed: %v", err) + } + }) + + t.Run("Test CreateAPIRule", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "domain": "appwrite.company.com", + "type": "deployment", + "trigger": "manual", + "redirectUrl": "https://appwrite.io/docs", + "redirectStatusCode": 301, + "deploymentId": "n3u9feiwmf", + "deploymentResourceId": "n3u9feiwmf", + "deploymentVcsProviderBranch": "main", + "status": "verified", + "logs": "Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.", + "renewAt": "datetime" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateAPIRule("") + if err != nil { + t.Errorf("Method CreateAPIRule failed: %v", err) + } + }) + + t.Run("Test CreateFunctionRule", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "domain": "appwrite.company.com", + "type": "deployment", + "trigger": "manual", + "redirectUrl": "https://appwrite.io/docs", + "redirectStatusCode": 301, + "deploymentId": "n3u9feiwmf", + "deploymentResourceId": "n3u9feiwmf", + "deploymentVcsProviderBranch": "main", + "status": "verified", + "logs": "Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.", + "renewAt": "datetime" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateFunctionRule("", "") + if err != nil { + t.Errorf("Method CreateFunctionRule failed: %v", err) + } + }) + + t.Run("Test CreateRedirectRule", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "domain": "appwrite.company.com", + "type": "deployment", + "trigger": "manual", + "redirectUrl": "https://appwrite.io/docs", + "redirectStatusCode": 301, + "deploymentId": "n3u9feiwmf", + "deploymentResourceId": "n3u9feiwmf", + "deploymentVcsProviderBranch": "main", + "status": "verified", + "logs": "Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.", + "renewAt": "datetime" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateRedirectRule("", "https://example.com", "301", "", "site") + if err != nil { + t.Errorf("Method CreateRedirectRule failed: %v", err) + } + }) + + t.Run("Test CreateSiteRule", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "domain": "appwrite.company.com", + "type": "deployment", + "trigger": "manual", + "redirectUrl": "https://appwrite.io/docs", + "redirectStatusCode": 301, + "deploymentId": "n3u9feiwmf", + "deploymentResourceId": "n3u9feiwmf", + "deploymentVcsProviderBranch": "main", + "status": "verified", + "logs": "Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.", + "renewAt": "datetime" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateSiteRule("", "") + if err != nil { + t.Errorf("Method CreateSiteRule failed: %v", err) + } + }) + + t.Run("Test GetRule", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "domain": "appwrite.company.com", + "type": "deployment", + "trigger": "manual", + "redirectUrl": "https://appwrite.io/docs", + "redirectStatusCode": 301, + "deploymentId": "n3u9feiwmf", + "deploymentResourceId": "n3u9feiwmf", + "deploymentVcsProviderBranch": "main", + "status": "verified", + "logs": "Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.", + "renewAt": "datetime" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.GetRule("") + if err != nil { + t.Errorf("Method GetRule failed: %v", err) + } + }) + + t.Run("Test DeleteRule", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.DeleteRule("") + if err != nil { + t.Errorf("Method DeleteRule failed: %v", err) + } + }) + + t.Run("Test UpdateRuleStatus", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "domain": "appwrite.company.com", + "type": "deployment", + "trigger": "manual", + "redirectUrl": "https://appwrite.io/docs", + "redirectStatusCode": 301, + "deploymentId": "n3u9feiwmf", + "deploymentResourceId": "n3u9feiwmf", + "deploymentVcsProviderBranch": "main", + "status": "verified", + "logs": "Verification of DNS records failed with DNS resolver 8.8.8.8. Domain stage.myapp.com does not have DNS record.", + "renewAt": "datetime" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateRuleStatus("") + if err != nil { + t.Errorf("Method UpdateRuleStatus failed: %v", err) + } + }) +} diff --git a/sites/sites.go b/sites/sites.go index a570400b..8390deb4 100644 --- a/sites/sites.go +++ b/sites/sites.go @@ -1443,13 +1443,48 @@ func (srv *Sites) DeleteLog(SiteId string, LogId string)(*interface{}, error) { return &parsed, nil } - +type ListVariablesOptions struct { + Queries []string + Total bool + enabledSetters map[string]bool +} +func (options ListVariablesOptions) New() *ListVariablesOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + } + return &options +} +type ListVariablesOption func(*ListVariablesOptions) +func (srv *Sites) WithListVariablesQueries(v []string) ListVariablesOption { + return func(o *ListVariablesOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *Sites) WithListVariablesTotal(v bool) ListVariablesOption { + return func(o *ListVariablesOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} + // ListVariables get a list of all variables of a specific site. -func (srv *Sites) ListVariables(SiteId string)(*models.VariableList, error) { +func (srv *Sites) ListVariables(SiteId string, optionalSetters ...ListVariablesOption)(*models.VariableList, error) { r := strings.NewReplacer("{siteId}", SiteId) path := r.Replace("/sites/{siteId}/variables") + options := ListVariablesOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } params := map[string]interface{}{} params["siteId"] = SiteId + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } headers := map[string]interface{}{ } @@ -1494,10 +1529,10 @@ func (srv *Sites) WithCreateVariableSecret(v bool) CreateVariableOption { o.enabledSetters["Secret"] = true } } - + // CreateVariable create a new site variable. These variables can be accessed // during build and runtime (server-side rendering) as environment variables. -func (srv *Sites) CreateVariable(SiteId string, Key string, Value string, optionalSetters ...CreateVariableOption)(*models.Variable, error) { +func (srv *Sites) CreateVariable(SiteId string, VariableId string, Key string, Value string, optionalSetters ...CreateVariableOption)(*models.Variable, error) { r := strings.NewReplacer("{siteId}", SiteId) path := r.Replace("/sites/{siteId}/variables") options := CreateVariableOptions{}.New() @@ -1506,6 +1541,7 @@ func (srv *Sites) CreateVariable(SiteId string, Key string, Value string, option } params := map[string]interface{}{} params["siteId"] = SiteId + params["variableId"] = VariableId params["key"] = Key params["value"] = Value if options.enabledSetters["Secret"] { @@ -1575,18 +1611,26 @@ func (srv *Sites) GetVariable(SiteId string, VariableId string)(*models.Variable } type UpdateVariableOptions struct { + Key string Value string Secret bool enabledSetters map[string]bool } func (options UpdateVariableOptions) New() *UpdateVariableOptions { options.enabledSetters = map[string]bool{ + "Key": false, "Value": false, "Secret": false, } return &options } type UpdateVariableOption func(*UpdateVariableOptions) +func (srv *Sites) WithUpdateVariableKey(v string) UpdateVariableOption { + return func(o *UpdateVariableOptions) { + o.Key = v + o.enabledSetters["Key"] = true + } +} func (srv *Sites) WithUpdateVariableValue(v string) UpdateVariableOption { return func(o *UpdateVariableOptions) { o.Value = v @@ -1599,9 +1643,9 @@ func (srv *Sites) WithUpdateVariableSecret(v bool) UpdateVariableOption { o.enabledSetters["Secret"] = true } } - + // UpdateVariable update variable by its unique ID. -func (srv *Sites) UpdateVariable(SiteId string, VariableId string, Key string, optionalSetters ...UpdateVariableOption)(*models.Variable, error) { +func (srv *Sites) UpdateVariable(SiteId string, VariableId string, optionalSetters ...UpdateVariableOption)(*models.Variable, error) { r := strings.NewReplacer("{siteId}", SiteId, "{variableId}", VariableId) path := r.Replace("/sites/{siteId}/variables/{variableId}") options := UpdateVariableOptions{}.New() @@ -1611,7 +1655,9 @@ func (srv *Sites) UpdateVariable(SiteId string, VariableId string, Key string, o params := map[string]interface{}{} params["siteId"] = SiteId params["variableId"] = VariableId - params["key"] = Key + if options.enabledSetters["Key"] { + params["key"] = options.Key + } if options.enabledSetters["Value"] { params["value"] = options.Value } diff --git a/sites/sites_test.go b/sites/sites_test.go index 34bbf474..822a6b59 100644 --- a/sites/sites_test.go +++ b/sites/sites_test.go @@ -1096,7 +1096,7 @@ func TestSites(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.CreateVariable("", "", "") + _, err := srv.CreateVariable("", "", "", "") if err != nil { t.Errorf("Method CreateVariable failed: %v", err) } @@ -1162,7 +1162,7 @@ func TestSites(t *testing.T) { srv := New(newTestClient(ts)) - _, err := srv.UpdateVariable("", "", "") + _, err := srv.UpdateVariable("", "") if err != nil { t.Errorf("Method UpdateVariable failed: %v", err) } diff --git a/tablesdb/tables_db.go b/tablesdb/tables_db.go index c4c9bb3e..d785d07f 100644 --- a/tablesdb/tables_db.go +++ b/tablesdb/tables_db.go @@ -1043,6 +1043,188 @@ func (srv *TablesDB) ListColumns(DatabaseId string, TableId string, optionalSett } return &parsed, nil +} +type CreateBigIntColumnOptions struct { + Min int + Max int + Default int + Array bool + enabledSetters map[string]bool +} +func (options CreateBigIntColumnOptions) New() *CreateBigIntColumnOptions { + options.enabledSetters = map[string]bool{ + "Min": false, + "Max": false, + "Default": false, + "Array": false, + } + return &options +} +type CreateBigIntColumnOption func(*CreateBigIntColumnOptions) +func (srv *TablesDB) WithCreateBigIntColumnMin(v int) CreateBigIntColumnOption { + return func(o *CreateBigIntColumnOptions) { + o.Min = v + o.enabledSetters["Min"] = true + } +} +func (srv *TablesDB) WithCreateBigIntColumnMax(v int) CreateBigIntColumnOption { + return func(o *CreateBigIntColumnOptions) { + o.Max = v + o.enabledSetters["Max"] = true + } +} +func (srv *TablesDB) WithCreateBigIntColumnDefault(v int) CreateBigIntColumnOption { + return func(o *CreateBigIntColumnOptions) { + o.Default = v + o.enabledSetters["Default"] = true + } +} +func (srv *TablesDB) WithCreateBigIntColumnArray(v bool) CreateBigIntColumnOption { + return func(o *CreateBigIntColumnOptions) { + o.Array = v + o.enabledSetters["Array"] = true + } +} + +// CreateBigIntColumn create a bigint column. Optionally, minimum and maximum +// values can be provided. +func (srv *TablesDB) CreateBigIntColumn(DatabaseId string, TableId string, Key string, Required bool, optionalSetters ...CreateBigIntColumnOption)(*models.ColumnBigint, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{tableId}", TableId) + path := r.Replace("/tablesdb/{databaseId}/tables/{tableId}/columns/bigint") + options := CreateBigIntColumnOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["tableId"] = TableId + params["key"] = Key + params["required"] = Required + if options.enabledSetters["Min"] { + params["min"] = options.Min + } + if options.enabledSetters["Max"] { + params["max"] = options.Max + } + if options.enabledSetters["Default"] { + params["default"] = options.Default + } + if options.enabledSetters["Array"] { + params["array"] = options.Array + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("POST", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.ColumnBigint{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.ColumnBigint + parsed, ok := resp.Result.(models.ColumnBigint) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateBigIntColumnOptions struct { + Min int + Max int + NewKey string + enabledSetters map[string]bool +} +func (options UpdateBigIntColumnOptions) New() *UpdateBigIntColumnOptions { + options.enabledSetters = map[string]bool{ + "Min": false, + "Max": false, + "NewKey": false, + } + return &options +} +type UpdateBigIntColumnOption func(*UpdateBigIntColumnOptions) +func (srv *TablesDB) WithUpdateBigIntColumnMin(v int) UpdateBigIntColumnOption { + return func(o *UpdateBigIntColumnOptions) { + o.Min = v + o.enabledSetters["Min"] = true + } +} +func (srv *TablesDB) WithUpdateBigIntColumnMax(v int) UpdateBigIntColumnOption { + return func(o *UpdateBigIntColumnOptions) { + o.Max = v + o.enabledSetters["Max"] = true + } +} +func (srv *TablesDB) WithUpdateBigIntColumnNewKey(v string) UpdateBigIntColumnOption { + return func(o *UpdateBigIntColumnOptions) { + o.NewKey = v + o.enabledSetters["NewKey"] = true + } +} + +// UpdateBigIntColumn update a bigint column. Changing the `default` value +// will not update already existing rows. +func (srv *TablesDB) UpdateBigIntColumn(DatabaseId string, TableId string, Key string, Required bool, Default int, optionalSetters ...UpdateBigIntColumnOption)(*models.ColumnBigint, error) { + r := strings.NewReplacer("{databaseId}", DatabaseId, "{tableId}", TableId, "{key}", Key) + path := r.Replace("/tablesdb/{databaseId}/tables/{tableId}/columns/bigint/{key}") + options := UpdateBigIntColumnOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["databaseId"] = DatabaseId + params["tableId"] = TableId + params["key"] = Key + params["required"] = Required + params["default"] = Default + if options.enabledSetters["Min"] { + params["min"] = options.Min + } + if options.enabledSetters["Max"] { + params["max"] = options.Max + } + if options.enabledSetters["NewKey"] { + params["newKey"] = options.NewKey + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.ColumnBigint{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.ColumnBigint + parsed, ok := resp.Result.(models.ColumnBigint) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + } type CreateBooleanColumnOptions struct { Default bool diff --git a/tablesdb/tables_db_test.go b/tablesdb/tables_db_test.go index e235baf2..91997085 100644 --- a/tablesdb/tables_db_test.go +++ b/tablesdb/tables_db_test.go @@ -776,6 +776,70 @@ func TestTablesDB(t *testing.T) { } }) + t.Run("Test CreateBigIntColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "count", + "type": "bigint", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + t.Errorf("Expected method POST, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.CreateBigIntColumn("", "", "", true) + if err != nil { + t.Errorf("Method CreateBigIntColumn failed: %v", err) + } + }) + + t.Run("Test UpdateBigIntColumn", func(t *testing.T) { + mockResponse := ` +{ + "key": "count", + "type": "bigint", + "status": "available", + "error": "string", + "required": true, + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdateBigIntColumn("", "", "", true, 1) + if err != nil { + t.Errorf("Method UpdateBigIntColumn failed: %v", err) + } + }) + t.Run("Test CreateBooleanColumn", func(t *testing.T) { mockResponse := ` { diff --git a/teams/teams_test.go b/teams/teams_test.go index dc909b78..57fa52a9 100644 --- a/teams/teams_test.go +++ b/teams/teams_test.go @@ -187,6 +187,7 @@ func TestTeams(t *testing.T) { "userId": "5e5ea5c16897e", "userName": "John Doe", "userEmail": "john@appwrite.io", + "userPhone": "+1 555 555 5555", "teamId": "5e5ea5c16897e", "teamName": "VIP", "invited": "2020-10-15T06:38:00.000+00:00", @@ -227,6 +228,7 @@ func TestTeams(t *testing.T) { "userId": "5e5ea5c16897e", "userName": "John Doe", "userEmail": "john@appwrite.io", + "userPhone": "+1 555 555 5555", "teamId": "5e5ea5c16897e", "teamName": "VIP", "invited": "2020-10-15T06:38:00.000+00:00", @@ -265,6 +267,7 @@ func TestTeams(t *testing.T) { "userId": "5e5ea5c16897e", "userName": "John Doe", "userEmail": "john@appwrite.io", + "userPhone": "+1 555 555 5555", "teamId": "5e5ea5c16897e", "teamName": "VIP", "invited": "2020-10-15T06:38:00.000+00:00", @@ -303,6 +306,7 @@ func TestTeams(t *testing.T) { "userId": "5e5ea5c16897e", "userName": "John Doe", "userEmail": "john@appwrite.io", + "userPhone": "+1 555 555 5555", "teamId": "5e5ea5c16897e", "teamName": "VIP", "invited": "2020-10-15T06:38:00.000+00:00", @@ -367,6 +371,7 @@ func TestTeams(t *testing.T) { "userId": "5e5ea5c16897e", "userName": "John Doe", "userEmail": "john@appwrite.io", + "userPhone": "+1 555 555 5555", "teamId": "5e5ea5c16897e", "teamName": "VIP", "invited": "2020-10-15T06:38:00.000+00:00", diff --git a/users/users_test.go b/users/users_test.go index 8dbd19a9..dc1bf95c 100644 --- a/users/users_test.go +++ b/users/users_test.go @@ -892,6 +892,7 @@ func TestUsers(t *testing.T) { "userId": "5e5ea5c16897e", "userName": "John Doe", "userEmail": "john@appwrite.io", + "userPhone": "+1 555 555 5555", "teamId": "5e5ea5c16897e", "teamName": "VIP", "invited": "2020-10-15T06:38:00.000+00:00", From 6695939bb9ba88821d70a2a6a75e8af07968cd4a Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 7 May 2026 18:51:22 +0530 Subject: [PATCH 2/7] chore: refresh sdk for latest spec (sanitized oauth examples) --- CHANGELOG.md | 6 ------ client/client.go | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2bd1d5c..d83e8b40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,5 @@ # Change Log -## v3.1.0 - -* Added: Introduced `bigint` create/update APIs for legacy Databases attributes -* Added: Introduced `bigint` create/update APIs for `TablesDB` columns -* Updated: Extended key-list query filters with `key`, `resourceType`, `resourceId`, and `secret` - ## v3.0.0 * [BREAKING] Renamed Webhook model fields: `security` → `tls`, `httpUser` → `authUsername`, `httpPass` → `authPassword`, `signatureKey` → `secret` diff --git a/client/client.go b/client/client.go index 8175418f..30581fb3 100644 --- a/client/client.go +++ b/client/client.go @@ -74,11 +74,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.9.4", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.1.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.0.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v3.1.0", + "x-sdk-version": "v3.0.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { From 81fb3caa643a614e2cda1ea047b0744b9ef97db3 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 7 May 2026 18:58:52 +0530 Subject: [PATCH 3/7] chore: refresh sdk for latest spec (sanitized oauth examples) --- CHANGELOG.md | 6 ++++++ client/client.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d83e8b40..a2bd1d5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## v3.1.0 + +* Added: Introduced `bigint` create/update APIs for legacy Databases attributes +* Added: Introduced `bigint` create/update APIs for `TablesDB` columns +* Updated: Extended key-list query filters with `key`, `resourceType`, `resourceId`, and `secret` + ## v3.0.0 * [BREAKING] Renamed Webhook model fields: `security` → `tls`, `httpUser` → `authUsername`, `httpPass` → `authPassword`, `signatureKey` → `secret` diff --git a/client/client.go b/client/client.go index 30581fb3..8175418f 100644 --- a/client/client.go +++ b/client/client.go @@ -74,11 +74,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.9.4", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.0.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.1.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v3.0.0", + "x-sdk-version": "v3.1.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { From 1e87dd048272fd319c3c7c72e3e13c6c621bed98 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 8 May 2026 10:43:24 +0000 Subject: [PATCH 4/7] feat: Go SDK update for version v3.1.0 --- appwrite/appwrite.go | 4 + client/client.go | 4 +- docs/examples/presences/delete.md | 21 ++ docs/examples/presences/get.md | 21 ++ docs/examples/presences/list.md | 23 ++ docs/examples/presences/update-presence.md | 27 ++ docs/examples/presences/upsert.md | 26 ++ models/backupArchive.go | 2 +- models/presence.go | 53 +++ models/presenceList.go | 35 ++ models/presenceList_test.go | 24 ++ models/presence_test.go | 41 +++ presences/presences.go | 354 +++++++++++++++++++++ presences/presences_test.go | 181 +++++++++++ 14 files changed, 813 insertions(+), 3 deletions(-) create mode 100644 docs/examples/presences/delete.md create mode 100644 docs/examples/presences/get.md create mode 100644 docs/examples/presences/list.md create mode 100644 docs/examples/presences/update-presence.md create mode 100644 docs/examples/presences/upsert.md create mode 100644 models/presence.go create mode 100644 models/presenceList.go create mode 100644 models/presenceList_test.go create mode 100644 models/presence_test.go create mode 100644 presences/presences.go create mode 100644 presences/presences_test.go diff --git a/appwrite/appwrite.go b/appwrite/appwrite.go index a858a2a5..ff83cd9c 100644 --- a/appwrite/appwrite.go +++ b/appwrite/appwrite.go @@ -14,6 +14,7 @@ import ( "github.com/appwrite/sdk-for-go/v3/health" "github.com/appwrite/sdk-for-go/v3/locale" "github.com/appwrite/sdk-for-go/v3/messaging" + "github.com/appwrite/sdk-for-go/v3/presences" "github.com/appwrite/sdk-for-go/v3/project" "github.com/appwrite/sdk-for-go/v3/proxy" "github.com/appwrite/sdk-for-go/v3/sites" @@ -55,6 +56,9 @@ func NewLocale(clt client.Client) *locale.Locale { func NewMessaging(clt client.Client) *messaging.Messaging { return messaging.New(clt) } +func NewPresences(clt client.Client) *presences.Presences { + return presences.New(clt) +} func NewProject(clt client.Client) *project.Project { return project.New(clt) } diff --git a/client/client.go b/client/client.go index 8175418f..b5888476 100644 --- a/client/client.go +++ b/client/client.go @@ -74,11 +74,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.9.4", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.1.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.2.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v3.1.0", + "x-sdk-version": "v3.2.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { diff --git a/docs/examples/presences/delete.md b/docs/examples/presences/delete.md new file mode 100644 index 00000000..446c0ecc --- /dev/null +++ b/docs/examples/presences/delete.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/presences" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := presences.New(client) + +response, error := service.Delete( + "", +) +``` diff --git a/docs/examples/presences/get.md b/docs/examples/presences/get.md new file mode 100644 index 00000000..f6a27093 --- /dev/null +++ b/docs/examples/presences/get.md @@ -0,0 +1,21 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/presences" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := presences.New(client) + +response, error := service.Get( + "", +) +``` diff --git a/docs/examples/presences/list.md b/docs/examples/presences/list.md new file mode 100644 index 00000000..c21af919 --- /dev/null +++ b/docs/examples/presences/list.md @@ -0,0 +1,23 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/presences" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := presences.New(client) + +response, error := service.List( + presences.WithListQueries([]interface{}{}), + presences.WithListTotal(false), + presences.WithListTtl(0), +) +``` diff --git a/docs/examples/presences/update-presence.md b/docs/examples/presences/update-presence.md new file mode 100644 index 00000000..10c9107c --- /dev/null +++ b/docs/examples/presences/update-presence.md @@ -0,0 +1,27 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/presences" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := presences.New(client) + +response, error := service.UpdatePresence( + "", + "", + presences.WithUpdatePresenceStatus(""), + presences.WithUpdatePresenceExpiresAt("2020-10-15T06:38:00.000+00:00"), + presences.WithUpdatePresenceMetadata(map[string]interface{}{}), + presences.WithUpdatePresencePermissions(interface{}{"read("any")"}), + presences.WithUpdatePresencePurge(false), +) +``` diff --git a/docs/examples/presences/upsert.md b/docs/examples/presences/upsert.md new file mode 100644 index 00000000..369c73c6 --- /dev/null +++ b/docs/examples/presences/upsert.md @@ -0,0 +1,26 @@ +```go +package main + +import ( + "fmt" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/presences" +) + +client := client.New( + client.WithEndpoint("https://.cloud.appwrite.io/v1") + client.WithProject("") + client.WithKey("") +) + +service := presences.New(client) + +response, error := service.Upsert( + "", + "", + "", + presences.WithUpsertPermissions(interface{}{"read("any")"}), + presences.WithUpsertExpiresAt("2020-10-15T06:38:00.000+00:00"), + presences.WithUpsertMetadata(map[string]interface{}{}), +) +``` diff --git a/models/backupArchive.go b/models/backupArchive.go index 88b0395e..8c61d6f2 100644 --- a/models/backupArchive.go +++ b/models/backupArchive.go @@ -18,7 +18,7 @@ type BackupArchive struct { // Archive size in bytes. Size int `json:"size"` // The status of the archive creation. Possible values: pending, processing, - // uploading, completed, failed. + // uploading, completed, failed, skipped. Status string `json:"status"` // The backup start time. StartedAt string `json:"startedAt"` diff --git a/models/presence.go b/models/presence.go new file mode 100644 index 00000000..039331f5 --- /dev/null +++ b/models/presence.go @@ -0,0 +1,53 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// Presence Model +type Presence struct { + // Presence ID. + Id string `json:"$id"` + // Presence sequence ID. + Sequence string `json:"$sequence"` + // Presence creation date in ISO 8601 format. + CreatedAt string `json:"$createdAt"` + // Presence update date in ISO 8601 format. + UpdatedAt string `json:"$updatedAt"` + // Presence permissions. [Learn more about + // permissions](https://appwrite.io/docs/permissions). + Permissions []string `json:"$permissions"` + // User internal ID. + UserInternalId string `json:"userInternalId"` + // User ID. + UserId string `json:"userId"` + // Presence status. + Status string `json:"status"` + // Presence source. + Source string `json:"source"` + // Presence expiry date in ISO 8601 format. + ExpiresAt string `json:"expiresAt"` + + // Used by Decode() method + data []byte +} + +func (model Presence) New(data []byte) *Presence { + model.data = data + return &model +} + +// Use this method to get response in desired type +func (model *Presence) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/presenceList.go b/models/presenceList.go new file mode 100644 index 00000000..3f40e085 --- /dev/null +++ b/models/presenceList.go @@ -0,0 +1,35 @@ +package models + +import ( + "encoding/json" + "errors" +) + +// PresencesList Model +type PresenceList struct { + // Total number of presences that matched your query. + Total int `json:"total"` + // List of presences. + Presences []Presence `json:"presences"` + + // Used by Decode() method + data []byte +} + +func (model PresenceList) New(data []byte) *PresenceList { + model.data = data + return &model +} + +func (model *PresenceList) Decode(value interface{}) error { + if len(model.data) <= 0 { + return errors.New("method Decode() cannot be used on nested struct") + } + + err := json.Unmarshal(model.data, value) + if err != nil { + return err + } + + return nil +} \ No newline at end of file diff --git a/models/presenceList_test.go b/models/presenceList_test.go new file mode 100644 index 00000000..65819158 --- /dev/null +++ b/models/presenceList_test.go @@ -0,0 +1,24 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPresenceListModel(t *testing.T) { + model := PresenceList{ Total: 5, Presences: []Presence{Presence{ Id: "5e5ea5c16897e", Sequence: "1", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, UserInternalId: "1", UserId: "674af8f3e12a5f9ac0be", Source: "HTTP", }, + }, } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result PresenceList + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Total != model.Total { + t.Errorf("Expected Total %v, got %v", model.Total, result.Total) + }} diff --git a/models/presence_test.go b/models/presence_test.go new file mode 100644 index 00000000..2348ebae --- /dev/null +++ b/models/presence_test.go @@ -0,0 +1,41 @@ +package models + +import ( + "encoding/json" + "testing" +) + +func TestPresenceModel(t *testing.T) { + model := Presence{ Id: "5e5ea5c16897e", Sequence: "1", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, UserInternalId: "1", UserId: "674af8f3e12a5f9ac0be", Source: "HTTP", } + + data, err := json.Marshal(model) + if err != nil { + t.Fatal(err) + } + + var result Presence + err = json.Unmarshal(data, &result) + if err != nil { + t.Fatal(err) + } + if result.Id != model.Id { + t.Errorf("Expected Id %v, got %v", model.Id, result.Id) + } + if result.Sequence != model.Sequence { + t.Errorf("Expected Sequence %v, got %v", model.Sequence, result.Sequence) + } + if result.CreatedAt != model.CreatedAt { + t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) + } + if result.UpdatedAt != model.UpdatedAt { + t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) + } + if result.UserInternalId != model.UserInternalId { + t.Errorf("Expected UserInternalId %v, got %v", model.UserInternalId, result.UserInternalId) + } + if result.UserId != model.UserId { + t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) + } + if result.Source != model.Source { + t.Errorf("Expected Source %v, got %v", model.Source, result.Source) + }} diff --git a/presences/presences.go b/presences/presences.go new file mode 100644 index 00000000..0925c232 --- /dev/null +++ b/presences/presences.go @@ -0,0 +1,354 @@ +package presences + +import ( + "encoding/json" + "errors" + "github.com/appwrite/sdk-for-go/v3/client" + "github.com/appwrite/sdk-for-go/v3/models" + "strings" +) + +// Presences service +type Presences struct { + client client.Client +} + +func New(clt client.Client) *Presences { + return &Presences{ + client: clt, + } +} + +type ListOptions struct { + Queries []string + Total bool + Ttl int + enabledSetters map[string]bool +} +func (options ListOptions) New() *ListOptions { + options.enabledSetters = map[string]bool{ + "Queries": false, + "Total": false, + "Ttl": false, + } + return &options +} +type ListOption func(*ListOptions) +func (srv *Presences) WithListQueries(v []string) ListOption { + return func(o *ListOptions) { + o.Queries = v + o.enabledSetters["Queries"] = true + } +} +func (srv *Presences) WithListTotal(v bool) ListOption { + return func(o *ListOptions) { + o.Total = v + o.enabledSetters["Total"] = true + } +} +func (srv *Presences) WithListTtl(v int) ListOption { + return func(o *ListOptions) { + o.Ttl = v + o.enabledSetters["Ttl"] = true + } +} + +// List list presence logs. +func (srv *Presences) List(optionalSetters ...ListOption)(*models.PresenceList, error) { + path := "/presences" + options := ListOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["Queries"] { + params["queries"] = options.Queries + } + if options.enabledSetters["Total"] { + params["total"] = options.Total + } + if options.enabledSetters["Ttl"] { + params["ttl"] = options.Ttl + } + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.PresenceList{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.PresenceList + parsed, ok := resp.Result.(models.PresenceList) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Get get a presence log by its unique ID. +func (srv *Presences) Get(PresenceId string)(*models.Presence, error) { + r := strings.NewReplacer("{presenceId}", PresenceId) + path := r.Replace("/presences/{presenceId}") + params := map[string]interface{}{} + params["presenceId"] = PresenceId + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Presence{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Presence + parsed, ok := resp.Result.(models.Presence) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpsertOptions struct { + Permissions []string + ExpiresAt string + Metadata interface{} + enabledSetters map[string]bool +} +func (options UpsertOptions) New() *UpsertOptions { + options.enabledSetters = map[string]bool{ + "Permissions": false, + "ExpiresAt": false, + "Metadata": false, + } + return &options +} +type UpsertOption func(*UpsertOptions) +func (srv *Presences) WithUpsertPermissions(v []string) UpsertOption { + return func(o *UpsertOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *Presences) WithUpsertExpiresAt(v string) UpsertOption { + return func(o *UpsertOptions) { + o.ExpiresAt = v + o.enabledSetters["ExpiresAt"] = true + } +} +func (srv *Presences) WithUpsertMetadata(v interface{}) UpsertOption { + return func(o *UpsertOptions) { + o.Metadata = v + o.enabledSetters["Metadata"] = true + } +} + +// Upsert create or update a presence log by its unique ID. +func (srv *Presences) Upsert(PresenceId string, UserId string, Status string, optionalSetters ...UpsertOption)(*models.Presence, error) { + r := strings.NewReplacer("{presenceId}", PresenceId) + path := r.Replace("/presences/{presenceId}") + options := UpsertOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["presenceId"] = PresenceId + params["userId"] = UserId + params["status"] = Status + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["ExpiresAt"] { + params["expiresAt"] = options.ExpiresAt + } + if options.enabledSetters["Metadata"] { + params["metadata"] = options.Metadata + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PUT", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Presence{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Presence + parsed, ok := resp.Result.(models.Presence) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdatePresenceOptions struct { + Status string + ExpiresAt string + Metadata interface{} + Permissions []string + Purge bool + enabledSetters map[string]bool +} +func (options UpdatePresenceOptions) New() *UpdatePresenceOptions { + options.enabledSetters = map[string]bool{ + "Status": false, + "ExpiresAt": false, + "Metadata": false, + "Permissions": false, + "Purge": false, + } + return &options +} +type UpdatePresenceOption func(*UpdatePresenceOptions) +func (srv *Presences) WithUpdatePresenceStatus(v string) UpdatePresenceOption { + return func(o *UpdatePresenceOptions) { + o.Status = v + o.enabledSetters["Status"] = true + } +} +func (srv *Presences) WithUpdatePresenceExpiresAt(v string) UpdatePresenceOption { + return func(o *UpdatePresenceOptions) { + o.ExpiresAt = v + o.enabledSetters["ExpiresAt"] = true + } +} +func (srv *Presences) WithUpdatePresenceMetadata(v interface{}) UpdatePresenceOption { + return func(o *UpdatePresenceOptions) { + o.Metadata = v + o.enabledSetters["Metadata"] = true + } +} +func (srv *Presences) WithUpdatePresencePermissions(v []string) UpdatePresenceOption { + return func(o *UpdatePresenceOptions) { + o.Permissions = v + o.enabledSetters["Permissions"] = true + } +} +func (srv *Presences) WithUpdatePresencePurge(v bool) UpdatePresenceOption { + return func(o *UpdatePresenceOptions) { + o.Purge = v + o.enabledSetters["Purge"] = true + } +} + +// UpdatePresence update a presence log by its unique ID. +func (srv *Presences) UpdatePresence(PresenceId string, UserId string, optionalSetters ...UpdatePresenceOption)(*models.Presence, error) { + r := strings.NewReplacer("{presenceId}", PresenceId) + path := r.Replace("/presences/{presenceId}") + options := UpdatePresenceOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + params["presenceId"] = PresenceId + params["userId"] = UserId + if options.enabledSetters["Status"] { + params["status"] = options.Status + } + if options.enabledSetters["ExpiresAt"] { + params["expiresAt"] = options.ExpiresAt + } + if options.enabledSetters["Metadata"] { + params["metadata"] = options.Metadata + } + if options.enabledSetters["Permissions"] { + params["permissions"] = options.Permissions + } + if options.enabledSetters["Purge"] { + params["purge"] = options.Purge + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.Presence{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.Presence + parsed, ok := resp.Result.(models.Presence) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// Delete delete a presence log by its unique ID. +func (srv *Presences) Delete(PresenceId string)(*interface{}, error) { + r := strings.NewReplacer("{presenceId}", PresenceId) + path := r.Replace("/presences/{presenceId}") + params := map[string]interface{}{} + params["presenceId"] = PresenceId + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("DELETE", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var parsed interface{} + + err = json.Unmarshal(bytes, &parsed) + if err != nil { + return nil, err + } + return &parsed, nil + } + var parsed interface{} + parsed, ok := resp.Result.(interface{}) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} diff --git a/presences/presences_test.go b/presences/presences_test.go new file mode 100644 index 00000000..f6737d8a --- /dev/null +++ b/presences/presences_test.go @@ -0,0 +1,181 @@ +package presences + +import ( + "net/http" + "net/http/httptest" + "testing" + + "github.com/appwrite/sdk-for-go/v3/client" +) + +func TestPresences(t *testing.T) { + newTestClient := func(ts *httptest.Server) client.Client { + c := client.New() + c.Endpoint = ts.URL + c.Client = ts.Client() + return c + } + + t.Run("Test List", func(t *testing.T) { + mockResponse := ` +{ + "total": 5, + "presences": [ + { + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "userInternalId": "1", + "userId": "674af8f3e12a5f9ac0be", + "source": "HTTP" + } + ] +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.List() + if err != nil { + t.Errorf("Method List failed: %v", err) + } + }) + + t.Run("Test Get", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "userInternalId": "1", + "userId": "674af8f3e12a5f9ac0be", + "source": "HTTP" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Get("") + if err != nil { + t.Errorf("Method Get failed: %v", err) + } + }) + + t.Run("Test Upsert", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "userInternalId": "1", + "userId": "674af8f3e12a5f9ac0be", + "source": "HTTP" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PUT" { + t.Errorf("Expected method PUT, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Upsert("", "", "") + if err != nil { + t.Errorf("Method Upsert failed: %v", err) + } + }) + + t.Run("Test UpdatePresence", func(t *testing.T) { + mockResponse := ` +{ + "$id": "5e5ea5c16897e", + "$sequence": "1", + "$createdAt": "2020-10-15T06:38:00.000+00:00", + "$updatedAt": "2020-10-15T06:38:00.000+00:00", + "$permissions": [], + "userInternalId": "1", + "userId": "674af8f3e12a5f9ac0be", + "source": "HTTP" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "PATCH" { + t.Errorf("Expected method PATCH, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.UpdatePresence("", "") + if err != nil { + t.Errorf("Method UpdatePresence failed: %v", err) + } + }) + + t.Run("Test Delete", func(t *testing.T) { + mockResponse := ` +{ + "message": "success" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "DELETE" { + t.Errorf("Expected method DELETE, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + _, err := srv.Delete("") + if err != nil { + t.Errorf("Method Delete failed: %v", err) + } + }) +} From 214226b3d31d614beec8a06133504bc19bf69e32 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 8 May 2026 11:00:22 +0000 Subject: [PATCH 5/7] feat: Go SDK update for version v3.1.0 --- client/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/client.go b/client/client.go index b5888476..8175418f 100644 --- a/client/client.go +++ b/client/client.go @@ -74,11 +74,11 @@ type Client struct { func New(optionalSetters ...ClientOption) Client { headers := map[string]string{ "X-Appwrite-Response-Format" : "1.9.4", - "user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.2.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), + "user-agent" : fmt.Sprintf("AppwriteGoSDK/v3.1.0 (%s; %s)", runtime.GOOS, runtime.GOARCH), "x-sdk-name": "Go", "x-sdk-platform": "server", "x-sdk-language": "go", - "x-sdk-version": "v3.2.0", + "x-sdk-version": "v3.1.0", } httpClient, err := GetDefaultClient(defaultTimeout) if err != nil { From 4beeef254fa3b30a2f83eec7636a42ab22face9d Mon Sep 17 00:00:00 2001 From: root Date: Fri, 8 May 2026 11:14:21 +0000 Subject: [PATCH 6/7] chore: remove presences API artifacts --- appwrite/appwrite.go | 4 - docs/examples/presences/delete.md | 21 -- docs/examples/presences/get.md | 21 -- docs/examples/presences/list.md | 23 -- docs/examples/presences/update-presence.md | 27 -- docs/examples/presences/upsert.md | 26 -- models/presence.go | 53 --- models/presenceList.go | 35 -- models/presenceList_test.go | 24 -- models/presence_test.go | 41 --- presences/presences.go | 354 --------------------- presences/presences_test.go | 181 ----------- 12 files changed, 810 deletions(-) delete mode 100644 docs/examples/presences/delete.md delete mode 100644 docs/examples/presences/get.md delete mode 100644 docs/examples/presences/list.md delete mode 100644 docs/examples/presences/update-presence.md delete mode 100644 docs/examples/presences/upsert.md delete mode 100644 models/presence.go delete mode 100644 models/presenceList.go delete mode 100644 models/presenceList_test.go delete mode 100644 models/presence_test.go delete mode 100644 presences/presences.go delete mode 100644 presences/presences_test.go diff --git a/appwrite/appwrite.go b/appwrite/appwrite.go index ff83cd9c..a858a2a5 100644 --- a/appwrite/appwrite.go +++ b/appwrite/appwrite.go @@ -14,7 +14,6 @@ import ( "github.com/appwrite/sdk-for-go/v3/health" "github.com/appwrite/sdk-for-go/v3/locale" "github.com/appwrite/sdk-for-go/v3/messaging" - "github.com/appwrite/sdk-for-go/v3/presences" "github.com/appwrite/sdk-for-go/v3/project" "github.com/appwrite/sdk-for-go/v3/proxy" "github.com/appwrite/sdk-for-go/v3/sites" @@ -56,9 +55,6 @@ func NewLocale(clt client.Client) *locale.Locale { func NewMessaging(clt client.Client) *messaging.Messaging { return messaging.New(clt) } -func NewPresences(clt client.Client) *presences.Presences { - return presences.New(clt) -} func NewProject(clt client.Client) *project.Project { return project.New(clt) } diff --git a/docs/examples/presences/delete.md b/docs/examples/presences/delete.md deleted file mode 100644 index 446c0ecc..00000000 --- a/docs/examples/presences/delete.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/v3/client" - "github.com/appwrite/sdk-for-go/v3/presences" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := presences.New(client) - -response, error := service.Delete( - "", -) -``` diff --git a/docs/examples/presences/get.md b/docs/examples/presences/get.md deleted file mode 100644 index f6a27093..00000000 --- a/docs/examples/presences/get.md +++ /dev/null @@ -1,21 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/v3/client" - "github.com/appwrite/sdk-for-go/v3/presences" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := presences.New(client) - -response, error := service.Get( - "", -) -``` diff --git a/docs/examples/presences/list.md b/docs/examples/presences/list.md deleted file mode 100644 index c21af919..00000000 --- a/docs/examples/presences/list.md +++ /dev/null @@ -1,23 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/v3/client" - "github.com/appwrite/sdk-for-go/v3/presences" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := presences.New(client) - -response, error := service.List( - presences.WithListQueries([]interface{}{}), - presences.WithListTotal(false), - presences.WithListTtl(0), -) -``` diff --git a/docs/examples/presences/update-presence.md b/docs/examples/presences/update-presence.md deleted file mode 100644 index 10c9107c..00000000 --- a/docs/examples/presences/update-presence.md +++ /dev/null @@ -1,27 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/v3/client" - "github.com/appwrite/sdk-for-go/v3/presences" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := presences.New(client) - -response, error := service.UpdatePresence( - "", - "", - presences.WithUpdatePresenceStatus(""), - presences.WithUpdatePresenceExpiresAt("2020-10-15T06:38:00.000+00:00"), - presences.WithUpdatePresenceMetadata(map[string]interface{}{}), - presences.WithUpdatePresencePermissions(interface{}{"read("any")"}), - presences.WithUpdatePresencePurge(false), -) -``` diff --git a/docs/examples/presences/upsert.md b/docs/examples/presences/upsert.md deleted file mode 100644 index 369c73c6..00000000 --- a/docs/examples/presences/upsert.md +++ /dev/null @@ -1,26 +0,0 @@ -```go -package main - -import ( - "fmt" - "github.com/appwrite/sdk-for-go/v3/client" - "github.com/appwrite/sdk-for-go/v3/presences" -) - -client := client.New( - client.WithEndpoint("https://.cloud.appwrite.io/v1") - client.WithProject("") - client.WithKey("") -) - -service := presences.New(client) - -response, error := service.Upsert( - "", - "", - "", - presences.WithUpsertPermissions(interface{}{"read("any")"}), - presences.WithUpsertExpiresAt("2020-10-15T06:38:00.000+00:00"), - presences.WithUpsertMetadata(map[string]interface{}{}), -) -``` diff --git a/models/presence.go b/models/presence.go deleted file mode 100644 index 039331f5..00000000 --- a/models/presence.go +++ /dev/null @@ -1,53 +0,0 @@ -package models - -import ( - "encoding/json" - "errors" -) - -// Presence Model -type Presence struct { - // Presence ID. - Id string `json:"$id"` - // Presence sequence ID. - Sequence string `json:"$sequence"` - // Presence creation date in ISO 8601 format. - CreatedAt string `json:"$createdAt"` - // Presence update date in ISO 8601 format. - UpdatedAt string `json:"$updatedAt"` - // Presence permissions. [Learn more about - // permissions](https://appwrite.io/docs/permissions). - Permissions []string `json:"$permissions"` - // User internal ID. - UserInternalId string `json:"userInternalId"` - // User ID. - UserId string `json:"userId"` - // Presence status. - Status string `json:"status"` - // Presence source. - Source string `json:"source"` - // Presence expiry date in ISO 8601 format. - ExpiresAt string `json:"expiresAt"` - - // Used by Decode() method - data []byte -} - -func (model Presence) New(data []byte) *Presence { - model.data = data - return &model -} - -// Use this method to get response in desired type -func (model *Presence) Decode(value interface{}) error { - if len(model.data) <= 0 { - return errors.New("method Decode() cannot be used on nested struct") - } - - err := json.Unmarshal(model.data, value) - if err != nil { - return err - } - - return nil -} \ No newline at end of file diff --git a/models/presenceList.go b/models/presenceList.go deleted file mode 100644 index 3f40e085..00000000 --- a/models/presenceList.go +++ /dev/null @@ -1,35 +0,0 @@ -package models - -import ( - "encoding/json" - "errors" -) - -// PresencesList Model -type PresenceList struct { - // Total number of presences that matched your query. - Total int `json:"total"` - // List of presences. - Presences []Presence `json:"presences"` - - // Used by Decode() method - data []byte -} - -func (model PresenceList) New(data []byte) *PresenceList { - model.data = data - return &model -} - -func (model *PresenceList) Decode(value interface{}) error { - if len(model.data) <= 0 { - return errors.New("method Decode() cannot be used on nested struct") - } - - err := json.Unmarshal(model.data, value) - if err != nil { - return err - } - - return nil -} \ No newline at end of file diff --git a/models/presenceList_test.go b/models/presenceList_test.go deleted file mode 100644 index 65819158..00000000 --- a/models/presenceList_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package models - -import ( - "encoding/json" - "testing" -) - -func TestPresenceListModel(t *testing.T) { - model := PresenceList{ Total: 5, Presences: []Presence{Presence{ Id: "5e5ea5c16897e", Sequence: "1", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, UserInternalId: "1", UserId: "674af8f3e12a5f9ac0be", Source: "HTTP", }, - }, } - - data, err := json.Marshal(model) - if err != nil { - t.Fatal(err) - } - - var result PresenceList - err = json.Unmarshal(data, &result) - if err != nil { - t.Fatal(err) - } - if result.Total != model.Total { - t.Errorf("Expected Total %v, got %v", model.Total, result.Total) - }} diff --git a/models/presence_test.go b/models/presence_test.go deleted file mode 100644 index 2348ebae..00000000 --- a/models/presence_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package models - -import ( - "encoding/json" - "testing" -) - -func TestPresenceModel(t *testing.T) { - model := Presence{ Id: "5e5ea5c16897e", Sequence: "1", CreatedAt: "2020-10-15T06:38:00.000+00:00", UpdatedAt: "2020-10-15T06:38:00.000+00:00", Permissions: []string{"test"}, UserInternalId: "1", UserId: "674af8f3e12a5f9ac0be", Source: "HTTP", } - - data, err := json.Marshal(model) - if err != nil { - t.Fatal(err) - } - - var result Presence - err = json.Unmarshal(data, &result) - if err != nil { - t.Fatal(err) - } - if result.Id != model.Id { - t.Errorf("Expected Id %v, got %v", model.Id, result.Id) - } - if result.Sequence != model.Sequence { - t.Errorf("Expected Sequence %v, got %v", model.Sequence, result.Sequence) - } - if result.CreatedAt != model.CreatedAt { - t.Errorf("Expected CreatedAt %v, got %v", model.CreatedAt, result.CreatedAt) - } - if result.UpdatedAt != model.UpdatedAt { - t.Errorf("Expected UpdatedAt %v, got %v", model.UpdatedAt, result.UpdatedAt) - } - if result.UserInternalId != model.UserInternalId { - t.Errorf("Expected UserInternalId %v, got %v", model.UserInternalId, result.UserInternalId) - } - if result.UserId != model.UserId { - t.Errorf("Expected UserId %v, got %v", model.UserId, result.UserId) - } - if result.Source != model.Source { - t.Errorf("Expected Source %v, got %v", model.Source, result.Source) - }} diff --git a/presences/presences.go b/presences/presences.go deleted file mode 100644 index 0925c232..00000000 --- a/presences/presences.go +++ /dev/null @@ -1,354 +0,0 @@ -package presences - -import ( - "encoding/json" - "errors" - "github.com/appwrite/sdk-for-go/v3/client" - "github.com/appwrite/sdk-for-go/v3/models" - "strings" -) - -// Presences service -type Presences struct { - client client.Client -} - -func New(clt client.Client) *Presences { - return &Presences{ - client: clt, - } -} - -type ListOptions struct { - Queries []string - Total bool - Ttl int - enabledSetters map[string]bool -} -func (options ListOptions) New() *ListOptions { - options.enabledSetters = map[string]bool{ - "Queries": false, - "Total": false, - "Ttl": false, - } - return &options -} -type ListOption func(*ListOptions) -func (srv *Presences) WithListQueries(v []string) ListOption { - return func(o *ListOptions) { - o.Queries = v - o.enabledSetters["Queries"] = true - } -} -func (srv *Presences) WithListTotal(v bool) ListOption { - return func(o *ListOptions) { - o.Total = v - o.enabledSetters["Total"] = true - } -} -func (srv *Presences) WithListTtl(v int) ListOption { - return func(o *ListOptions) { - o.Ttl = v - o.enabledSetters["Ttl"] = true - } -} - -// List list presence logs. -func (srv *Presences) List(optionalSetters ...ListOption)(*models.PresenceList, error) { - path := "/presences" - options := ListOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["Queries"] { - params["queries"] = options.Queries - } - if options.enabledSetters["Total"] { - params["total"] = options.Total - } - if options.enabledSetters["Ttl"] { - params["ttl"] = options.Ttl - } - headers := map[string]interface{}{ - } - - resp, err := srv.client.Call("GET", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.PresenceList{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.PresenceList - parsed, ok := resp.Result.(models.PresenceList) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// Get get a presence log by its unique ID. -func (srv *Presences) Get(PresenceId string)(*models.Presence, error) { - r := strings.NewReplacer("{presenceId}", PresenceId) - path := r.Replace("/presences/{presenceId}") - params := map[string]interface{}{} - params["presenceId"] = PresenceId - headers := map[string]interface{}{ - } - - resp, err := srv.client.Call("GET", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Presence{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Presence - parsed, ok := resp.Result.(models.Presence) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpsertOptions struct { - Permissions []string - ExpiresAt string - Metadata interface{} - enabledSetters map[string]bool -} -func (options UpsertOptions) New() *UpsertOptions { - options.enabledSetters = map[string]bool{ - "Permissions": false, - "ExpiresAt": false, - "Metadata": false, - } - return &options -} -type UpsertOption func(*UpsertOptions) -func (srv *Presences) WithUpsertPermissions(v []string) UpsertOption { - return func(o *UpsertOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} -func (srv *Presences) WithUpsertExpiresAt(v string) UpsertOption { - return func(o *UpsertOptions) { - o.ExpiresAt = v - o.enabledSetters["ExpiresAt"] = true - } -} -func (srv *Presences) WithUpsertMetadata(v interface{}) UpsertOption { - return func(o *UpsertOptions) { - o.Metadata = v - o.enabledSetters["Metadata"] = true - } -} - -// Upsert create or update a presence log by its unique ID. -func (srv *Presences) Upsert(PresenceId string, UserId string, Status string, optionalSetters ...UpsertOption)(*models.Presence, error) { - r := strings.NewReplacer("{presenceId}", PresenceId) - path := r.Replace("/presences/{presenceId}") - options := UpsertOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["presenceId"] = PresenceId - params["userId"] = UserId - params["status"] = Status - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - if options.enabledSetters["ExpiresAt"] { - params["expiresAt"] = options.ExpiresAt - } - if options.enabledSetters["Metadata"] { - params["metadata"] = options.Metadata - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PUT", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Presence{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Presence - parsed, ok := resp.Result.(models.Presence) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdatePresenceOptions struct { - Status string - ExpiresAt string - Metadata interface{} - Permissions []string - Purge bool - enabledSetters map[string]bool -} -func (options UpdatePresenceOptions) New() *UpdatePresenceOptions { - options.enabledSetters = map[string]bool{ - "Status": false, - "ExpiresAt": false, - "Metadata": false, - "Permissions": false, - "Purge": false, - } - return &options -} -type UpdatePresenceOption func(*UpdatePresenceOptions) -func (srv *Presences) WithUpdatePresenceStatus(v string) UpdatePresenceOption { - return func(o *UpdatePresenceOptions) { - o.Status = v - o.enabledSetters["Status"] = true - } -} -func (srv *Presences) WithUpdatePresenceExpiresAt(v string) UpdatePresenceOption { - return func(o *UpdatePresenceOptions) { - o.ExpiresAt = v - o.enabledSetters["ExpiresAt"] = true - } -} -func (srv *Presences) WithUpdatePresenceMetadata(v interface{}) UpdatePresenceOption { - return func(o *UpdatePresenceOptions) { - o.Metadata = v - o.enabledSetters["Metadata"] = true - } -} -func (srv *Presences) WithUpdatePresencePermissions(v []string) UpdatePresenceOption { - return func(o *UpdatePresenceOptions) { - o.Permissions = v - o.enabledSetters["Permissions"] = true - } -} -func (srv *Presences) WithUpdatePresencePurge(v bool) UpdatePresenceOption { - return func(o *UpdatePresenceOptions) { - o.Purge = v - o.enabledSetters["Purge"] = true - } -} - -// UpdatePresence update a presence log by its unique ID. -func (srv *Presences) UpdatePresence(PresenceId string, UserId string, optionalSetters ...UpdatePresenceOption)(*models.Presence, error) { - r := strings.NewReplacer("{presenceId}", PresenceId) - path := r.Replace("/presences/{presenceId}") - options := UpdatePresenceOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - params["presenceId"] = PresenceId - params["userId"] = UserId - if options.enabledSetters["Status"] { - params["status"] = options.Status - } - if options.enabledSetters["ExpiresAt"] { - params["expiresAt"] = options.ExpiresAt - } - if options.enabledSetters["Metadata"] { - params["metadata"] = options.Metadata - } - if options.enabledSetters["Permissions"] { - params["permissions"] = options.Permissions - } - if options.enabledSetters["Purge"] { - params["purge"] = options.Purge - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PATCH", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.Presence{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.Presence - parsed, ok := resp.Result.(models.Presence) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} - -// Delete delete a presence log by its unique ID. -func (srv *Presences) Delete(PresenceId string)(*interface{}, error) { - r := strings.NewReplacer("{presenceId}", PresenceId) - path := r.Replace("/presences/{presenceId}") - params := map[string]interface{}{} - params["presenceId"] = PresenceId - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("DELETE", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - var parsed interface{} - - err = json.Unmarshal(bytes, &parsed) - if err != nil { - return nil, err - } - return &parsed, nil - } - var parsed interface{} - parsed, ok := resp.Result.(interface{}) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} diff --git a/presences/presences_test.go b/presences/presences_test.go deleted file mode 100644 index f6737d8a..00000000 --- a/presences/presences_test.go +++ /dev/null @@ -1,181 +0,0 @@ -package presences - -import ( - "net/http" - "net/http/httptest" - "testing" - - "github.com/appwrite/sdk-for-go/v3/client" -) - -func TestPresences(t *testing.T) { - newTestClient := func(ts *httptest.Server) client.Client { - c := client.New() - c.Endpoint = ts.URL - c.Client = ts.Client() - return c - } - - t.Run("Test List", func(t *testing.T) { - mockResponse := ` -{ - "total": 5, - "presences": [ - { - "$id": "5e5ea5c16897e", - "$sequence": "1", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "$permissions": [], - "userInternalId": "1", - "userId": "674af8f3e12a5f9ac0be", - "source": "HTTP" - } - ] -} -` - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Expected method GET, got %s", r.Method) - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(mockResponse)) - })) - defer ts.Close() - - srv := New(newTestClient(ts)) - - _, err := srv.List() - if err != nil { - t.Errorf("Method List failed: %v", err) - } - }) - - t.Run("Test Get", func(t *testing.T) { - mockResponse := ` -{ - "$id": "5e5ea5c16897e", - "$sequence": "1", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "$permissions": [], - "userInternalId": "1", - "userId": "674af8f3e12a5f9ac0be", - "source": "HTTP" -} -` - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Expected method GET, got %s", r.Method) - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(mockResponse)) - })) - defer ts.Close() - - srv := New(newTestClient(ts)) - - _, err := srv.Get("") - if err != nil { - t.Errorf("Method Get failed: %v", err) - } - }) - - t.Run("Test Upsert", func(t *testing.T) { - mockResponse := ` -{ - "$id": "5e5ea5c16897e", - "$sequence": "1", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "$permissions": [], - "userInternalId": "1", - "userId": "674af8f3e12a5f9ac0be", - "source": "HTTP" -} -` - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "PUT" { - t.Errorf("Expected method PUT, got %s", r.Method) - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(mockResponse)) - })) - defer ts.Close() - - srv := New(newTestClient(ts)) - - _, err := srv.Upsert("", "", "") - if err != nil { - t.Errorf("Method Upsert failed: %v", err) - } - }) - - t.Run("Test UpdatePresence", func(t *testing.T) { - mockResponse := ` -{ - "$id": "5e5ea5c16897e", - "$sequence": "1", - "$createdAt": "2020-10-15T06:38:00.000+00:00", - "$updatedAt": "2020-10-15T06:38:00.000+00:00", - "$permissions": [], - "userInternalId": "1", - "userId": "674af8f3e12a5f9ac0be", - "source": "HTTP" -} -` - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "PATCH" { - t.Errorf("Expected method PATCH, got %s", r.Method) - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(mockResponse)) - })) - defer ts.Close() - - srv := New(newTestClient(ts)) - - _, err := srv.UpdatePresence("", "") - if err != nil { - t.Errorf("Method UpdatePresence failed: %v", err) - } - }) - - t.Run("Test Delete", func(t *testing.T) { - mockResponse := ` -{ - "message": "success" -} -` - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "DELETE" { - t.Errorf("Expected method DELETE, got %s", r.Method) - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(mockResponse)) - })) - defer ts.Close() - - srv := New(newTestClient(ts)) - - _, err := srv.Delete("") - if err != nil { - t.Errorf("Method Delete failed: %v", err) - } - }) -} From 29f0a8a58f92aae2c7f9085384e05b3ce4795e0d Mon Sep 17 00:00:00 2001 From: root Date: Fri, 8 May 2026 11:55:05 +0000 Subject: [PATCH 7/7] chore: update Go SDK to v3.1.0 --- README.md | 2 +- models/oAuth2Amazon_test.go | 2 +- models/oAuth2Auth0_test.go | 2 +- models/oAuth2Authentik_test.go | 2 +- models/oAuth2Autodesk_test.go | 2 +- models/oAuth2Bitbucket_test.go | 2 +- models/oAuth2Bitly_test.go | 2 +- models/oAuth2Box_test.go | 2 +- models/oAuth2Dailymotion_test.go | 2 +- models/oAuth2Discord_test.go | 2 +- models/oAuth2Disqus_test.go | 2 +- models/oAuth2Dropbox_test.go | 2 +- models/oAuth2Etsy_test.go | 2 +- models/oAuth2Facebook_test.go | 2 +- models/oAuth2Figma_test.go | 2 +- models/oAuth2FusionAuth_test.go | 2 +- models/oAuth2Github_test.go | 2 +- models/oAuth2Gitlab_test.go | 2 +- models/oAuth2Google_test.go | 2 +- models/oAuth2Keycloak_test.go | 2 +- models/oAuth2Kick_test.go | 2 +- models/oAuth2Linkedin_test.go | 2 +- models/oAuth2Microsoft_test.go | 2 +- models/oAuth2Notion_test.go | 2 +- models/oAuth2Oidc_test.go | 2 +- models/oAuth2Okta_test.go | 2 +- models/oAuth2Paypal_test.go | 2 +- models/oAuth2Podio_test.go | 2 +- models/oAuth2Salesforce_test.go | 2 +- models/oAuth2Slack_test.go | 2 +- models/oAuth2Spotify_test.go | 2 +- models/oAuth2Stripe_test.go | 2 +- models/oAuth2Tradeshift_test.go | 2 +- models/oAuth2Twitch_test.go | 2 +- models/oAuth2WordPress_test.go | 2 +- models/oAuth2X_test.go | 2 +- models/oAuth2Yahoo_test.go | 2 +- models/oAuth2Yandex_test.go | 2 +- models/oAuth2Zoho_test.go | 2 +- models/oAuth2Zoom_test.go | 2 +- project/project.go | 1367 +++++++++++++++--------------- project/project_test.go | 150 ++-- 42 files changed, 799 insertions(+), 798 deletions(-) diff --git a/README.md b/README.md index 76e362cd..da1e65bf 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-go/releases).** +**This SDK is compatible with Appwrite server version 1.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-go/releases).** Appwrite is an open-source backend as a service server that abstracts and simplifies complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Go SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/models/oAuth2Amazon_test.go b/models/oAuth2Amazon_test.go index a5a1d57d..33d4a22f 100644 --- a/models/oAuth2Amazon_test.go +++ b/models/oAuth2Amazon_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2AmazonModel(t *testing.T) { - model := OAuth2Amazon{ Id: "github", Enabled: true, ClientId: "amzn1.application-oa2-client.87400c00000000000000000000063d5b2", ClientSecret: "79ffe4000000000000000000000000000000000000000000000000000002de55", } + model := OAuth2Amazon{ Id: "github", Enabled: true, ClientId: "amzn1.application-oa2-client.87400c00000000000000000000063d5b2", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Auth0_test.go b/models/oAuth2Auth0_test.go index 07dada05..e1e4a358 100644 --- a/models/oAuth2Auth0_test.go +++ b/models/oAuth2Auth0_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2Auth0Model(t *testing.T) { - model := OAuth2Auth0{ Id: "github", Enabled: true, ClientId: "OaOkIA000000000000000000005KLSYq", ClientSecret: "zXz0000-00000000000000000000000000000-00000000000000000000PJafnF", Endpoint: "example.us.auth0.com", } + model := OAuth2Auth0{ Id: "github", Enabled: true, ClientId: "OaOkIA000000000000000000005KLSYq", ClientSecret: "<CLIENT_SECRET>", Endpoint: "example.us.auth0.com", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Authentik_test.go b/models/oAuth2Authentik_test.go index aeefaeec..ebd52806 100644 --- a/models/oAuth2Authentik_test.go +++ b/models/oAuth2Authentik_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2AuthentikModel(t *testing.T) { - model := OAuth2Authentik{ Id: "github", Enabled: true, ClientId: "dTKOPa0000000000000000000000000000e7G8hv", ClientSecret: "ntQadq000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000Hp5WK", Endpoint: "example.authentik.com", } + model := OAuth2Authentik{ Id: "github", Enabled: true, ClientId: "dTKOPa0000000000000000000000000000e7G8hv", ClientSecret: "<CLIENT_SECRET>", Endpoint: "example.authentik.com", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Autodesk_test.go b/models/oAuth2Autodesk_test.go index f8db242a..9a0cd5a0 100644 --- a/models/oAuth2Autodesk_test.go +++ b/models/oAuth2Autodesk_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2AutodeskModel(t *testing.T) { - model := OAuth2Autodesk{ Id: "github", Enabled: true, ClientId: "5zw90v00000000000000000000kVYXN7", ClientSecret: "7I000000000000MW", } + model := OAuth2Autodesk{ Id: "github", Enabled: true, ClientId: "5zw90v00000000000000000000kVYXN7", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Bitbucket_test.go b/models/oAuth2Bitbucket_test.go index 10af6b12..8e2575b4 100644 --- a/models/oAuth2Bitbucket_test.go +++ b/models/oAuth2Bitbucket_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2BitbucketModel(t *testing.T) { - model := OAuth2Bitbucket{ Id: "github", Enabled: true, Key: "Knt70000000000ByRc", Secret: "NMfLZJ00000000000000000000TLQdDx", } + model := OAuth2Bitbucket{ Id: "github", Enabled: true, Key: "Knt70000000000ByRc", Secret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Bitly_test.go b/models/oAuth2Bitly_test.go index 387a23e5..a15909f2 100644 --- a/models/oAuth2Bitly_test.go +++ b/models/oAuth2Bitly_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2BitlyModel(t *testing.T) { - model := OAuth2Bitly{ Id: "github", Enabled: true, ClientId: "d95151000000000000000000000000000067af9b", ClientSecret: "a13e250000000000000000000000000000d73095", } + model := OAuth2Bitly{ Id: "github", Enabled: true, ClientId: "d95151000000000000000000000000000067af9b", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Box_test.go b/models/oAuth2Box_test.go index 02ee9caf..89ba6b0d 100644 --- a/models/oAuth2Box_test.go +++ b/models/oAuth2Box_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2BoxModel(t *testing.T) { - model := OAuth2Box{ Id: "github", Enabled: true, ClientId: "deglcs00000000000000000000x2og6y", ClientSecret: "OKM1f100000000000000000000eshEif", } + model := OAuth2Box{ Id: "github", Enabled: true, ClientId: "deglcs00000000000000000000x2og6y", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Dailymotion_test.go b/models/oAuth2Dailymotion_test.go index f5852c72..260ad79f 100644 --- a/models/oAuth2Dailymotion_test.go +++ b/models/oAuth2Dailymotion_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2DailymotionModel(t *testing.T) { - model := OAuth2Dailymotion{ Id: "github", Enabled: true, ApiKey: "07a9000000000000067f", ApiSecret: "a399a90000000000000000000000000000d90639", } + model := OAuth2Dailymotion{ Id: "github", Enabled: true, ApiKey: "07a9000000000000067f", ApiSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Discord_test.go b/models/oAuth2Discord_test.go index d03aa3dd..7b93e066 100644 --- a/models/oAuth2Discord_test.go +++ b/models/oAuth2Discord_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2DiscordModel(t *testing.T) { - model := OAuth2Discord{ Id: "github", Enabled: true, ClientId: "950722000000343754", ClientSecret: "YmPXnM000000000000000000002zFg5D", } + model := OAuth2Discord{ Id: "github", Enabled: true, ClientId: "950722000000343754", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Disqus_test.go b/models/oAuth2Disqus_test.go index 74985cbc..71642c15 100644 --- a/models/oAuth2Disqus_test.go +++ b/models/oAuth2Disqus_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2DisqusModel(t *testing.T) { - model := OAuth2Disqus{ Id: "github", Enabled: true, PublicKey: "cgegH70000000000000000000000000000000000000000000000000000Hr1nYX", SecretKey: "W7Bykj00000000000000000000000000000000000000000000000000003o43w9", } + model := OAuth2Disqus{ Id: "github", Enabled: true, PublicKey: "cgegH70000000000000000000000000000000000000000000000000000Hr1nYX", SecretKey: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Dropbox_test.go b/models/oAuth2Dropbox_test.go index 44d4d794..6cadf0dd 100644 --- a/models/oAuth2Dropbox_test.go +++ b/models/oAuth2Dropbox_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2DropboxModel(t *testing.T) { - model := OAuth2Dropbox{ Id: "github", Enabled: true, AppKey: "jl000000000009t", AppSecret: "g200000000000vw", } + model := OAuth2Dropbox{ Id: "github", Enabled: true, AppKey: "jl000000000009t", AppSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Etsy_test.go b/models/oAuth2Etsy_test.go index e42ee6a1..af193b32 100644 --- a/models/oAuth2Etsy_test.go +++ b/models/oAuth2Etsy_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2EtsyModel(t *testing.T) { - model := OAuth2Etsy{ Id: "github", Enabled: true, KeyString: "nsgzxh0000000000008j85a2", SharedSecret: "tp000000ru", } + model := OAuth2Etsy{ Id: "github", Enabled: true, KeyString: "nsgzxh0000000000008j85a2", SharedSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Facebook_test.go b/models/oAuth2Facebook_test.go index b3d5476f..f50c9300 100644 --- a/models/oAuth2Facebook_test.go +++ b/models/oAuth2Facebook_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2FacebookModel(t *testing.T) { - model := OAuth2Facebook{ Id: "github", Enabled: true, AppId: "260600000007694", AppSecret: "2d0b2800000000000000000000d38af4", } + model := OAuth2Facebook{ Id: "github", Enabled: true, AppId: "260600000007694", AppSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Figma_test.go b/models/oAuth2Figma_test.go index 6765b0a3..611297f6 100644 --- a/models/oAuth2Figma_test.go +++ b/models/oAuth2Figma_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2FigmaModel(t *testing.T) { - model := OAuth2Figma{ Id: "github", Enabled: true, ClientId: "byay5H0000000000VtiI40", ClientSecret: "yEpOYn0000000000000000004iIsU5", } + model := OAuth2Figma{ Id: "github", Enabled: true, ClientId: "byay5H0000000000VtiI40", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2FusionAuth_test.go b/models/oAuth2FusionAuth_test.go index f4acd5a7..8b2a9a2b 100644 --- a/models/oAuth2FusionAuth_test.go +++ b/models/oAuth2FusionAuth_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2FusionAuthModel(t *testing.T) { - model := OAuth2FusionAuth{ Id: "github", Enabled: true, ClientId: "b2222c00-0000-0000-0000-000000862097", ClientSecret: "Jx4s0C0000000000000000000000000000000wGqLsc", Endpoint: "example.fusionauth.io", } + model := OAuth2FusionAuth{ Id: "github", Enabled: true, ClientId: "b2222c00-0000-0000-0000-000000862097", ClientSecret: "<CLIENT_SECRET>", Endpoint: "example.fusionauth.io", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Github_test.go b/models/oAuth2Github_test.go index d56c255d..01381a1c 100644 --- a/models/oAuth2Github_test.go +++ b/models/oAuth2Github_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2GithubModel(t *testing.T) { - model := OAuth2Github{ Id: "github", Enabled: true, ClientId: "e4d87900000000540733", ClientSecret: "5e07c00000000000000000000000000000198bcc", } + model := OAuth2Github{ Id: "github", Enabled: true, ClientId: "e4d87900000000540733", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Gitlab_test.go b/models/oAuth2Gitlab_test.go index 6e9c90c4..f3890745 100644 --- a/models/oAuth2Gitlab_test.go +++ b/models/oAuth2Gitlab_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2GitlabModel(t *testing.T) { - model := OAuth2Gitlab{ Id: "github", Enabled: true, ApplicationId: "d41ffe0000000000000000000000000000000000000000000000000000d5e252", Secret: "gloas-838cfa0000000000000000000000000000000000000000000000000000ecbb38", Endpoint: "https://gitlab.com", } + model := OAuth2Gitlab{ Id: "github", Enabled: true, ApplicationId: "d41ffe0000000000000000000000000000000000000000000000000000d5e252", Secret: "<CLIENT_SECRET>", Endpoint: "https://gitlab.com", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Google_test.go b/models/oAuth2Google_test.go index 87a36ad9..f4c3eac6 100644 --- a/models/oAuth2Google_test.go +++ b/models/oAuth2Google_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2GoogleModel(t *testing.T) { - model := OAuth2Google{ Id: "github", Enabled: true, ClientId: "your-google-client-id.apps.googleusercontent.com", ClientSecret: "your-google-client-secret", } + model := OAuth2Google{ Id: "github", Enabled: true, ClientId: "120000000095-92ifjb00000000000000000000g7ijfb.apps.googleusercontent.com", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Keycloak_test.go b/models/oAuth2Keycloak_test.go index 50ca7e79..2ab7a990 100644 --- a/models/oAuth2Keycloak_test.go +++ b/models/oAuth2Keycloak_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2KeycloakModel(t *testing.T) { - model := OAuth2Keycloak{ Id: "github", Enabled: true, ClientId: "appwrite-o0000000st-app", ClientSecret: "jdjrJd00000000000000000000HUsaZO", Endpoint: "keycloak.example.com", RealmName: "appwrite-realm", } + model := OAuth2Keycloak{ Id: "github", Enabled: true, ClientId: "appwrite-o0000000st-app", ClientSecret: "<CLIENT_SECRET>", Endpoint: "keycloak.example.com", RealmName: "appwrite-realm", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Kick_test.go b/models/oAuth2Kick_test.go index 33e96f41..4fce53eb 100644 --- a/models/oAuth2Kick_test.go +++ b/models/oAuth2Kick_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2KickModel(t *testing.T) { - model := OAuth2Kick{ Id: "github", Enabled: true, ClientId: "01KQ7C00000000000001MFHS32", ClientSecret: "34ac5600000000000000000000000000000000000000000000000000e830c8b", } + model := OAuth2Kick{ Id: "github", Enabled: true, ClientId: "01KQ7C00000000000001MFHS32", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Linkedin_test.go b/models/oAuth2Linkedin_test.go index a8f7ee21..f99daa22 100644 --- a/models/oAuth2Linkedin_test.go +++ b/models/oAuth2Linkedin_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2LinkedinModel(t *testing.T) { - model := OAuth2Linkedin{ Id: "github", Enabled: true, ClientId: "770000000000dv", PrimaryClientSecret: "your-linkedin-client-secret", } + model := OAuth2Linkedin{ Id: "github", Enabled: true, ClientId: "770000000000dv", PrimaryClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Microsoft_test.go b/models/oAuth2Microsoft_test.go index 188dee22..997e43a6 100644 --- a/models/oAuth2Microsoft_test.go +++ b/models/oAuth2Microsoft_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2MicrosoftModel(t *testing.T) { - model := OAuth2Microsoft{ Id: "github", Enabled: true, ApplicationId: "00001111-aaaa-2222-bbbb-3333cccc4444", ApplicationSecret: "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u", Tenant: "common", } + model := OAuth2Microsoft{ Id: "github", Enabled: true, ApplicationId: "00001111-aaaa-2222-bbbb-3333cccc4444", ApplicationSecret: "<CLIENT_SECRET>", Tenant: "common", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Notion_test.go b/models/oAuth2Notion_test.go index 37602278..ecef3cd2 100644 --- a/models/oAuth2Notion_test.go +++ b/models/oAuth2Notion_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2NotionModel(t *testing.T) { - model := OAuth2Notion{ Id: "github", Enabled: true, OauthClientId: "341d8700-0000-0000-0000-000000446ee3", OauthClientSecret: "secret_dLUr4b000000000000000000000000000000lFHAa9", } + model := OAuth2Notion{ Id: "github", Enabled: true, OauthClientId: "341d8700-0000-0000-0000-000000446ee3", OauthClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Oidc_test.go b/models/oAuth2Oidc_test.go index c9229d87..687ac977 100644 --- a/models/oAuth2Oidc_test.go +++ b/models/oAuth2Oidc_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2OidcModel(t *testing.T) { - model := OAuth2Oidc{ Id: "github", Enabled: true, ClientId: "qibI2x0000000000000000000000000006L2YFoG", ClientSecret: "Ah68ed000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003qpcHV", WellKnownURL: "https://myoauth.com/.well-known/openid-configuration", AuthorizationURL: "https://myoauth.com/oauth2/authorize", TokenURL: "https://myoauth.com/oauth2/token", UserInfoURL: "https://myoauth.com/oauth2/userinfo", } + model := OAuth2Oidc{ Id: "github", Enabled: true, ClientId: "qibI2x0000000000000000000000000006L2YFoG", ClientSecret: "<CLIENT_SECRET>", WellKnownURL: "https://myoauth.com/.well-known/openid-configuration", AuthorizationURL: "https://myoauth.com/oauth2/authorize", TokenURL: "https://myoauth.com/oauth2/token", UserInfoURL: "https://myoauth.com/oauth2/userinfo", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Okta_test.go b/models/oAuth2Okta_test.go index 46c5212d..cad9174e 100644 --- a/models/oAuth2Okta_test.go +++ b/models/oAuth2Okta_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2OktaModel(t *testing.T) { - model := OAuth2Okta{ Id: "github", Enabled: true, ClientId: "0oa00000000000000698", ClientSecret: "Kiq0000000000000000000000000000000000000-00000000000H2L5-3SJ-vRV", Domain: "trial-6400025.okta.com", AuthorizationServerId: "aus000000000000000h7z", } + model := OAuth2Okta{ Id: "github", Enabled: true, ClientId: "0oa00000000000000698", ClientSecret: "<CLIENT_SECRET>", Domain: "trial-6400025.okta.com", AuthorizationServerId: "aus000000000000000h7z", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Paypal_test.go b/models/oAuth2Paypal_test.go index b3826177..f1774bc0 100644 --- a/models/oAuth2Paypal_test.go +++ b/models/oAuth2Paypal_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2PaypalModel(t *testing.T) { - model := OAuth2Paypal{ Id: "github", Enabled: true, ClientId: "AdhIEG7-000000000000-0000000000000000000000000000000-0000000000000000000000-2pyB", SecretKey: "EH8KCXtew--000000000000000000000000000000000000000_C-1_5UP_000000000000000CB7KDp", } + model := OAuth2Paypal{ Id: "github", Enabled: true, ClientId: "AdhIEG7-000000000000-0000000000000000000000000000000-0000000000000000000000-2pyB", SecretKey: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Podio_test.go b/models/oAuth2Podio_test.go index 2b20d03d..2ba539f4 100644 --- a/models/oAuth2Podio_test.go +++ b/models/oAuth2Podio_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2PodioModel(t *testing.T) { - model := OAuth2Podio{ Id: "github", Enabled: true, ClientId: "appwrite-oauth-test-app", ClientSecret: "Rn247T0000000000000000000000000000000000000000000000000000W2zWTN", } + model := OAuth2Podio{ Id: "github", Enabled: true, ClientId: "appwrite-oauth-test-app", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Salesforce_test.go b/models/oAuth2Salesforce_test.go index 6f9c818f..31073f27 100644 --- a/models/oAuth2Salesforce_test.go +++ b/models/oAuth2Salesforce_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2SalesforceModel(t *testing.T) { - model := OAuth2Salesforce{ Id: "github", Enabled: true, CustomerKey: "3MVG9I0000000000000000000000000000000000000000000000000000000000000000000000000C5Aejq", CustomerSecret: "3w000000000000e2", } + model := OAuth2Salesforce{ Id: "github", Enabled: true, CustomerKey: "3MVG9I0000000000000000000000000000000000000000000000000000000000000000000000000C5Aejq", CustomerSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Slack_test.go b/models/oAuth2Slack_test.go index 417079dc..3b2ef17c 100644 --- a/models/oAuth2Slack_test.go +++ b/models/oAuth2Slack_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2SlackModel(t *testing.T) { - model := OAuth2Slack{ Id: "github", Enabled: true, ClientId: "23000000089.15000000000023", ClientSecret: "81656000000000000000000000f3d2fd", } + model := OAuth2Slack{ Id: "github", Enabled: true, ClientId: "23000000089.15000000000023", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Spotify_test.go b/models/oAuth2Spotify_test.go index 5c3ec029..1eea7d4d 100644 --- a/models/oAuth2Spotify_test.go +++ b/models/oAuth2Spotify_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2SpotifyModel(t *testing.T) { - model := OAuth2Spotify{ Id: "github", Enabled: true, ClientId: "6ec271000000000000000000009beace", ClientSecret: "db068a000000000000000000008b5b9f", } + model := OAuth2Spotify{ Id: "github", Enabled: true, ClientId: "6ec271000000000000000000009beace", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Stripe_test.go b/models/oAuth2Stripe_test.go index 3bda33de..9748ca73 100644 --- a/models/oAuth2Stripe_test.go +++ b/models/oAuth2Stripe_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2StripeModel(t *testing.T) { - model := OAuth2Stripe{ Id: "github", Enabled: true, ClientId: "ca_UKibXX0000000000000000000006byvR", ApiSecretKey: "sk_51SfOd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000QGWYfp", } + model := OAuth2Stripe{ Id: "github", Enabled: true, ClientId: "ca_UKibXX0000000000000000000006byvR", ApiSecretKey: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Tradeshift_test.go b/models/oAuth2Tradeshift_test.go index f7eec444..8c7bf91b 100644 --- a/models/oAuth2Tradeshift_test.go +++ b/models/oAuth2Tradeshift_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2TradeshiftModel(t *testing.T) { - model := OAuth2Tradeshift{ Id: "github", Enabled: true, Oauth2ClientId: "appwrite-test-org.appwrite-test-app", Oauth2ClientSecret: "7cb52700-0000-0000-0000-000000ca5b83", } + model := OAuth2Tradeshift{ Id: "github", Enabled: true, Oauth2ClientId: "appwrite-test-org.appwrite-test-app", Oauth2ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Twitch_test.go b/models/oAuth2Twitch_test.go index ba5c231b..80b0ab0b 100644 --- a/models/oAuth2Twitch_test.go +++ b/models/oAuth2Twitch_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2TwitchModel(t *testing.T) { - model := OAuth2Twitch{ Id: "github", Enabled: true, ClientId: "vvi0in000000000000000000ikmt9p", ClientSecret: "pmapue000000000000000000zylw3v", } + model := OAuth2Twitch{ Id: "github", Enabled: true, ClientId: "vvi0in000000000000000000ikmt9p", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2WordPress_test.go b/models/oAuth2WordPress_test.go index 726a697f..0a77c4f1 100644 --- a/models/oAuth2WordPress_test.go +++ b/models/oAuth2WordPress_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2WordPressModel(t *testing.T) { - model := OAuth2WordPress{ Id: "github", Enabled: true, ClientId: "130005", ClientSecret: "PlBfJS0000000000000000000000000000000000000000000000000000EdUZJk", } + model := OAuth2WordPress{ Id: "github", Enabled: true, ClientId: "130005", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2X_test.go b/models/oAuth2X_test.go index e8b68fc1..939a9d97 100644 --- a/models/oAuth2X_test.go +++ b/models/oAuth2X_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2XModel(t *testing.T) { - model := OAuth2X{ Id: "github", Enabled: true, CustomerKey: "slzZV0000000000000NFLaWT", SecretKey: "tkEPkp00000000000000000000000000000000000000FTxbI9", } + model := OAuth2X{ Id: "github", Enabled: true, CustomerKey: "slzZV0000000000000NFLaWT", SecretKey: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Yahoo_test.go b/models/oAuth2Yahoo_test.go index c0adc5e3..417159c6 100644 --- a/models/oAuth2Yahoo_test.go +++ b/models/oAuth2Yahoo_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2YahooModel(t *testing.T) { - model := OAuth2Yahoo{ Id: "github", Enabled: true, ClientId: "dj0yJm000000000000000000000000000000000000000000000000000000000000000000000000000000000000Z4PWRm", ClientSecret: "cf978f0000000000000000000000000000c5e2e9", } + model := OAuth2Yahoo{ Id: "github", Enabled: true, ClientId: "dj0yJm000000000000000000000000000000000000000000000000000000000000000000000000000000000000Z4PWRm", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Yandex_test.go b/models/oAuth2Yandex_test.go index a6e15a7a..5ba66f99 100644 --- a/models/oAuth2Yandex_test.go +++ b/models/oAuth2Yandex_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2YandexModel(t *testing.T) { - model := OAuth2Yandex{ Id: "github", Enabled: true, ClientId: "6a8a6a0000000000000000000091483c", ClientSecret: "bbf98500000000000000000000c75a63", } + model := OAuth2Yandex{ Id: "github", Enabled: true, ClientId: "6a8a6a0000000000000000000091483c", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Zoho_test.go b/models/oAuth2Zoho_test.go index 8265b406..7fac600b 100644 --- a/models/oAuth2Zoho_test.go +++ b/models/oAuth2Zoho_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2ZohoModel(t *testing.T) { - model := OAuth2Zoho{ Id: "github", Enabled: true, ClientId: "1000.83C178000000000000000000RPNX0B", ClientSecret: "fb5cac000000000000000000000000000000a68f6e", } + model := OAuth2Zoho{ Id: "github", Enabled: true, ClientId: "1000.83C178000000000000000000RPNX0B", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/models/oAuth2Zoom_test.go b/models/oAuth2Zoom_test.go index fe4b7e35..e91aa93f 100644 --- a/models/oAuth2Zoom_test.go +++ b/models/oAuth2Zoom_test.go @@ -6,7 +6,7 @@ import ( ) func TestOAuth2ZoomModel(t *testing.T) { - model := OAuth2Zoom{ Id: "github", Enabled: true, ClientId: "QMAC00000000000000w0AQ", ClientSecret: "GAWsG4000000000000000000007U01ON", } + model := OAuth2Zoom{ Id: "github", Enabled: true, ClientId: "QMAC00000000000000w0AQ", ClientSecret: "<CLIENT_SECRET>", } data, err := json.Marshal(model) if err != nil { diff --git a/project/project.go b/project/project.go index dc57708a..9b8215fb 100644 --- a/project/project.go +++ b/project/project.go @@ -706,571 +706,219 @@ func (srv *Project) ListOAuth2Providers(optionalSetters ...ListOAuth2ProvidersOp return &parsed, nil } +type UpdateOAuth2AmazonOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2AmazonOptions) New() *UpdateOAuth2AmazonOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2AmazonOption func(*UpdateOAuth2AmazonOptions) +func (srv *Project) WithUpdateOAuth2AmazonClientId(v string) UpdateOAuth2AmazonOption { + return func(o *UpdateOAuth2AmazonOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2AmazonClientSecret(v string) UpdateOAuth2AmazonOption { + return func(o *UpdateOAuth2AmazonOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2AmazonEnabled(v bool) UpdateOAuth2AmazonOption { + return func(o *UpdateOAuth2AmazonOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} -// GetOAuth2Provider get a single OAuth2 provider configuration. Credential -// fields (client secret, p8 file, key/team IDs) are write-only and always -// returned empty. -func (srv *Project) GetOAuth2Provider(ProviderId string)(models.Model, error) { - path := "/project/oauth2/:provider" +// UpdateOAuth2Amazon update the project OAuth2 Amazon configuration. +func (srv *Project) UpdateOAuth2Amazon(optionalSetters ...UpdateOAuth2AmazonOption)(*models.OAuth2Amazon, error) { + path := "/project/oauth2/amazon" + options := UpdateOAuth2AmazonOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } params := map[string]interface{}{} - params["providerId"] = ProviderId + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } headers := map[string]interface{}{ + "content-type": "application/json", } - resp, err := srv.client.Call("GET", path, headers, params) + resp, err := srv.client.Call("PATCH", path, headers, params) if err != nil { return nil, err } if strings.HasPrefix(resp.Type, "application/json") { bytes := []byte(resp.Result.(string)) - var response map[string]interface{} - if err := json.Unmarshal(bytes, &response); err != nil { - return nil, err - } - if fmt.Sprint(response["$id"]) == "github" { - parsed := models.OAuth2Github{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "discord" { - parsed := models.OAuth2Discord{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "figma" { - parsed := models.OAuth2Figma{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "dropbox" { - parsed := models.OAuth2Dropbox{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "dailymotion" { - parsed := models.OAuth2Dailymotion{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } + parsed := models.OAuth2Amazon{}.New(bytes) - return parsed, nil + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err } - if fmt.Sprint(response["$id"]) == "bitbucket" { - parsed := models.OAuth2Bitbucket{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "bitly" { - parsed := models.OAuth2Bitly{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } + return parsed, nil + } + var parsed models.OAuth2Amazon + parsed, ok := resp.Result.(models.OAuth2Amazon) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "box" { - parsed := models.OAuth2Box{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } +} +type UpdateOAuth2AppleOptions struct { + ServiceId string + KeyId string + TeamId string + P8File string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2AppleOptions) New() *UpdateOAuth2AppleOptions { + options.enabledSetters = map[string]bool{ + "ServiceId": false, + "KeyId": false, + "TeamId": false, + "P8File": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2AppleOption func(*UpdateOAuth2AppleOptions) +func (srv *Project) WithUpdateOAuth2AppleServiceId(v string) UpdateOAuth2AppleOption { + return func(o *UpdateOAuth2AppleOptions) { + o.ServiceId = v + o.enabledSetters["ServiceId"] = true + } +} +func (srv *Project) WithUpdateOAuth2AppleKeyId(v string) UpdateOAuth2AppleOption { + return func(o *UpdateOAuth2AppleOptions) { + o.KeyId = v + o.enabledSetters["KeyId"] = true + } +} +func (srv *Project) WithUpdateOAuth2AppleTeamId(v string) UpdateOAuth2AppleOption { + return func(o *UpdateOAuth2AppleOptions) { + o.TeamId = v + o.enabledSetters["TeamId"] = true + } +} +func (srv *Project) WithUpdateOAuth2AppleP8File(v string) UpdateOAuth2AppleOption { + return func(o *UpdateOAuth2AppleOptions) { + o.P8File = v + o.enabledSetters["P8File"] = true + } +} +func (srv *Project) WithUpdateOAuth2AppleEnabled(v bool) UpdateOAuth2AppleOption { + return func(o *UpdateOAuth2AppleOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Apple update the project OAuth2 Apple configuration. +func (srv *Project) UpdateOAuth2Apple(optionalSetters ...UpdateOAuth2AppleOption)(*models.OAuth2Apple, error) { + path := "/project/oauth2/apple" + options := UpdateOAuth2AppleOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ServiceId"] { + params["serviceId"] = options.ServiceId + } + if options.enabledSetters["KeyId"] { + params["keyId"] = options.KeyId + } + if options.enabledSetters["TeamId"] { + params["teamId"] = options.TeamId + } + if options.enabledSetters["P8File"] { + params["p8File"] = options.P8File + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "autodesk" { - parsed := models.OAuth2Autodesk{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "google" { - parsed := models.OAuth2Google{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } + parsed := models.OAuth2Apple{}.New(bytes) - return parsed, nil + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err } - if fmt.Sprint(response["$id"]) == "zoom" { - parsed := models.OAuth2Zoom{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "zoho" { - parsed := models.OAuth2Zoho{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "yandex" { - parsed := models.OAuth2Yandex{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "x" { - parsed := models.OAuth2X{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "wordpress" { - parsed := models.OAuth2WordPress{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "twitch" { - parsed := models.OAuth2Twitch{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "stripe" { - parsed := models.OAuth2Stripe{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "spotify" { - parsed := models.OAuth2Spotify{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "slack" { - parsed := models.OAuth2Slack{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "podio" { - parsed := models.OAuth2Podio{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "notion" { - parsed := models.OAuth2Notion{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "salesforce" { - parsed := models.OAuth2Salesforce{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "yahoo" { - parsed := models.OAuth2Yahoo{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "linkedin" { - parsed := models.OAuth2Linkedin{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "disqus" { - parsed := models.OAuth2Disqus{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "amazon" { - parsed := models.OAuth2Amazon{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "etsy" { - parsed := models.OAuth2Etsy{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "facebook" { - parsed := models.OAuth2Facebook{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "tradeshiftBox" { - parsed := models.OAuth2Tradeshift{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "paypalSandbox" { - parsed := models.OAuth2Paypal{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "gitlab" { - parsed := models.OAuth2Gitlab{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "authentik" { - parsed := models.OAuth2Authentik{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "auth0" { - parsed := models.OAuth2Auth0{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "fusionauth" { - parsed := models.OAuth2FusionAuth{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "keycloak" { - parsed := models.OAuth2Keycloak{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "oidc" { - parsed := models.OAuth2Oidc{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "apple" { - parsed := models.OAuth2Apple{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "okta" { - parsed := models.OAuth2Okta{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "kick" { - parsed := models.OAuth2Kick{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - if fmt.Sprint(response["$id"]) == "microsoft" { - parsed := models.OAuth2Microsoft{}.New(bytes) - if err := json.Unmarshal(bytes, parsed); err != nil { - return nil, err - } - - return parsed, nil - } - - return nil, errors.New("unable to match response to any expected response model") - } - parsed, ok := resp.Result.(models.Model) - if !ok { - return nil, errors.New("unexpected response type") - } - return parsed, nil + return parsed, nil + } + var parsed models.OAuth2Apple + parsed, ok := resp.Result.(models.OAuth2Apple) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil } -type UpdateOAuth2AmazonOptions struct { +type UpdateOAuth2Auth0Options struct { ClientId string ClientSecret string + Endpoint string Enabled bool enabledSetters map[string]bool } -func (options UpdateOAuth2AmazonOptions) New() *UpdateOAuth2AmazonOptions { +func (options UpdateOAuth2Auth0Options) New() *UpdateOAuth2Auth0Options { options.enabledSetters = map[string]bool{ "ClientId": false, "ClientSecret": false, + "Endpoint": false, "Enabled": false, } return &options } -type UpdateOAuth2AmazonOption func(*UpdateOAuth2AmazonOptions) -func (srv *Project) WithUpdateOAuth2AmazonClientId(v string) UpdateOAuth2AmazonOption { - return func(o *UpdateOAuth2AmazonOptions) { +type UpdateOAuth2Auth0Option func(*UpdateOAuth2Auth0Options) +func (srv *Project) WithUpdateOAuth2Auth0ClientId(v string) UpdateOAuth2Auth0Option { + return func(o *UpdateOAuth2Auth0Options) { o.ClientId = v o.enabledSetters["ClientId"] = true } } -func (srv *Project) WithUpdateOAuth2AmazonClientSecret(v string) UpdateOAuth2AmazonOption { - return func(o *UpdateOAuth2AmazonOptions) { +func (srv *Project) WithUpdateOAuth2Auth0ClientSecret(v string) UpdateOAuth2Auth0Option { + return func(o *UpdateOAuth2Auth0Options) { o.ClientSecret = v o.enabledSetters["ClientSecret"] = true } } -func (srv *Project) WithUpdateOAuth2AmazonEnabled(v bool) UpdateOAuth2AmazonOption { - return func(o *UpdateOAuth2AmazonOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// UpdateOAuth2Amazon update the project OAuth2 Amazon configuration. -func (srv *Project) UpdateOAuth2Amazon(optionalSetters ...UpdateOAuth2AmazonOption)(*models.OAuth2Amazon, error) { - path := "/project/oauth2/amazon" - options := UpdateOAuth2AmazonOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["ClientId"] { - params["clientId"] = options.ClientId - } - if options.enabledSetters["ClientSecret"] { - params["clientSecret"] = options.ClientSecret - } - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PATCH", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.OAuth2Amazon{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.OAuth2Amazon - parsed, ok := resp.Result.(models.OAuth2Amazon) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateOAuth2AppleOptions struct { - ServiceId string - KeyId string - TeamId string - P8File string - Enabled bool - enabledSetters map[string]bool -} -func (options UpdateOAuth2AppleOptions) New() *UpdateOAuth2AppleOptions { - options.enabledSetters = map[string]bool{ - "ServiceId": false, - "KeyId": false, - "TeamId": false, - "P8File": false, - "Enabled": false, - } - return &options -} -type UpdateOAuth2AppleOption func(*UpdateOAuth2AppleOptions) -func (srv *Project) WithUpdateOAuth2AppleServiceId(v string) UpdateOAuth2AppleOption { - return func(o *UpdateOAuth2AppleOptions) { - o.ServiceId = v - o.enabledSetters["ServiceId"] = true - } -} -func (srv *Project) WithUpdateOAuth2AppleKeyId(v string) UpdateOAuth2AppleOption { - return func(o *UpdateOAuth2AppleOptions) { - o.KeyId = v - o.enabledSetters["KeyId"] = true - } -} -func (srv *Project) WithUpdateOAuth2AppleTeamId(v string) UpdateOAuth2AppleOption { - return func(o *UpdateOAuth2AppleOptions) { - o.TeamId = v - o.enabledSetters["TeamId"] = true - } -} -func (srv *Project) WithUpdateOAuth2AppleP8File(v string) UpdateOAuth2AppleOption { - return func(o *UpdateOAuth2AppleOptions) { - o.P8File = v - o.enabledSetters["P8File"] = true - } -} -func (srv *Project) WithUpdateOAuth2AppleEnabled(v bool) UpdateOAuth2AppleOption { - return func(o *UpdateOAuth2AppleOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// UpdateOAuth2Apple update the project OAuth2 Apple configuration. -func (srv *Project) UpdateOAuth2Apple(optionalSetters ...UpdateOAuth2AppleOption)(*models.OAuth2Apple, error) { - path := "/project/oauth2/apple" - options := UpdateOAuth2AppleOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["ServiceId"] { - params["serviceId"] = options.ServiceId - } - if options.enabledSetters["KeyId"] { - params["keyId"] = options.KeyId - } - if options.enabledSetters["TeamId"] { - params["teamId"] = options.TeamId - } - if options.enabledSetters["P8File"] { - params["p8File"] = options.P8File - } - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } - - resp, err := srv.client.Call("PATCH", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) - - parsed := models.OAuth2Apple{}.New(bytes) - - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err - } - - return parsed, nil - } - var parsed models.OAuth2Apple - parsed, ok := resp.Result.(models.OAuth2Apple) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil - -} -type UpdateOAuth2Auth0Options struct { - ClientId string - ClientSecret string - Endpoint string - Enabled bool - enabledSetters map[string]bool -} -func (options UpdateOAuth2Auth0Options) New() *UpdateOAuth2Auth0Options { - options.enabledSetters = map[string]bool{ - "ClientId": false, - "ClientSecret": false, - "Endpoint": false, - "Enabled": false, - } - return &options -} -type UpdateOAuth2Auth0Option func(*UpdateOAuth2Auth0Options) -func (srv *Project) WithUpdateOAuth2Auth0ClientId(v string) UpdateOAuth2Auth0Option { - return func(o *UpdateOAuth2Auth0Options) { - o.ClientId = v - o.enabledSetters["ClientId"] = true - } -} -func (srv *Project) WithUpdateOAuth2Auth0ClientSecret(v string) UpdateOAuth2Auth0Option { - return func(o *UpdateOAuth2Auth0Options) { - o.ClientSecret = v - o.enabledSetters["ClientSecret"] = true - } -} -func (srv *Project) WithUpdateOAuth2Auth0Endpoint(v string) UpdateOAuth2Auth0Option { - return func(o *UpdateOAuth2Auth0Options) { - o.Endpoint = v - o.enabledSetters["Endpoint"] = true +func (srv *Project) WithUpdateOAuth2Auth0Endpoint(v string) UpdateOAuth2Auth0Option { + return func(o *UpdateOAuth2Auth0Options) { + o.Endpoint = v + o.enabledSetters["Endpoint"] = true } } func (srv *Project) WithUpdateOAuth2Auth0Enabled(v bool) UpdateOAuth2Auth0Option { @@ -4362,186 +4010,539 @@ func (srv *Project) UpdateOAuth2Yandex(optionalSetters ...UpdateOAuth2YandexOpti "content-type": "application/json", } - resp, err := srv.client.Call("PATCH", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Yandex{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Yandex + parsed, ok := resp.Result.(models.OAuth2Yandex) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2ZohoOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2ZohoOptions) New() *UpdateOAuth2ZohoOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2ZohoOption func(*UpdateOAuth2ZohoOptions) +func (srv *Project) WithUpdateOAuth2ZohoClientId(v string) UpdateOAuth2ZohoOption { + return func(o *UpdateOAuth2ZohoOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2ZohoClientSecret(v string) UpdateOAuth2ZohoOption { + return func(o *UpdateOAuth2ZohoOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2ZohoEnabled(v bool) UpdateOAuth2ZohoOption { + return func(o *UpdateOAuth2ZohoOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Zoho update the project OAuth2 Zoho configuration. +func (srv *Project) UpdateOAuth2Zoho(optionalSetters ...UpdateOAuth2ZohoOption)(*models.OAuth2Zoho, error) { + path := "/project/oauth2/zoho" + options := UpdateOAuth2ZohoOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Zoho{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Zoho + parsed, ok := resp.Result.(models.OAuth2Zoho) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} +type UpdateOAuth2ZoomOptions struct { + ClientId string + ClientSecret string + Enabled bool + enabledSetters map[string]bool +} +func (options UpdateOAuth2ZoomOptions) New() *UpdateOAuth2ZoomOptions { + options.enabledSetters = map[string]bool{ + "ClientId": false, + "ClientSecret": false, + "Enabled": false, + } + return &options +} +type UpdateOAuth2ZoomOption func(*UpdateOAuth2ZoomOptions) +func (srv *Project) WithUpdateOAuth2ZoomClientId(v string) UpdateOAuth2ZoomOption { + return func(o *UpdateOAuth2ZoomOptions) { + o.ClientId = v + o.enabledSetters["ClientId"] = true + } +} +func (srv *Project) WithUpdateOAuth2ZoomClientSecret(v string) UpdateOAuth2ZoomOption { + return func(o *UpdateOAuth2ZoomOptions) { + o.ClientSecret = v + o.enabledSetters["ClientSecret"] = true + } +} +func (srv *Project) WithUpdateOAuth2ZoomEnabled(v bool) UpdateOAuth2ZoomOption { + return func(o *UpdateOAuth2ZoomOptions) { + o.Enabled = v + o.enabledSetters["Enabled"] = true + } +} + +// UpdateOAuth2Zoom update the project OAuth2 Zoom configuration. +func (srv *Project) UpdateOAuth2Zoom(optionalSetters ...UpdateOAuth2ZoomOption)(*models.OAuth2Zoom, error) { + path := "/project/oauth2/zoom" + options := UpdateOAuth2ZoomOptions{}.New() + for _, opt := range optionalSetters { + opt(options) + } + params := map[string]interface{}{} + if options.enabledSetters["ClientId"] { + params["clientId"] = options.ClientId + } + if options.enabledSetters["ClientSecret"] { + params["clientSecret"] = options.ClientSecret + } + if options.enabledSetters["Enabled"] { + params["enabled"] = options.Enabled + } + headers := map[string]interface{}{ + "content-type": "application/json", + } + + resp, err := srv.client.Call("PATCH", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + parsed := models.OAuth2Zoom{}.New(bytes) + + err = json.Unmarshal(bytes, parsed) + if err != nil { + return nil, err + } + + return parsed, nil + } + var parsed models.OAuth2Zoom + parsed, ok := resp.Result.(models.OAuth2Zoom) + if !ok { + return nil, errors.New("unexpected response type") + } + return &parsed, nil + +} + +// GetOAuth2Provider get a single OAuth2 provider configuration. Credential +// fields (client secret, p8 file, key/team IDs) are write-only and always +// returned empty. +func (srv *Project) GetOAuth2Provider(ProviderId string)(models.Model, error) { + r := strings.NewReplacer("{providerId}", ProviderId) + path := r.Replace("/project/oauth2/{providerId}") + params := map[string]interface{}{} + params["providerId"] = ProviderId + headers := map[string]interface{}{ + } + + resp, err := srv.client.Call("GET", path, headers, params) + if err != nil { + return nil, err + } + if strings.HasPrefix(resp.Type, "application/json") { + bytes := []byte(resp.Result.(string)) + + var response map[string]interface{} + if err := json.Unmarshal(bytes, &response); err != nil { + return nil, err + } + if fmt.Sprint(response["$id"]) == "github" { + parsed := models.OAuth2Github{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "discord" { + parsed := models.OAuth2Discord{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "figma" { + parsed := models.OAuth2Figma{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "dropbox" { + parsed := models.OAuth2Dropbox{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "dailymotion" { + parsed := models.OAuth2Dailymotion{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "bitbucket" { + parsed := models.OAuth2Bitbucket{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "bitly" { + parsed := models.OAuth2Bitly{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "box" { + parsed := models.OAuth2Box{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "autodesk" { + parsed := models.OAuth2Autodesk{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "google" { + parsed := models.OAuth2Google{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "zoom" { + parsed := models.OAuth2Zoom{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "zoho" { + parsed := models.OAuth2Zoho{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "yandex" { + parsed := models.OAuth2Yandex{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "x" { + parsed := models.OAuth2X{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "wordpress" { + parsed := models.OAuth2WordPress{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "twitch" { + parsed := models.OAuth2Twitch{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "stripe" { + parsed := models.OAuth2Stripe{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "spotify" { + parsed := models.OAuth2Spotify{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "slack" { + parsed := models.OAuth2Slack{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "podio" { + parsed := models.OAuth2Podio{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "notion" { + parsed := models.OAuth2Notion{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "salesforce" { + parsed := models.OAuth2Salesforce{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "yahoo" { + parsed := models.OAuth2Yahoo{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "linkedin" { + parsed := models.OAuth2Linkedin{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "disqus" { + parsed := models.OAuth2Disqus{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "amazon" { + parsed := models.OAuth2Amazon{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "etsy" { + parsed := models.OAuth2Etsy{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } + + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "facebook" { + parsed := models.OAuth2Facebook{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - parsed := models.OAuth2Yandex{}.New(bytes) + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "tradeshiftBox" { + parsed := models.OAuth2Tradeshift{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err + return parsed, nil } + if fmt.Sprint(response["$id"]) == "paypalSandbox" { + parsed := models.OAuth2Paypal{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - return parsed, nil - } - var parsed models.OAuth2Yandex - parsed, ok := resp.Result.(models.OAuth2Yandex) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "gitlab" { + parsed := models.OAuth2Gitlab{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } -} -type UpdateOAuth2ZohoOptions struct { - ClientId string - ClientSecret string - Enabled bool - enabledSetters map[string]bool -} -func (options UpdateOAuth2ZohoOptions) New() *UpdateOAuth2ZohoOptions { - options.enabledSetters = map[string]bool{ - "ClientId": false, - "ClientSecret": false, - "Enabled": false, - } - return &options -} -type UpdateOAuth2ZohoOption func(*UpdateOAuth2ZohoOptions) -func (srv *Project) WithUpdateOAuth2ZohoClientId(v string) UpdateOAuth2ZohoOption { - return func(o *UpdateOAuth2ZohoOptions) { - o.ClientId = v - o.enabledSetters["ClientId"] = true - } -} -func (srv *Project) WithUpdateOAuth2ZohoClientSecret(v string) UpdateOAuth2ZohoOption { - return func(o *UpdateOAuth2ZohoOptions) { - o.ClientSecret = v - o.enabledSetters["ClientSecret"] = true - } -} -func (srv *Project) WithUpdateOAuth2ZohoEnabled(v bool) UpdateOAuth2ZohoOption { - return func(o *UpdateOAuth2ZohoOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// UpdateOAuth2Zoho update the project OAuth2 Zoho configuration. -func (srv *Project) UpdateOAuth2Zoho(optionalSetters ...UpdateOAuth2ZohoOption)(*models.OAuth2Zoho, error) { - path := "/project/oauth2/zoho" - options := UpdateOAuth2ZohoOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["ClientId"] { - params["clientId"] = options.ClientId - } - if options.enabledSetters["ClientSecret"] { - params["clientSecret"] = options.ClientSecret - } - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "authentik" { + parsed := models.OAuth2Authentik{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - resp, err := srv.client.Call("PATCH", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "auth0" { + parsed := models.OAuth2Auth0{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - parsed := models.OAuth2Zoho{}.New(bytes) + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "fusionauth" { + parsed := models.OAuth2FusionAuth{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err + return parsed, nil } + if fmt.Sprint(response["$id"]) == "keycloak" { + parsed := models.OAuth2Keycloak{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - return parsed, nil - } - var parsed models.OAuth2Zoho - parsed, ok := resp.Result.(models.OAuth2Zoho) - if !ok { - return nil, errors.New("unexpected response type") - } - return &parsed, nil + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "oidc" { + parsed := models.OAuth2Oidc{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } -} -type UpdateOAuth2ZoomOptions struct { - ClientId string - ClientSecret string - Enabled bool - enabledSetters map[string]bool -} -func (options UpdateOAuth2ZoomOptions) New() *UpdateOAuth2ZoomOptions { - options.enabledSetters = map[string]bool{ - "ClientId": false, - "ClientSecret": false, - "Enabled": false, - } - return &options -} -type UpdateOAuth2ZoomOption func(*UpdateOAuth2ZoomOptions) -func (srv *Project) WithUpdateOAuth2ZoomClientId(v string) UpdateOAuth2ZoomOption { - return func(o *UpdateOAuth2ZoomOptions) { - o.ClientId = v - o.enabledSetters["ClientId"] = true - } -} -func (srv *Project) WithUpdateOAuth2ZoomClientSecret(v string) UpdateOAuth2ZoomOption { - return func(o *UpdateOAuth2ZoomOptions) { - o.ClientSecret = v - o.enabledSetters["ClientSecret"] = true - } -} -func (srv *Project) WithUpdateOAuth2ZoomEnabled(v bool) UpdateOAuth2ZoomOption { - return func(o *UpdateOAuth2ZoomOptions) { - o.Enabled = v - o.enabledSetters["Enabled"] = true - } -} - -// UpdateOAuth2Zoom update the project OAuth2 Zoom configuration. -func (srv *Project) UpdateOAuth2Zoom(optionalSetters ...UpdateOAuth2ZoomOption)(*models.OAuth2Zoom, error) { - path := "/project/oauth2/zoom" - options := UpdateOAuth2ZoomOptions{}.New() - for _, opt := range optionalSetters { - opt(options) - } - params := map[string]interface{}{} - if options.enabledSetters["ClientId"] { - params["clientId"] = options.ClientId - } - if options.enabledSetters["ClientSecret"] { - params["clientSecret"] = options.ClientSecret - } - if options.enabledSetters["Enabled"] { - params["enabled"] = options.Enabled - } - headers := map[string]interface{}{ - "content-type": "application/json", - } + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "apple" { + parsed := models.OAuth2Apple{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - resp, err := srv.client.Call("PATCH", path, headers, params) - if err != nil { - return nil, err - } - if strings.HasPrefix(resp.Type, "application/json") { - bytes := []byte(resp.Result.(string)) + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "okta" { + parsed := models.OAuth2Okta{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - parsed := models.OAuth2Zoom{}.New(bytes) + return parsed, nil + } + if fmt.Sprint(response["$id"]) == "kick" { + parsed := models.OAuth2Kick{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - err = json.Unmarshal(bytes, parsed) - if err != nil { - return nil, err + return parsed, nil } + if fmt.Sprint(response["$id"]) == "microsoft" { + parsed := models.OAuth2Microsoft{}.New(bytes) + if err := json.Unmarshal(bytes, parsed); err != nil { + return nil, err + } - return parsed, nil + return parsed, nil + } + + return nil, errors.New("unable to match response to any expected response model") } - var parsed models.OAuth2Zoom - parsed, ok := resp.Result.(models.OAuth2Zoom) + parsed, ok := resp.Result.(models.Model) if !ok { return nil, errors.New("unexpected response type") } - return &parsed, nil + return parsed, nil } type ListPlatformsOptions struct { diff --git a/project/project_test.go b/project/project_test.go index f0fbb0eb..1f34f265 100644 --- a/project/project_test.go +++ b/project/project_test.go @@ -778,46 +778,13 @@ func TestProject(t *testing.T) { } }) - t.Run("Test GetOAuth2Provider", func(t *testing.T) { - mockResponse := ` -{ - "$id": "microsoft", - "enabled": true, - "applicationId": "00001111-aaaa-2222-bbbb-3333cccc4444", - "applicationSecret": "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u", - "tenant": "common" -} -` - - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - t.Errorf("Expected method GET, got %s", r.Method) - } - - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - _, _ = w.Write([]byte(mockResponse)) - })) - defer ts.Close() - - srv := New(newTestClient(ts)) - - response, err := srv.GetOAuth2Provider("amazon") - if err != nil { - t.Errorf("Method GetOAuth2Provider failed: %v", err) - } - if _, ok := response.(*models.OAuth2Microsoft); !ok { - t.Errorf("Expected response type *models.OAuth2Microsoft, got %T", response) - } - }) - t.Run("Test UpdateOAuth2Amazon", func(t *testing.T) { mockResponse := ` { "$id": "github", "enabled": true, "clientId": "amzn1.application-oa2-client.87400c00000000000000000000063d5b2", - "clientSecret": "79ffe4000000000000000000000000000000000000000000000000000002de55" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -877,7 +844,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "OaOkIA000000000000000000005KLSYq", - "clientSecret": "zXz0000-00000000000000000000000000000-00000000000000000000PJafnF", + "clientSecret": "<CLIENT_SECRET>", "endpoint": "example.us.auth0.com" } ` @@ -907,7 +874,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "dTKOPa0000000000000000000000000000e7G8hv", - "clientSecret": "ntQadq000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000Hp5WK", + "clientSecret": "<CLIENT_SECRET>", "endpoint": "example.authentik.com" } ` @@ -937,7 +904,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "5zw90v00000000000000000000kVYXN7", - "clientSecret": "7I000000000000MW" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -966,7 +933,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "key": "Knt70000000000ByRc", - "secret": "NMfLZJ00000000000000000000TLQdDx" + "secret": "<CLIENT_SECRET>" } ` @@ -995,7 +962,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "d95151000000000000000000000000000067af9b", - "clientSecret": "a13e250000000000000000000000000000d73095" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1024,7 +991,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "deglcs00000000000000000000x2og6y", - "clientSecret": "OKM1f100000000000000000000eshEif" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1053,7 +1020,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "apiKey": "07a9000000000000067f", - "apiSecret": "a399a90000000000000000000000000000d90639" + "apiSecret": "<CLIENT_SECRET>" } ` @@ -1082,7 +1049,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "950722000000343754", - "clientSecret": "YmPXnM000000000000000000002zFg5D" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1111,7 +1078,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "publicKey": "cgegH70000000000000000000000000000000000000000000000000000Hr1nYX", - "secretKey": "W7Bykj00000000000000000000000000000000000000000000000000003o43w9" + "secretKey": "<CLIENT_SECRET>" } ` @@ -1140,7 +1107,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "appKey": "jl000000000009t", - "appSecret": "g200000000000vw" + "appSecret": "<CLIENT_SECRET>" } ` @@ -1169,7 +1136,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "keyString": "nsgzxh0000000000008j85a2", - "sharedSecret": "tp000000ru" + "sharedSecret": "<CLIENT_SECRET>" } ` @@ -1198,7 +1165,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "appId": "260600000007694", - "appSecret": "2d0b2800000000000000000000d38af4" + "appSecret": "<CLIENT_SECRET>" } ` @@ -1227,7 +1194,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "byay5H0000000000VtiI40", - "clientSecret": "yEpOYn0000000000000000004iIsU5" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1256,7 +1223,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "b2222c00-0000-0000-0000-000000862097", - "clientSecret": "Jx4s0C0000000000000000000000000000000wGqLsc", + "clientSecret": "<CLIENT_SECRET>", "endpoint": "example.fusionauth.io" } ` @@ -1286,7 +1253,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "e4d87900000000540733", - "clientSecret": "5e07c00000000000000000000000000000198bcc" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1315,7 +1282,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "applicationId": "d41ffe0000000000000000000000000000000000000000000000000000d5e252", - "secret": "gloas-838cfa0000000000000000000000000000000000000000000000000000ecbb38", + "secret": "<CLIENT_SECRET>", "endpoint": "https://gitlab.com" } ` @@ -1344,8 +1311,8 @@ func TestProject(t *testing.T) { { "$id": "github", "enabled": true, - "clientId": "your-google-client-id.apps.googleusercontent.com", - "clientSecret": "your-google-client-secret" + "clientId": "120000000095-92ifjb00000000000000000000g7ijfb.apps.googleusercontent.com", + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1374,7 +1341,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "appwrite-o0000000st-app", - "clientSecret": "jdjrJd00000000000000000000HUsaZO", + "clientSecret": "<CLIENT_SECRET>", "endpoint": "keycloak.example.com", "realmName": "appwrite-realm" } @@ -1405,7 +1372,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "01KQ7C00000000000001MFHS32", - "clientSecret": "34ac5600000000000000000000000000000000000000000000000000e830c8b" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1434,7 +1401,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "770000000000dv", - "primaryClientSecret": "your-linkedin-client-secret" + "primaryClientSecret": "<CLIENT_SECRET>" } ` @@ -1463,7 +1430,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "applicationId": "00001111-aaaa-2222-bbbb-3333cccc4444", - "applicationSecret": "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u", + "applicationSecret": "<CLIENT_SECRET>", "tenant": "common" } ` @@ -1493,7 +1460,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "oauthClientId": "341d8700-0000-0000-0000-000000446ee3", - "oauthClientSecret": "secret_dLUr4b000000000000000000000000000000lFHAa9" + "oauthClientSecret": "<CLIENT_SECRET>" } ` @@ -1522,7 +1489,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "qibI2x0000000000000000000000000006L2YFoG", - "clientSecret": "Ah68ed000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003qpcHV", + "clientSecret": "<CLIENT_SECRET>", "wellKnownURL": "https://myoauth.com/.well-known/openid-configuration", "authorizationURL": "https://myoauth.com/oauth2/authorize", "tokenURL": "https://myoauth.com/oauth2/token", @@ -1555,7 +1522,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "0oa00000000000000698", - "clientSecret": "Kiq0000000000000000000000000000000000000-00000000000H2L5-3SJ-vRV", + "clientSecret": "<CLIENT_SECRET>", "domain": "trial-6400025.okta.com", "authorizationServerId": "aus000000000000000h7z" } @@ -1586,7 +1553,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "AdhIEG7-000000000000-0000000000000000000000000000000-0000000000000000000000-2pyB", - "secretKey": "EH8KCXtew--000000000000000000000000000000000000000_C-1_5UP_000000000000000CB7KDp" + "secretKey": "<CLIENT_SECRET>" } ` @@ -1615,7 +1582,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "AdhIEG7-000000000000-0000000000000000000000000000000-0000000000000000000000-2pyB", - "secretKey": "EH8KCXtew--000000000000000000000000000000000000000_C-1_5UP_000000000000000CB7KDp" + "secretKey": "<CLIENT_SECRET>" } ` @@ -1644,7 +1611,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "appwrite-oauth-test-app", - "clientSecret": "Rn247T0000000000000000000000000000000000000000000000000000W2zWTN" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1673,7 +1640,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "customerKey": "3MVG9I0000000000000000000000000000000000000000000000000000000000000000000000000C5Aejq", - "customerSecret": "3w000000000000e2" + "customerSecret": "<CLIENT_SECRET>" } ` @@ -1702,7 +1669,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "23000000089.15000000000023", - "clientSecret": "81656000000000000000000000f3d2fd" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1731,7 +1698,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "6ec271000000000000000000009beace", - "clientSecret": "db068a000000000000000000008b5b9f" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1760,7 +1727,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "ca_UKibXX0000000000000000000006byvR", - "apiSecretKey": "sk_51SfOd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000QGWYfp" + "apiSecretKey": "<CLIENT_SECRET>" } ` @@ -1789,7 +1756,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "oauth2ClientId": "appwrite-test-org.appwrite-test-app", - "oauth2ClientSecret": "7cb52700-0000-0000-0000-000000ca5b83" + "oauth2ClientSecret": "<CLIENT_SECRET>" } ` @@ -1818,7 +1785,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "oauth2ClientId": "appwrite-test-org.appwrite-test-app", - "oauth2ClientSecret": "7cb52700-0000-0000-0000-000000ca5b83" + "oauth2ClientSecret": "<CLIENT_SECRET>" } ` @@ -1847,7 +1814,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "vvi0in000000000000000000ikmt9p", - "clientSecret": "pmapue000000000000000000zylw3v" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1876,7 +1843,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "130005", - "clientSecret": "PlBfJS0000000000000000000000000000000000000000000000000000EdUZJk" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1905,7 +1872,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "customerKey": "slzZV0000000000000NFLaWT", - "secretKey": "tkEPkp00000000000000000000000000000000000000FTxbI9" + "secretKey": "<CLIENT_SECRET>" } ` @@ -1934,7 +1901,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "dj0yJm000000000000000000000000000000000000000000000000000000000000000000000000000000000000Z4PWRm", - "clientSecret": "cf978f0000000000000000000000000000c5e2e9" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1963,7 +1930,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "6a8a6a0000000000000000000091483c", - "clientSecret": "bbf98500000000000000000000c75a63" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -1992,7 +1959,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "1000.83C178000000000000000000RPNX0B", - "clientSecret": "fb5cac000000000000000000000000000000a68f6e" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -2021,7 +1988,7 @@ func TestProject(t *testing.T) { "$id": "github", "enabled": true, "clientId": "QMAC00000000000000w0AQ", - "clientSecret": "GAWsG4000000000000000000007U01ON" + "clientSecret": "<CLIENT_SECRET>" } ` @@ -2044,6 +2011,39 @@ func TestProject(t *testing.T) { } }) + t.Run("Test GetOAuth2Provider", func(t *testing.T) { + mockResponse := ` +{ + "$id": "microsoft", + "enabled": true, + "applicationId": "00001111-aaaa-2222-bbbb-3333cccc4444", + "applicationSecret": "<CLIENT_SECRET>", + "tenant": "common" +} +` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + t.Errorf("Expected method GET, got %s", r.Method) + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(mockResponse)) + })) + defer ts.Close() + + srv := New(newTestClient(ts)) + + response, err := srv.GetOAuth2Provider("amazon") + if err != nil { + t.Errorf("Method GetOAuth2Provider failed: %v", err) + } + if _, ok := response.(*models.OAuth2Microsoft); !ok { + t.Errorf("Expected response type *models.OAuth2Microsoft, got %T", response) + } + }) + t.Run("Test ListPlatforms", func(t *testing.T) { mockResponse := ` {