-
Notifications
You must be signed in to change notification settings - Fork 196
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
Built-in role definitions should be skiped by asoctl #4263
Merged
theunrepentantgeek
merged 2 commits into
main
from
feature/skip-builtin-roledefinitions
Sep 16, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
v2/api/authorization/customizations/role_definition_extensions.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,41 @@ | ||
/* | ||
Copyright (c) Microsoft Corporation. | ||
Licensed under the MIT license. | ||
*/ | ||
|
||
package customizations | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
api "github.com/Azure/azure-service-operator/v2/api/authorization/v1api20220401" | ||
|
||
"github.com/Azure/azure-service-operator/v2/pkg/genruntime" | ||
"github.com/Azure/azure-service-operator/v2/pkg/genruntime/extensions" | ||
) | ||
|
||
var _ extensions.Importer = &RoleDefinitionExtension{} | ||
|
||
func (extension *RoleDefinitionExtension) Import( | ||
ctx context.Context, | ||
rsrc genruntime.ImportableResource, | ||
owner *genruntime.ResourceReference, | ||
next extensions.ImporterFunc, | ||
) (extensions.ImportResult, error) { | ||
result, err := next(ctx, rsrc, owner) | ||
if err != nil { | ||
return extensions.ImportResult{}, err | ||
} | ||
|
||
if definition, ok := rsrc.(*api.RoleDefinition); ok { | ||
// If this role definition is built in, we don't need to export it | ||
if definition.Spec.Type != nil { | ||
if strings.EqualFold(*definition.Spec.Type, "BuiltInRole") { | ||
return extensions.ImportSkipped("role definition is built-in"), nil | ||
} | ||
} | ||
} | ||
|
||
return result, nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be the storage version? (I checked other
Import
impls and it seems it doesn't, I guess this is because we call import on the latest public API shape not the latest storage shape which makes some sense...)Assuming above is true and this doesn't need to be the storage version, how do we catch when we update to support a newer API version and this cast is no longer correct? We can do that statically by asserting the type impls the
Hub
interface, but there's no such static assertion here so the code will compile even though it doesn't work.Do we have a test that covers this case?
Wondering if at they very least we should do something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I think the other imports could use this check too, or one like it - we could fabricate an interface on the latest API version of each resource and then avoid the weird indirection through the storage version for this if we prefer, but in some ways that feels even more awkward)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface is only ever generated for a single version of any one resource - usually the latest stable version, though a preview version will be used if no stable version is available.
If we import a new stable version of a resource and that interface moves, we get a compilation error here in the extension because the cast from
genruntime.ImportableResource
can never succeed. It will look something like this:To provoke this, I changed the import from
authorization/v1api20220401
(which works) toauthorization/v1api20200801preview
.So while we don't have an explicit type assertion, we still get the same level of protection.