-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: role management policy resource
- Loading branch information
1 parent
e128e98
commit 90fc00a
Showing
26 changed files
with
3,494 additions
and
4 deletions.
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
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
66 changes: 66 additions & 0 deletions
66
internal/services/authorization/parse/role_management_policy.go
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,66 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/authorization/2020-10-01/rolemanagementpolicies" | ||
) | ||
|
||
type RoleManagementPolicyID struct { | ||
Scope string | ||
RoleManagementPolicyName string | ||
RoleDefinitionId string | ||
} | ||
|
||
func NewRoleManagementPolicyID(scope string, roleManagementPolicyName string, roleDefinitionId string) RoleManagementPolicyID { | ||
return RoleManagementPolicyID{ | ||
Scope: scope, | ||
RoleManagementPolicyName: roleManagementPolicyName, | ||
RoleDefinitionId: roleDefinitionId, | ||
} | ||
} | ||
|
||
func (id RoleManagementPolicyID) ID() string { | ||
fmtString := "%s/providers/Microsoft.Authorization/roleManagementPolicies/%s|%s" | ||
return fmt.Sprintf(fmtString, id.Scope, id.RoleManagementPolicyName, id.RoleDefinitionId) | ||
} | ||
|
||
func (id RoleManagementPolicyID) ScopedRoleManagementPolicyId() rolemanagementpolicies.ScopedRoleManagementPolicyId { | ||
return rolemanagementpolicies.NewScopedRoleManagementPolicyID(id.Scope, id.RoleManagementPolicyName) | ||
} | ||
|
||
func (id RoleManagementPolicyID) String() string { | ||
segments := []string{ | ||
fmt.Sprintf("RoleManagementPolicyName %q", id.RoleManagementPolicyName), | ||
fmt.Sprintf("Scope %q", id.Scope), | ||
fmt.Sprintf("Role Definition Id %q", id.RoleDefinitionId), | ||
} | ||
segmentsStr := strings.Join(segments, " / ") | ||
return fmt.Sprintf("%s: (%s)", "Role Management Policy", segmentsStr) | ||
} | ||
|
||
// RoleManagementPolicyId is a pseudo ID for storing Scope parameter as this it not retrievable from API | ||
// It is formed of the Azure Resource ID for the Role and the Scope it is created against | ||
func RoleManagementPolicyId(input string) (*RoleManagementPolicyID, error) { | ||
parts := strings.Split(input, "|") | ||
if len(parts) != 2 { | ||
return nil, fmt.Errorf("could not parse Role Management Policy ID, invalid format %q", input) | ||
} | ||
|
||
roleManagementPolicyID := RoleManagementPolicyID{} | ||
|
||
rawRoleManagementPolicyId := parts[0] | ||
rawRoleDefinitionId := parts[1] | ||
|
||
roleManagementPolicyId, err := rolemanagementpolicies.ParseScopedRoleManagementPolicyID(rawRoleManagementPolicyId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
roleManagementPolicyID.Scope = *&roleManagementPolicyId.Scope | ||
roleManagementPolicyID.RoleManagementPolicyName = *&roleManagementPolicyId.RoleManagementPolicyName | ||
|
||
roleManagementPolicyID.RoleDefinitionId = rawRoleDefinitionId | ||
|
||
return &roleManagementPolicyID, 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
Oops, something went wrong.