Skip to content

Commit

Permalink
Make priority as a pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanprodan-okta committed Sep 23, 2021
1 parent 1416ecf commit ed5bfe4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/oklog/run v1.0.0 // indirect
github.com/okta/okta-sdk-golang/v2 v2.6.2
github.com/okta/okta-sdk-golang/v2 v2.6.3-0.20210923165359-20aeac44ab01
github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627 // indirect
github.com/russellhaering/goxmldsig v1.1.0 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/okta/okta-sdk-golang/v2 v2.6.2 h1:JcMjG0264ockA2RIrMA4L0fbnZAH+9qo2T/QuFApkj8=
github.com/okta/okta-sdk-golang/v2 v2.6.2/go.mod h1:0y8stgdplWMjaEbMr4mVtw0R+BdktpGZRw2sWKZWsMs=
github.com/okta/okta-sdk-golang/v2 v2.6.3-0.20210923165359-20aeac44ab01 h1:eTw4NCD4FBAAT+tqx8qq2WhPjVwauVp//mvG4c3wrUY=
github.com/okta/okta-sdk-golang/v2 v2.6.3-0.20210923165359-20aeac44ab01/go.mod h1:0y8stgdplWMjaEbMr4mVtw0R+BdktpGZRw2sWKZWsMs=
github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627 h1:pSCLCl6joCFRnjpeojzOpEYs4q7Vditq8fySFG5ap3Y=
github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
4 changes: 2 additions & 2 deletions okta/resource_okta_app_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ func buildAppGroupAssignment(d *schema.ResourceData) okta.ApplicationGroupAssign
var profile interface{}
rawProfile := d.Get("profile").(string)
_ = json.Unmarshal([]byte(rawProfile), &profile)
priority := d.Get("priority").(int)
priority := int64(d.Get("priority").(int))
return okta.ApplicationGroupAssignment{
Profile: profile,
Priority: int64(priority),
Priority: &priority,
}
}
23 changes: 16 additions & 7 deletions okta/resource_okta_app_group_assignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ func syncGroups(d *schema.ResourceData, groups []interface{}, assignments []*okt
for _, assignment := range assignments {
if assignment.Id == d.Get(fmt.Sprintf("group.%d.id", i)).(string) {
present = true
groups[i].(map[string]interface{})["priority"] = int(assignment.Priority)
if assignment.Priority != nil {
groups[i].(map[string]interface{})["priority"] = int(*assignment.Priority)
}
jsonProfile, _ := json.Marshal(assignment.Profile)
if string(jsonProfile) != "" {
groups[i].(map[string]interface{})["profile"] = string(jsonProfile)
Expand Down Expand Up @@ -218,8 +220,10 @@ func containsAssignment(assignments []*okta.ApplicationGroupAssignment, assignme

func containsEqualAssignment(assignments []*okta.ApplicationGroupAssignment, assignment *okta.ApplicationGroupAssignment) bool {
for i := range assignments {
if assignments[i].Id == assignment.Id && assignments[i].Priority == assignment.Priority &&
reflect.DeepEqual(assignments[i].Profile, assignment.Profile) {
if assignments[i].Id == assignment.Id && reflect.DeepEqual(assignments[i].Profile, assignment.Profile) {
if assignment.Priority != nil {
return reflect.DeepEqual(assignments[i].Priority, assignment.Priority)
}
return true
}
}
Expand All @@ -245,11 +249,16 @@ func tfGroupsToGroupAssignments(d *schema.ResourceData) []*okta.ApplicationGroup
rawProfile := d.Get(fmt.Sprintf("group.%d.profile", i))
var profile interface{}
_ = json.Unmarshal([]byte(rawProfile.(string)), &profile)
assignments[i] = &okta.ApplicationGroupAssignment{
Id: d.Get(fmt.Sprintf("group.%d.id", i)).(string),
Priority: int64(d.Get(fmt.Sprintf("group.%d.priority", i)).(int)),
Profile: profile,
a := &okta.ApplicationGroupAssignment{
Id: d.Get(fmt.Sprintf("group.%d.id", i)).(string),
Profile: profile,
}
priority, ok := d.GetOk(fmt.Sprintf("group.%d.priority", i))
if ok {
p := int64(priority.(int))
a.Priority = &p
}
assignments[i] = a
}
return assignments
}
Expand Down

0 comments on commit ed5bfe4

Please sign in to comment.