-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Azure role definitions and assignments clients
- Loading branch information
Showing
5 changed files
with
119 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
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,39 @@ | ||
package azure | ||
|
||
import ( | ||
"context" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2" | ||
"github.com/gravitational/trace" | ||
) | ||
|
||
type RoleAssignmentsClient interface { | ||
ListRoleAssignments(ctx context.Context, scope string) ([]*armauthorization.RoleAssignment, error) | ||
} | ||
|
||
type roleAssignmentsClient struct { | ||
cli *armauthorization.RoleAssignmentsClient | ||
} | ||
|
||
func (c *roleAssignmentsClient) ListRoleAssignments(ctx context.Context, scope string) ([]*armauthorization.RoleAssignment, error) { | ||
pager := c.cli.NewListForScopePager(scope, nil) | ||
roleDefs := make([]*armauthorization.RoleAssignment, 0, 128) | ||
for pager.More() { | ||
page, err := pager.NextPage(ctx) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
roleDefs = append(roleDefs, page.Value...) | ||
} | ||
return roleDefs, nil | ||
} | ||
|
||
func NewRoleAssignmentsClient(subscription string, cred azcore.TokenCredential, options *arm.ClientOptions) (RoleAssignmentsClient, error) { | ||
clientFactory, err := armauthorization.NewClientFactory(subscription, cred, options) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
roleDefCli := clientFactory.NewRoleAssignmentsClient() | ||
return &roleAssignmentsClient{cli: roleDefCli}, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package azure | ||
|
||
import ( | ||
"context" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2" | ||
"github.com/gravitational/trace" | ||
) | ||
|
||
type RoleDefinitionsClient interface { | ||
ListRoleDefinitions(ctx context.Context, scope string) ([]*armauthorization.RoleDefinition, error) | ||
} | ||
|
||
type roleDefinitionsClient struct { | ||
cli *armauthorization.RoleDefinitionsClient | ||
} | ||
|
||
func (c *roleDefinitionsClient) ListRoleDefinitions(ctx context.Context, scope string) ([]*armauthorization.RoleDefinition, error) { | ||
pager := c.cli.NewListPager(scope, nil) | ||
roleDefs := make([]*armauthorization.RoleDefinition, 0, 128) | ||
for pager.More() { | ||
page, err := pager.NextPage(ctx) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
roleDefs = append(roleDefs, page.Value...) | ||
} | ||
return roleDefs, nil | ||
} | ||
|
||
func NewRoleDefinitionsClient(subscription string, cred azcore.TokenCredential, options *arm.ClientOptions) (RoleDefinitionsClient, error) { | ||
clientFactory, err := armauthorization.NewClientFactory(subscription, cred, options) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
roleDefCli := clientFactory.NewRoleDefinitionsClient() | ||
return &roleDefinitionsClient{cli: roleDefCli}, 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