Skip to content

Commit

Permalink
Add AU region code support (#358)
Browse files Browse the repository at this point in the history
* Add `AU` region code support

* changelogs

* testing updates

* update readme

* update workflow tests

* add warning for deprecated env var
  • Loading branch information
patrickcping authored Jun 5, 2024
1 parent 6afd3a9 commit c02bbb3
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/acceptance-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ jobs:
PINGONE_ENVIRONMENT_ID_TESTACC: ${{ secrets.EU_PINGONE_ENVIRONMENT_ID }}
# Dummy values follow to test the env var defaulting behaviours
PINGONE_REGION_TESTACC: Europe
PINGONE_REGION_CODE_TESTACC: EU
PINGONE_API_ACCESS_TOKEN: DummyAccessToken
PINGONE_API_SERVICE_HOSTNAME: api.ping-eng.com
PINGONE_AUTH_SERVICE_HOSTNAME: auth.ping-eng.com
PINGONE_CLIENT_ID: 7682a4d9-15d6-405a-9fd2-d9e08d3adfbe
PINGONE_CLIENT_SECRET: dummyclientsecret
PINGONE_ENVIRONMENT_ID: 7682a4d9-15d6-405a-9fd2-d9e08d3adfbe
PINGONE_REGION: AsiaPacific
PINGONE_REGION_CODE: AP

timeout-minutes: 15
strategy:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ jobs:
PINGONE_CLIENT_SECRET_TESTACC: ${{ secrets.EU_PINGONE_CLIENT_SECRET }}
PINGONE_ENVIRONMENT_ID_TESTACC: ${{ secrets.EU_PINGONE_ENVIRONMENT_ID }}
PINGONE_REGION_TESTACC: Europe
PINGONE_REGION_CODE_TESTACC: EU
PINGONE_API_ACCESS_TOKEN: testtest
PINGONE_API_SERVICE_HOSTNAME: api.ping-eng.com
PINGONE_AUTH_SERVICE_HOSTNAME: auth.ping-eng.com
PINGONE_CLIENT_ID: 9c052a8a-14be-44e4-8f07-2662569994ce
PINGONE_CLIENT_SECRET: testtesttest
PINGONE_ENVIRONMENT_ID: 9c052a8a-14be-44e4-8f07-2662569994ce
PINGONE_REGION: AsiaPacific
PINGONE_REGION_CODE: AP

timeout-minutes: 15
strategy:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* `github.com/patrickcping/pingone-go-sdk-v2` : v0.12.0
* **Note** Removal of retracted module `github.com/patrickcping/pingone-go-sdk-v2/agreementmanagement`. [#352](https://github.com/patrickcping/pingone-go-sdk-v2/pull/352)
* **Note** Deprecated the region name. Region codes should be used instead. [#358](https://github.com/patrickcping/pingone-go-sdk-v2/pull/358)
* `github.com/patrickcping/pingone-go-sdk-v2/agreementmanagement` : [v0.3.2](./agreementmanagement/CHANGELOG.md)
* **MODULE RETRACTION** The API endpoint in this module suffers major loss of function. The module has been retracted but is retained in the source repo for the purpose of retration. [#352](https://github.com/patrickcping/pingone-go-sdk-v2/pull/352)
* `github.com/patrickcping/pingone-go-sdk-v2/authorize` : [v0.5.0](./authorize/CHANGELOG.md)
Expand Down Expand Up @@ -29,6 +30,7 @@
* **Enhancement** Added the `DeletePreviousResourceSecret` function to control resource secret rotation. [#347](https://github.com/patrickcping/pingone-go-sdk-v2/pull/347)
* **Enhancement** Added `Previous` to the `ResourceSecret` model to control resource secret rotation. [#347](https://github.com/patrickcping/pingone-go-sdk-v2/pull/347)
* **Enhancement** Add the `com.au` top level domain to the connection configuration. [#351](https://github.com/patrickcping/pingone-go-sdk-v2/pull/351)
* **Enhancement** Add the `AU` region code to the `EnumRegionCode` model. [#358](https://github.com/patrickcping/pingone-go-sdk-v2/pull/358)
* `github.com/patrickcping/pingone-go-sdk-v2/mfa` : [v0.19.0](./mfa/CHANGELOG.md)
* **Breaking change** Remove optional `DeviceAuthenticationPolicyMobileOtpWindow` from `DeviceAuthenticationPolicyMobileOtp` constructor. [#343](https://github.com/patrickcping/pingone-go-sdk-v2/pull/343)
* **Enhancement** Added `PromptForNicknameOnPairing` boolean field to the `DeviceAuthenticationPolicyFido2`, `DeviceAuthenticationPolicyMobile`, `DeviceAuthenticationPolicyOfflineDevice` and `DeviceAuthenticationPolicyTotp` models. [#349](https://github.com/patrickcping/pingone-go-sdk-v2/pull/349)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ config := &pingone.Config{
ClientSecret: clientSecret,
EnvironmentID: environmentId,
AccessToken: accessToken,
Region: region,
RegionCode: regionCode,
}

client, err := config.APIClient(ctx)
Expand All @@ -55,9 +55,9 @@ The result is an object with clients initialised for each service:
* `client.RiskAPIClient`
* `client.VerifyAPIClient`

In the above, if an `AccessToken` is provided, this will be verified and used. If the `AccessToken` is not provided, the SDK will retrieve an access token from the provided `ClientID`, `ClientSecret`, `EnvironmentID` and `Region` parameters.
In the above, if an `AccessToken` is provided, this will be verified and used. If the `AccessToken` is not provided, the SDK will retrieve an access token from the provided `ClientID`, `ClientSecret`, `EnvironmentID` and `RegionCode` parameters.

The client SDK defaults to production hostnames, and the `Region` is used to add the relevant suffix to the hostname. For example, `Europe` as a `Region` value with suffix the service hostname with `.eu`. Hostnames can be overridden with the optional `APIHostnameOverride`, and `AuthHostnameOverride` parameters.
The client SDK defaults to production hostnames, and the `RegionCode` is used to add the relevant suffix to the hostname. For example, `EU` as a `RegionCode` value with suffix the service hostname with `.eu`. Hostnames can be overridden with the optional `APIHostnameOverride`, and `AuthHostnameOverride` parameters.

An API call can be made against the API objects, as in the following example to get all environments in a tenant:

Expand Down
1 change: 1 addition & 0 deletions management/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* **Enhancement** Added the `DeletePreviousResourceSecret` function to control resource secret rotation. [#347](https://github.com/patrickcping/pingone-go-sdk-v2/pull/347)
* **Enhancement** Added `Previous` to the `ResourceSecret` model to control resource secret rotation. [#347](https://github.com/patrickcping/pingone-go-sdk-v2/pull/347)
* **Enhancement** Add the `com.au` top level domain to the connection configuration. [#351](https://github.com/patrickcping/pingone-go-sdk-v2/pull/351)
* **Enhancement** Add the `AU` region code to the `EnumRegionCode` model. [#358](https://github.com/patrickcping/pingone-go-sdk-v2/pull/358)

# v0.39.0 (2024-05-01)

Expand Down
1 change: 1 addition & 0 deletions management/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27195,6 +27195,7 @@ components:
is set when the environment is created and cannot be updated.
enum:
- AP
- AU
- CA
- EU
- NA
Expand Down
2 changes: 2 additions & 0 deletions management/docs/EnumRegionCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

* `AP` (value: `"AP"`)

* `AU` (value: `"AU"`)

* `CA` (value: `"CA"`)

* `EU` (value: `"EU"`)
Expand Down
2 changes: 1 addition & 1 deletion management/generate/pingone-management.yml
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ components:
default: JWT Bearer Token
EnumRegionCode:
type: string
enum: [AP, CA, EU, NA]
enum: [AP, AU, CA, EU, NA]
description: A string that specifies the environment region code. The value is set when the environment is created and cannot be updated.
EnumRegionCodeLicense:
type: string
Expand Down
2 changes: 2 additions & 0 deletions management/model_enum_region_code.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 87 additions & 9 deletions pingone/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,23 @@ func (c *Config) APIClient(ctx context.Context) (*Client, error) {
return nil, err
}

var region model.RegionMapping
if c.Region != "" {
region = model.FindRegionByName(c.Region) //nolint:staticcheck
}

if v := c.RegionCode; v != nil {
region = model.FindRegionByAPICode(*v)
}

apiClient := &Client{
AuthorizeAPIClient: authorizeClient,
CredentialsAPIClient: credentialsClient,
ManagementAPIClient: managementClient,
MFAAPIClient: mfaClient,
RiskAPIClient: riskClient,
VerifyAPIClient: verifyClient,
Region: model.FindRegionByName(c.Region),
Region: region,
}

return apiClient, nil
Expand Down Expand Up @@ -120,7 +129,17 @@ func (c *Config) AuthorizeAPIClient(ctx context.Context) (*authorize.APIClient,
}
} else {
clientcfg.SetDefaultServerIndex(0)
err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", model.FindRegionByName(c.Region).URLSuffix)

var region model.RegionMapping
if c.Region != "" {
region = model.FindRegionByName(c.Region) //nolint:staticcheck
}

if v := c.RegionCode; v != nil {
region = model.FindRegionByAPICode(*v)
}

err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", region.URLSuffix)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -193,7 +212,17 @@ func (c *Config) CredentialsAPIClient(ctx context.Context) (*credentials.APIClie
}
} else {
clientcfg.SetDefaultServerIndex(0)
err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", model.FindRegionByName(c.Region).URLSuffix)

var region model.RegionMapping
if c.Region != "" {
region = model.FindRegionByName(c.Region) //nolint:staticcheck
}

if v := c.RegionCode; v != nil {
region = model.FindRegionByAPICode(*v)
}

err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", region.URLSuffix)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -265,7 +294,17 @@ func (c *Config) ManagementAPIClient(ctx context.Context) (*management.APIClient
}
} else {
clientcfg.SetDefaultServerIndex(0)
err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", model.FindRegionByName(c.Region).URLSuffix)

var region model.RegionMapping
if c.Region != "" {
region = model.FindRegionByName(c.Region) //nolint:staticcheck
}

if v := c.RegionCode; v != nil {
region = model.FindRegionByAPICode(*v)
}

err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", region.URLSuffix)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -337,7 +376,17 @@ func (c *Config) MFAAPIClient(ctx context.Context) (*mfa.APIClient, error) {
}
} else {
clientcfg.SetDefaultServerIndex(0)
err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", model.FindRegionByName(c.Region).URLSuffix)

var region model.RegionMapping
if c.Region != "" {
region = model.FindRegionByName(c.Region) //nolint:staticcheck
}

if v := c.RegionCode; v != nil {
region = model.FindRegionByAPICode(*v)
}

err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", region.URLSuffix)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -409,7 +458,17 @@ func (c *Config) RiskAPIClient(ctx context.Context) (*risk.APIClient, error) {
}
} else {
clientcfg.SetDefaultServerIndex(0)
err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", model.FindRegionByName(c.Region).URLSuffix)

var region model.RegionMapping
if c.Region != "" {
region = model.FindRegionByName(c.Region) //nolint:staticcheck
}

if v := c.RegionCode; v != nil {
region = model.FindRegionByAPICode(*v)
}

err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", region.URLSuffix)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -481,7 +540,17 @@ func (c *Config) VerifyAPIClient(ctx context.Context) (*verify.APIClient, error)
}
} else {
clientcfg.SetDefaultServerIndex(0)
err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", model.FindRegionByName(c.Region).URLSuffix)

var region model.RegionMapping
if c.Region != "" {
region = model.FindRegionByName(c.Region) //nolint:staticcheck
}

if v := c.RegionCode; v != nil {
region = model.FindRegionByAPICode(*v)
}

err := clientcfg.SetDefaultServerVariableDefaultValue("suffix", region.URLSuffix)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -514,11 +583,20 @@ func (c *Config) getToken(ctx context.Context) error {

if !checkForValue(c.AccessToken) {

if !checkForValue(c.ClientID) || !checkForValue(c.ClientSecret) || !checkForValue(c.EnvironmentID) || !checkForValue(c.Region) {
if !checkForValue(c.ClientID) || !checkForValue(c.ClientSecret) || !checkForValue(c.EnvironmentID) || (!checkForValue(c.Region) && !checkForValue(c.RegionCode)) {
return fmt.Errorf("Required parameter missing. Must provide ClientID, ClientSecret, EnvironmentID and Region.")
}

regionSuffix := model.FindRegionByName(c.Region).URLSuffix
var region model.RegionMapping
if c.Region != "" {
region = model.FindRegionByName(c.Region) //nolint:staticcheck
}

if v := c.RegionCode; v != nil {
region = model.FindRegionByAPICode(*v)
}

regionSuffix := region.URLSuffix

//Get URL from SDK
authURL := fmt.Sprintf("https://auth.pingone.%s", regionSuffix)
Expand Down
Loading

0 comments on commit c02bbb3

Please sign in to comment.