Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Fix bug around app include/exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumew committed Aug 22, 2019
1 parent 5969771 commit 92572d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
15 changes: 8 additions & 7 deletions okta/resource_policy_rule_idp_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ func buildAppConditions(d *schema.ResourceData) *sdk.IdpDiscoveryRuleApp {
}

excludeList := []*sdk.IdpDiscoveryRuleAppObj{}

if v, ok := d.GetOk("app_exclude"); ok {
valueList := v.(*schema.Set).List()

for _, item := range valueList {
if value, ok := item.(map[string]interface{}); ok {
includeList = append(excludeList, &sdk.IdpDiscoveryRuleAppObj{
excludeList = append(excludeList, &sdk.IdpDiscoveryRuleAppObj{
ID: getMapString(value, "id"),
Type: getMapString(value, "type"),
Name: getMapString(value, "name"),
Expand Down Expand Up @@ -198,8 +199,8 @@ func buildUserIdPatterns(d *schema.ResourceData) []*sdk.IdpDiscoveryRulePattern
}

func buildIdentifier(d *schema.ResourceData) *sdk.IdpDiscoveryRuleUserIdentifier {

uidType := d.Get("user_identifier_type").(string)

if uidType != "" {
return &sdk.IdpDiscoveryRuleUserIdentifier{
Attribute: d.Get("user_identifier_attribute").(string),
Expand Down Expand Up @@ -242,7 +243,7 @@ func flattenPlatformInclude(platform *sdk.IdpDiscoveryRulePlatform) *schema.Set
}

func flattenAppInclude(app *sdk.IdpDiscoveryRuleApp) *schema.Set {
var flattened []interface{}
flattened := []interface{}{}

if app != nil && app.Include != nil {
for _, v := range app.Include {
Expand All @@ -257,18 +258,18 @@ func flattenAppInclude(app *sdk.IdpDiscoveryRuleApp) *schema.Set {
}

func flattenAppExclude(app *sdk.IdpDiscoveryRuleApp) *schema.Set {
var flattend []interface{}
flattened := []interface{}{}

if app != nil && app.Include != nil {
if app != nil && app.Exclude != nil {
for _, v := range app.Exclude {
flattend = append(flattend, map[string]interface{}{
flattened = append(flattened, map[string]interface{}{
"id": v.ID,
"name": v.Name,
"type": v.Type,
})
}
}
return schema.NewSet(schema.HashResource(appResource), flattend)
return schema.NewSet(schema.HashResource(appResource), flattened)
}

func resourcePolicyRuleIdpDiscoveryExists(d *schema.ResourceData, m interface{}) (bool, error) {
Expand Down
3 changes: 3 additions & 0 deletions okta/resource_policy_rule_idp_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestAccOktaPolicyRuleIdpDiscovery(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", buildResourceName(ri)),
resource.TestCheckResourceAttr(resourceName, "status", "ACTIVE"),
resource.TestCheckResourceAttr(resourceName, "user_identifier_patterns.#", "1"),
resource.TestCheckResourceAttr(resourceName, "user_identifier_type", "ATTRIBUTE"),
),
},
{
Expand All @@ -42,6 +43,7 @@ func TestAccOktaPolicyRuleIdpDiscovery(t *testing.T) {
ensureRuleExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", buildResourceName(ri)),
resource.TestCheckResourceAttr(resourceName, "status", "ACTIVE"),
resource.TestCheckResourceAttr(resourceName, "user_identifier_type", "IDENTIFIER"),
resource.TestCheckResourceAttr(resourceName, "user_identifier_patterns.#", "2"),
),
},
Expand All @@ -51,6 +53,7 @@ func TestAccOktaPolicyRuleIdpDiscovery(t *testing.T) {
ensureRuleExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", buildResourceName(ri)),
resource.TestCheckResourceAttr(resourceName, "status", "INACTIVE"),
resource.TestCheckResourceAttr(resourceName, "user_identifier_type", "IDENTIFIER"),
resource.TestCheckResourceAttr(resourceName, "user_identifier_patterns.#", "2"),
),
},
Expand Down
2 changes: 1 addition & 1 deletion okta/resource_policy_rule_password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func doesRuleExistsUpstream(policyID string, ID string) (bool, error) {
client := getClientFromMetadata(testAccProvider.Meta())

rule, resp, err := client.Policies.GetPolicyRule(policyID, ID)
if resp.StatusCode == http.StatusNotFound {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return false, nil
} else if err != nil {
return false, err
Expand Down

0 comments on commit 92572d6

Please # to comment.