Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15/X] DXCDT-441: Reintroduce support for sap api client addon #671

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/data-sources/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Read-Only:
- `salesforce` (List of Object) (see [below for nested schema](#nestedobjatt--addons--salesforce))
- `salesforce_api` (List of Object) (see [below for nested schema](#nestedobjatt--addons--salesforce_api))
- `salesforce_sandbox_api` (List of Object) (see [below for nested schema](#nestedobjatt--addons--salesforce_sandbox_api))
- `sap_api` (List of Object) (see [below for nested schema](#nestedobjatt--addons--sap_api))
- `sentry` (List of Object) (see [below for nested schema](#nestedobjatt--addons--sentry))
- `slack` (List of Object) (see [below for nested schema](#nestedobjatt--addons--slack))

Expand Down Expand Up @@ -235,6 +236,19 @@ Read-Only:
- `principal` (String)


<a id="nestedobjatt--addons--sap_api"></a>
### Nested Schema for `addons.sap_api`

Read-Only:

- `client_id` (String)
- `name_identifier_format` (String)
- `scope` (String)
- `service_password` (String)
- `token_endpoint_url` (String)
- `username_attribute` (String)


<a id="nestedobjatt--addons--sentry"></a>
### Nested Schema for `addons.sentry`

Expand Down
14 changes: 14 additions & 0 deletions docs/data-sources/global_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Read-Only:
- `salesforce` (List of Object) (see [below for nested schema](#nestedobjatt--addons--salesforce))
- `salesforce_api` (List of Object) (see [below for nested schema](#nestedobjatt--addons--salesforce_api))
- `salesforce_sandbox_api` (List of Object) (see [below for nested schema](#nestedobjatt--addons--salesforce_sandbox_api))
- `sap_api` (List of Object) (see [below for nested schema](#nestedobjatt--addons--sap_api))
- `sentry` (List of Object) (see [below for nested schema](#nestedobjatt--addons--sentry))
- `slack` (List of Object) (see [below for nested schema](#nestedobjatt--addons--slack))

Expand Down Expand Up @@ -224,6 +225,19 @@ Read-Only:
- `principal` (String)


<a id="nestedobjatt--addons--sap_api"></a>
### Nested Schema for `addons.sap_api`

Read-Only:

- `client_id` (String)
- `name_identifier_format` (String)
- `scope` (String)
- `service_password` (String)
- `token_endpoint_url` (String)
- `username_attribute` (String)


<a id="nestedobjatt--addons--sentry"></a>
### Nested Schema for `addons.sentry`

Expand Down
14 changes: 14 additions & 0 deletions docs/resources/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Optional:
- `salesforce` (Block List, Max: 1) Salesforce SSO configuration. (see [below for nested schema](#nestedblock--addons--salesforce))
- `salesforce_api` (Block List, Max: 1) Salesforce API addon configuration. (see [below for nested schema](#nestedblock--addons--salesforce_api))
- `salesforce_sandbox_api` (Block List, Max: 1) Salesforce Sandbox addon configuration. (see [below for nested schema](#nestedblock--addons--salesforce_sandbox_api))
- `sap_api` (Block List, Max: 1) SAP API addon configuration. (see [below for nested schema](#nestedblock--addons--sap_api))
- `sentry` (Block List, Max: 1) Sentry SSO configuration. (see [below for nested schema](#nestedblock--addons--sentry))
- `slack` (Block List, Max: 1) Slack team or workspace name usually first segment in your Slack URL, for example `https://acme-org.slack.com` would be `acme-org`. (see [below for nested schema](#nestedblock--addons--slack))

Expand Down Expand Up @@ -300,6 +301,19 @@ Optional:
- `principal` (String, Sensitive) Name of the property in the user object that maps to a Salesforce username, for example `email`.


<a id="nestedblock--addons--sap_api"></a>
### Nested Schema for `addons.sap_api`

Optional:

- `client_id` (String) If activated in the OAuth 2.0 client configuration (transaction `SOAUTH2) the SAML attribute `client_id` must be set and equal the `client_id` form parameter of the access token request.
- `name_identifier_format` (String) NameID element of the Subject which can be used to express the user's identity. Defaults to `urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified`.
- `scope` (String) Requested scope for SAP APIs.
- `service_password` (String, Sensitive) Service account password to use to authenticate API calls to the token endpoint.
- `token_endpoint_url` (String) The OAuth2 token endpoint URL of your SAP OData server.
- `username_attribute` (String) Name of the property in the user object that maps to a SAP username, for example `email`.


<a id="nestedblock--addons--sentry"></a>
### Nested Schema for `addons.sentry`

Expand Down
14 changes: 14 additions & 0 deletions docs/resources/global_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Optional:
- `salesforce` (Block List, Max: 1) Salesforce SSO configuration. (see [below for nested schema](#nestedblock--addons--salesforce))
- `salesforce_api` (Block List, Max: 1) Salesforce API addon configuration. (see [below for nested schema](#nestedblock--addons--salesforce_api))
- `salesforce_sandbox_api` (Block List, Max: 1) Salesforce Sandbox addon configuration. (see [below for nested schema](#nestedblock--addons--salesforce_sandbox_api))
- `sap_api` (Block List, Max: 1) SAP API addon configuration. (see [below for nested schema](#nestedblock--addons--sap_api))
- `sentry` (Block List, Max: 1) Sentry SSO configuration. (see [below for nested schema](#nestedblock--addons--sentry))
- `slack` (Block List, Max: 1) Slack team or workspace name usually first segment in your Slack URL, for example `https://acme-org.slack.com` would be `acme-org`. (see [below for nested schema](#nestedblock--addons--slack))

Expand Down Expand Up @@ -243,6 +244,19 @@ Optional:
- `principal` (String, Sensitive) Name of the property in the user object that maps to a Salesforce username, for example `email`.


<a id="nestedblock--addons--sap_api"></a>
### Nested Schema for `addons.sap_api`

Optional:

- `client_id` (String) If activated in the OAuth 2.0 client configuration (transaction `SOAUTH2) the SAML attribute `client_id` must be set and equal the `client_id` form parameter of the access token request.
- `name_identifier_format` (String) NameID element of the Subject which can be used to express the user's identity. Defaults to `urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified`.
- `scope` (String) Requested scope for SAP APIs.
- `service_password` (String, Sensitive) Service account password to use to authenticate API calls to the token endpoint.
- `token_endpoint_url` (String) The OAuth2 token endpoint URL of your SAP OData server.
- `username_attribute` (String) Name of the property in the user object that maps to a SAP username, for example `email`.


<a id="nestedblock--addons--sentry"></a>
### Nested Schema for `addons.sentry`

Expand Down
20 changes: 20 additions & 0 deletions internal/auth0/client/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func expandClientAddons(d *schema.ResourceData) *management.ClientAddons {
addons.SalesforceAPI = expandClientAddonSalesforceAPI(addonsCfg.GetAttr("salesforce_api"))
addons.SalesforceSandboxAPI = expandClientAddonSalesforceSandboxAPI(addonsCfg.GetAttr("salesforce_sandbox_api"))
addons.Layer = expandClientAddonLayer(addonsCfg.GetAttr("layer"))
addons.SAPAPI = expandClientAddonSAPAPI(addonsCfg.GetAttr("sap_api"))
return stop
})

Expand Down Expand Up @@ -544,6 +545,25 @@ func expandClientAddonLayer(layerCfg cty.Value) *management.LayerClientAddon {
return &layerAddon
}

func expandClientAddonSAPAPI(sapAPICfg cty.Value) *management.SAPAPIClientAddon {
var sapAPIAddon management.SAPAPIClientAddon

sapAPICfg.ForEachElement(func(_ cty.Value, sapAPICfg cty.Value) (stop bool) {
sapAPIAddon = management.SAPAPIClientAddon{
ClientID: value.String(sapAPICfg.GetAttr("client_id")),
UsernameAttribute: value.String(sapAPICfg.GetAttr("username_attribute")),
TokenEndpointURL: value.String(sapAPICfg.GetAttr("token_endpoint_url")),
Scope: value.String(sapAPICfg.GetAttr("scope")),
ServicePassword: value.String(sapAPICfg.GetAttr("service_password")),
NameIdentifierFormat: value.String(sapAPICfg.GetAttr("name_identifier_format")),
}

return stop
})

return &sapAPIAddon
}

func clientHasChange(c *management.Client) bool {
return c.String() != "{}"
}
14 changes: 14 additions & 0 deletions internal/auth0/client/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func flattenClientAddons(addons *management.ClientAddons) []interface{} {
"salesforce_api": nil,
"salesforce_sandbox_api": nil,
"layer": nil,
"sap_api": nil,
}

if addons.GetAWS() != nil {
Expand Down Expand Up @@ -274,5 +275,18 @@ func flattenClientAddons(addons *management.ClientAddons) []interface{} {
}
}

if addons.GetSAPAPI() != nil {
m["sap_api"] = []interface{}{
map[string]interface{}{
"client_id": addons.GetSAPAPI().GetClientID(),
"username_attribute": addons.GetSAPAPI().GetUsernameAttribute(),
"token_endpoint_url": addons.GetSAPAPI().GetTokenEndpointURL(),
"scope": addons.GetSAPAPI().GetScope(),
"service_password": addons.GetSAPAPI().GetServicePassword(),
"name_identifier_format": addons.GetSAPAPI().GetNameIdentifierFormat(),
},
}
}

return []interface{}{m}
}
46 changes: 46 additions & 0 deletions internal/auth0/client/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,52 @@ func NewResource() *schema.Resource {
},
},
},
"sap_api": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Description: "SAP API addon configuration.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"client_id": {
Description: "If activated in the OAuth 2.0 client configuration (transaction `SOAUTH2) " +
"the SAML attribute `client_id` must be set and equal the `client_id` form " +
"parameter of the access token request.",
Type: schema.TypeString,
Optional: true,
},
"username_attribute": {
Description: "Name of the property in the user object that maps to a SAP username, for example `email`.",
Type: schema.TypeString,
Optional: true,
},
"token_endpoint_url": {
Description: "The OAuth2 token endpoint URL of your SAP OData server.",
Type: schema.TypeString,
Optional: true,
ValidateFunc: internalValidation.IsURLWithHTTPSorEmptyString,
},
"scope": {
Description: "Requested scope for SAP APIs.",
Type: schema.TypeString,
Optional: true,
},
"service_password": {
Description: "Service account password to use to authenticate API calls to the token endpoint.",
Type: schema.TypeString,
Optional: true,
Sensitive: true,
},
"name_identifier_format": {
Description: "NameID element of the Subject which can be used to express the user's identity. " +
"Defaults to `urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified`.",
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
},
},
Expand Down
32 changes: 32 additions & 0 deletions internal/auth0/client/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,24 @@ resource "auth0_client" "my_client" {
}
`

const testAccUpdateClientWithAddonsSAPAPI = `
resource "auth0_client" "my_client" {
name = "Acceptance Test - SSO Integration - {{.testName}}"
app_type = "sso_integration"

addons {
sap_api {
client_id = "client-id"
username_attribute = "email"
token_endpoint_url = "https://example.com"
scope = "use:api"
service_password = "123456"
name_identifier_format = "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"
}
}
}
`

func TestAccClientAddons(t *testing.T) {
acctest.Test(t, resource.TestCase{
Steps: []resource.TestStep{
Expand Down Expand Up @@ -1128,6 +1146,20 @@ func TestAccClientAddons(t *testing.T) {
resource.TestCheckResourceAttr("auth0_client.my_client", "addons.0.layer.0.expiration", "10"),
),
},
{
Config: acctest.ParseTestName(testAccUpdateClientWithAddonsSAPAPI, t.Name()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_client.my_client", "name", fmt.Sprintf("Acceptance Test - SSO Integration - %s", t.Name())),
resource.TestCheckResourceAttr("auth0_client.my_client", "app_type", "sso_integration"),
resource.TestCheckResourceAttr("auth0_client.my_client", "addons.#", "1"),
resource.TestCheckResourceAttr("auth0_client.my_client", "addons.0.sap_api.0.client_id", "client-id"),
resource.TestCheckResourceAttr("auth0_client.my_client", "addons.0.sap_api.0.username_attribute", "email"),
resource.TestCheckResourceAttr("auth0_client.my_client", "addons.0.sap_api.0.token_endpoint_url", "https://example.com"),
resource.TestCheckResourceAttr("auth0_client.my_client", "addons.0.sap_api.0.scope", "use:api"),
resource.TestCheckResourceAttr("auth0_client.my_client", "addons.0.sap_api.0.service_password", "123456"),
resource.TestCheckResourceAttr("auth0_client.my_client", "addons.0.sap_api.0.name_identifier_format", "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"),
),
},
},
})
}
Expand Down
Loading