-
Notifications
You must be signed in to change notification settings - Fork 45
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
feat(jaas-role): add jaas' role support #648
Open
SimoneDutto
wants to merge
2
commits into
juju:main
Choose a base branch
from
SimoneDutto:JUJU-7235/jaas-role
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
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
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,34 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "juju_jaas_role Data Source - terraform-provider-juju" | ||
subcategory: "" | ||
description: |- | ||
A data source representing a Juju JAAS Role. | ||
--- | ||
|
||
# juju_jaas_role (Data Source) | ||
|
||
A data source representing a Juju JAAS Role. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "juju_jaas_role" "test" { | ||
name = "role-0" | ||
} | ||
output "role_uuid" { | ||
value = data.juju_jaas_role.test.uuid | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) The name of the role. | ||
|
||
### Read-Only | ||
|
||
- `uuid` (String) The UUID of the role. |
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
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,50 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "juju_jaas_access_role Resource - terraform-provider-juju" | ||
subcategory: "" | ||
description: |- | ||
A resource that represents access to a role when using JAAS. | ||
--- | ||
|
||
# juju_jaas_access_role (Resource) | ||
|
||
A resource that represents access to a role when using JAAS. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "juju_jaas_access_role" "development" { | ||
role_id = juju_jaas_role.target-role.uuid | ||
access = "assignee" | ||
users = ["[email protected]"] | ||
roles = [juju_jaas_role.development.uuid] | ||
service_accounts = ["Client-ID-1", "Client-ID-2"] | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `access` (String) Level of access to grant. Changing this value will replace the Terraform resource. Valid access levels are described at https://canonical-jaas-documentation.readthedocs-hosted.com/en/latest/reference/authorisation_model/#valid-relations | ||
- `role_id` (String) The ID of the role for access management. If this is changed the resource will be deleted and a new resource will be created. | ||
|
||
### Optional | ||
|
||
- `groups` (Set of String) List of groups to grant access. | ||
- `service_accounts` (Set of String) List of service accounts to grant access. | ||
- `users` (Set of String) List of users to grant access. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# JAAS role access can be imported using the role UUID and access level | ||
$ terraform import juju_jaas_access_role.development UUID:assignee | ||
``` |
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,30 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "juju_jaas_role Resource - terraform-provider-juju" | ||
subcategory: "" | ||
description: |- | ||
A resource that represents a role in JAAS | ||
--- | ||
|
||
# juju_jaas_role (Resource) | ||
|
||
A resource that represents a role in JAAS | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "juju_jaas_role" "development" { | ||
name = "devops-team" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) Name of the role | ||
|
||
### Read-Only | ||
|
||
- `uuid` (String) UUID of the role |
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,7 @@ | ||
data "juju_jaas_role" "test" { | ||
name = "role-0" | ||
} | ||
|
||
output "role_uuid" { | ||
value = data.juju_jaas_role.test.uuid | ||
} |
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,2 @@ | ||
# JAAS role access can be imported using the role UUID and access level | ||
$ terraform import juju_jaas_access_role.development UUID:assignee |
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,7 @@ | ||
resource "juju_jaas_access_role" "development" { | ||
role_id = juju_jaas_role.target-role.uuid | ||
access = "assignee" | ||
users = ["[email protected]"] | ||
roles = [juju_jaas_role.development.uuid] | ||
service_accounts = ["Client-ID-1", "Client-ID-2"] | ||
} |
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,3 @@ | ||
resource "juju_jaas_role" "development" { | ||
name = "devops-team" | ||
} |
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
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 |
---|---|---|
|
@@ -217,3 +217,78 @@ func (jc *jaasClient) RemoveGroup(name string) error { | |
req := params.RemoveGroupRequest{Name: name} | ||
return client.RemoveGroup(&req) | ||
} | ||
|
||
// JaasRole represents a JAAS role used for permissions management. | ||
type JaasRole struct { | ||
SimoneDutto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Name string | ||
UUID string | ||
} | ||
|
||
// AddRole attempts to create a new role with the provided name. | ||
func (jc *jaasClient) AddRole(name string) (string, error) { | ||
conn, err := jc.GetConnection(nil) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer func() { _ = conn.Close() }() | ||
|
||
client := jc.getJaasApiClient(conn) | ||
req := params.AddRoleRequest{Name: name} | ||
|
||
resp, err := client.AddRole(&req) | ||
if err != nil { | ||
return "", err | ||
} | ||
return resp.UUID, nil | ||
} | ||
|
||
// ReadRoleByUUID attempts to read a role that matches the provided UUID. | ||
func (jc *jaasClient) ReadRoleByUUID(uuid string) (*JaasRole, error) { | ||
return jc.readRole(¶ms.GetRoleRequest{UUID: uuid}) | ||
} | ||
|
||
// ReadRoleByName attempts to read a role that matches the provided name. | ||
func (jc *jaasClient) ReadRoleByName(name string) (*JaasRole, error) { | ||
return jc.readRole(¶ms.GetRoleRequest{Name: name}) | ||
} | ||
|
||
Comment on lines
+245
to
+254
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. These two methods are implementation details. Which the caller shouldn't have to care about. It's cleaner at a package level to have a ReadRole method, then internally decide if it's a UUID or string. |
||
func (jc *jaasClient) readRole(req *params.GetRoleRequest) (*JaasRole, error) { | ||
conn, err := jc.GetConnection(nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer func() { _ = conn.Close() }() | ||
|
||
client := jc.getJaasApiClient(conn) | ||
resp, err := client.GetRole(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &JaasRole{Name: resp.Name, UUID: resp.UUID}, nil | ||
} | ||
|
||
// RenameRole attempts to rename a role that matches the provided name. | ||
func (jc *jaasClient) RenameRole(name, newName string) error { | ||
conn, err := jc.GetConnection(nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { _ = conn.Close() }() | ||
|
||
client := jc.getJaasApiClient(conn) | ||
req := params.RenameRoleRequest{Name: name, NewName: newName} | ||
return client.RenameRole(&req) | ||
} | ||
|
||
// RemoveRole attempts to remove a role that matches the provided name. | ||
func (jc *jaasClient) RemoveRole(name string) error { | ||
conn, err := jc.GetConnection(nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer func() { _ = conn.Close() }() | ||
|
||
client := jc.getJaasApiClient(conn) | ||
req := params.RemoveRoleRequest{Name: name} | ||
return client.RemoveRole(&req) | ||
} |
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.
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.
the linked page needs to be updated with valid access levels for roles
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.
nice catch, i'll propose a PR to change that page soon