-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new
okta_trusted_origins
data source (#766)
- Loading branch information
1 parent
f6fcbdc
commit b4eac29
Showing
6 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "okta_trusted_origins" "test" { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resource "okta_trusted_origin" "testAcc_replace_with_uuid" { | ||
name = "testAcc-replace_with_uuid" | ||
active = false | ||
origin = "https://example2-replace_with_uuid.com" | ||
scopes = ["CORS", "REDIRECT"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package okta | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"hash/crc32" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/okta/okta-sdk-golang/v2/okta" | ||
"github.com/okta/okta-sdk-golang/v2/okta/query" | ||
) | ||
|
||
func dataSourceTrustedOrigins() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceTrustedOriginsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"filter": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Filter criteria. Filter value will be URL-encoded by the provider", | ||
}, | ||
"trusted_origins": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Unique identifier", | ||
}, | ||
"active": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Whether the Trusted Origin is active or not - can only be issued post-creation", | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Unique name for this trusted origin", | ||
}, | ||
"origin": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Unique origin URL for this trusted origin", | ||
}, | ||
"scopes": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Description: "Scopes of the Trusted Origin - can either be CORS or REDIRECT only", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceTrustedOriginsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
qp := &query.Params{Limit: defaultPaginationLimit} | ||
filter, ok := d.GetOk("filter") | ||
if ok { | ||
qp.Filter = filter.(string) | ||
} | ||
trustedOrigins, err := collectTrustedOrigins(ctx, getOktaClientFromMetadata(m), qp) | ||
if err != nil { | ||
return diag.Errorf("failed to trusted origins: %v", err) | ||
} | ||
d.SetId(fmt.Sprintf("%d", crc32.ChecksumIEEE([]byte(qp.String())))) | ||
arr := make([]map[string]interface{}, len(trustedOrigins)) | ||
for i := range trustedOrigins { | ||
scopes := make([]string, len(trustedOrigins[i].Scopes)) | ||
for j := range trustedOrigins[i].Scopes { | ||
scopes[j] = trustedOrigins[i].Scopes[j].Type | ||
} | ||
arr[i] = map[string]interface{}{ | ||
"id": trustedOrigins[i].Id, | ||
"active": trustedOrigins[i].Status == statusActive, | ||
"name": trustedOrigins[i].Name, | ||
"origin": trustedOrigins[i].Origin, | ||
"scopes": scopes, | ||
} | ||
} | ||
_ = d.Set("trusted_origins", arr) | ||
return nil | ||
} | ||
|
||
func collectTrustedOrigins(ctx context.Context, client *okta.Client, qp *query.Params) ([]*okta.TrustedOrigin, error) { | ||
trustedOrigins, resp, err := client.TrustedOrigin.ListOrigins(ctx, qp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for resp.HasNextPage() { | ||
var nextTrustedOrigins []*okta.TrustedOrigin | ||
resp, err = resp.Next(ctx, &nextTrustedOrigins) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for i := range nextTrustedOrigins { | ||
trustedOrigins = append(trustedOrigins, nextTrustedOrigins[i]) | ||
} | ||
} | ||
return trustedOrigins, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
layout: 'okta' | ||
page_title: 'Okta: okta_trusted_origins' | ||
sidebar_current: 'docs-okta-datasource-trusted-origins' | ||
description: |- | ||
Get List of Trusted Origins using filters. | ||
--- | ||
|
||
# okta_trusted_origins | ||
|
||
This resource allows you to retrieve a list of trusted origins from Okta. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "okta_trusted_origins" "all" { | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
- `filter` - (Optional) Filter criteria (will be URL-encoded by the provider). See [Filtering](https://developer.okta.com/docs/reference/core-okta-api/#filter) for more information on the expressions used in filtering. | ||
|
||
## Attributes Reference | ||
|
||
- `trusted_origins` | ||
- `id` - The ID of the Trusted Origin. | ||
- `active` - Whether the Trusted Origin is active or not - can only be issued post-creation | ||
- `name` - Unique name for this trusted origin. | ||
- `origin` - Unique origin URL for this trusted origin. | ||
- `scopes` - Scopes of the Trusted Origin |