-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to test if miwi enabled
- Loading branch information
Showing
3 changed files
with
85 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,13 @@ | ||
package identity | ||
|
||
import ( | ||
"github.com/Azure/ARO-RP/pkg/api" | ||
) | ||
|
||
func IsManagedWorkloadIdentityEnabled(cluster *api.OpenShiftCluster) bool { | ||
if cluster.Properties.ServicePrincipalProfile == nil && cluster.Properties.PlatformWorkloadIdentityProfile != nil && cluster.Identity != nil { | ||
return true | ||
} | ||
|
||
return false | ||
} |
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,69 @@ | ||
package identity | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Azure/ARO-RP/pkg/api" | ||
) | ||
|
||
func TestIsManagedWorkloadIdentityEnabled(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cluster *api.OpenShiftCluster | ||
expected bool | ||
}{ | ||
{ | ||
name: "Workload Identity Enabled", | ||
cluster: &api.OpenShiftCluster{ | ||
Properties: api.OpenShiftClusterProperties{ | ||
ServicePrincipalProfile: nil, | ||
PlatformWorkloadIdentityProfile: &api.PlatformWorkloadIdentityProfile{}, | ||
}, | ||
Identity: &api.Identity{}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "Service Principal Profile not nil", | ||
cluster: &api.OpenShiftCluster{ | ||
Properties: api.OpenShiftClusterProperties{ | ||
ServicePrincipalProfile: &api.ServicePrincipalProfile{}, | ||
PlatformWorkloadIdentityProfile: nil, | ||
}, | ||
Identity: nil, | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "PlatformWorkloadIdentityProfile is nil", | ||
cluster: &api.OpenShiftCluster{ | ||
Properties: api.OpenShiftClusterProperties{ | ||
ServicePrincipalProfile: nil, | ||
PlatformWorkloadIdentityProfile: nil, | ||
}, | ||
Identity: &api.Identity{}, | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "Identity is nil", | ||
cluster: &api.OpenShiftCluster{ | ||
Properties: api.OpenShiftClusterProperties{ | ||
ServicePrincipalProfile: nil, | ||
PlatformWorkloadIdentityProfile: &api.PlatformWorkloadIdentityProfile{}, | ||
}, | ||
Identity: nil, | ||
}, | ||
expected: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := IsManagedWorkloadIdentityEnabled(tt.cluster) | ||
if result != tt.expected { | ||
t.Errorf("expected %t, got %t", tt.expected, result) | ||
} | ||
}) | ||
} | ||
} |
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