-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
At present If a customer attempts to use the custom role import function they must provide a json input file. It is possible to export an existing role to json in order to use it as a basis for creating a new role, i.e.:
➜ 4792 coder organizations roles show -O=rshl organization-workspace-creation-ban -ojson
[
{
"name": "organization-workspace-creation-ban",
"organization_id": "d898ad9c-63b7-40dd-a0b0-70216f783be0",
"display_name": "Organization Workspace Creation Ban",
"site_permissions": [],
"user_permissions": [],
"organization_permissions": [
{
"negate": true,
"resource_type": "workspace",
"action": "create"
},
{
"negate": true,
"resource_type": "workspace",
"action": "delete"
},
{
"negate": true,
"resource_type": "workspace",
"action": "create_agent"
},
{
"negate": true,
"resource_type": "workspace",
"action": "delete_agent"
}
],
"organization_member_permissions": [],
"assignable": true,
"built_in": true
}
]
If I then customise it (new name, display_name, change built_in to false) like so:
[
{
"name": "organization-workspace-creation-ban2",
"organization_id": "d898ad9c-63b7-40dd-a0b0-70216f783be0",
"display_name": "Organization Workspace Creation Ban2",
"site_permissions": [],
"user_permissions": [],
"organization_permissions": [
{
"negate": true,
"resource_type": "workspace",
"action": "create"
},
{
"negate": true,
"resource_type": "workspace",
"action": "delete"
},
{
"negate": true,
"resource_type": "workspace",
"action": "create_agent"
},
{
"negate": true,
"resource_type": "workspace",
"action": "delete_agent"
}
],
"organization_member_permissions": [],
"assignable": true,
"built_in": false
}
]
And then try and import it I receive an error:
➜ 4792 coder organizations roles create -O=rshl --stdin < builtin.json
Encountered an error running "coder organizations roles create", see "coder organizations roles create --help" for more information
error: parsing stdin json: json: cannot unmarshal array into Go value of type codersdk.Role
This is because the show command passes roles (a []codersdk.AssignableRoles slice) to the formatter, which outputs a JSON array.
While the create command expects json.Unmarshal(bytes, &customRole) where customRole is a single codersdk.Role object.
The fix is to remove the first and last lines of the file which each contain square braces, re-align the remaining JSON, and re-run the import.
Relevant Log Output
Expected Behavior
The create command should be able to parse json provided by Coder's show command, whether it contains a single or multiple role entries.
Steps to Reproduce
See Current Behavior
Environment
- Host OS:
- Coder version: 2.28.6
Additional Context
No response