-
Notifications
You must be signed in to change notification settings - Fork 1
[BB-1542] Add license entitlement provisioning #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2217950
5fb236e
999f08d
663955d
65ce57b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,15 @@ import ( | |
| ) | ||
|
|
||
| var licences = []string{creator, explorer, viewer, unlicensed} | ||
| var licensesMap = map[string]string{ | ||
| "creator": creator, | ||
| "explorer": explorer, | ||
| "viewer": viewer, | ||
| "unlicensed": unlicensed, | ||
| } | ||
| var RolesPerLicense = map[string][]string{ | ||
| creator: {siteAdministratorCreator, creator}, | ||
| explorer: {siteAdministratorExplorer, explorerCanPublish, explorer, readOnly, siteAdministrator}, | ||
| creator: {creator, siteAdministratorCreator}, | ||
| explorer: {explorer, siteAdministratorExplorer, explorerCanPublish, readOnly, siteAdministrator}, | ||
| viewer: {viewer}, | ||
| unlicensed: {unlicensed}, | ||
| } | ||
|
|
@@ -105,6 +111,34 @@ func (l *licenseResourceType) Grants(ctx context.Context, resource *v2.Resource, | |
| return rv, token, nil, nil | ||
| } | ||
|
|
||
| func (l *licenseResourceType) Grant(ctx context.Context, principal *v2.Resource, entitlement *v2.Entitlement) (annotations.Annotations, error) { | ||
| licenseName, ok := licensesMap[entitlement.Resource.Id.Resource] | ||
| if !ok { | ||
| return nil, fmt.Errorf("unknown license %s", entitlement.Resource.Id.Resource) | ||
| } | ||
| principalID := principal.Id.Resource | ||
|
|
||
| outputAnnotations := annotations.New() | ||
| err := l.client.UpdateUserSiteRole(ctx, principalID, licenseName) | ||
| if err != nil { | ||
| return outputAnnotations, fmt.Errorf("failed to grant %s license to user %s: %w", licenseName, principalID, err) | ||
| } | ||
|
|
||
| return outputAnnotations, nil | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: License Assignment Error and Missing Rate LimitingThe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| } | ||
aldevv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| func (l *licenseResourceType) Revoke(ctx context.Context, grant *v2.Grant) (annotations.Annotations, error) { | ||
| principalID := grant.Principal.Id.Resource | ||
|
|
||
| outputAnnotations := annotations.New() | ||
| err := l.client.UpdateUserSiteRole(ctx, principalID, unlicensed) | ||
aldevv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return outputAnnotations, fmt.Errorf("failed to revoke license from user %s: %w", principalID, err) | ||
| } | ||
|
|
||
| return outputAnnotations, nil | ||
| } | ||
|
|
||
| func licenseBuilder(client *tableau.Client) *licenseResourceType { | ||
| return &licenseResourceType{ | ||
| resourceType: resourceTypeLicense, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.