Managing Scoped Roles via the Command Line

You can use the datasphere command line interface to create, read, update, and delete scoped roles.

Prerequisites

To manage scoped roles and privileges via the command line, you must have a global role that grants you the following privileges:
  • Data Warehouse General (-R------) - To access SAP Datasphere.

  • Role (CRUD----) - To access the (Roles) and (Authorization Overview) areas in the (Security) tool and to create, update, and delete roles.

  • User (-------M) - To add users to roles.

  • Spaces (-------M) - To add spaces to scoped roles.

The DW Administrator global role, for example, grants these privileges. For more information, see Privileges and Permissions and Standard Roles Delivered with SAP Datasphere.
You must, in addition: To browse the available commands, enter the following and press Return:
datasphere scoped-roles

For general information about working with scoped roles in SAP Datasphere , see Create a Scoped Role to Assign Privileges to Users in Spaces .

List Scoped Roles

You can list the scoped roles in your tenant, and optionally write them to a file.

Enter the following command and press Return:
datasphere scoped-roles list
     [--output <file>.json]
Complete the parameters as follows:

Parameter

Description

--output <file>.json

[optional] Enter a path to a .json file to write the output to.

If you do not include this option, the output will be printed to the command line.

Read Scoped Roles

You can read the CSN/JSON definition of a scoped role and optionally write it to a file.

Enter the following command and press Return:
datasphere scoped-roles read
    --role <id>
    [--output <file>.json]
To read the list of spaces that are assigned to a scoped role, and optionally write it to a file, enter the following command and press Return:
datasphere scoped-roles scopes read
    --role <ID>
    --output <file>.json
To read the list of users assigned to a scoped role and optionally write it to a file, enter the following command and press Return:
datasphere scoped-roles users read
    --role <ID>
    --output <file>.json
Complete the parameters as follows:

Parameter

Description

--role <id>

Enter the ID of a scoped role.

--output <file>.json

[optional] Enter a path to a .json file to write the output to.

If you do not include this option, the output will be printed to the command line.

Create Scoped Roles

You can create scoped roles by providing a definition in a JSON file or an input string.

Enter the following command and press Return:
datasphere scoped-roles create
    --file-path <file>.json|--input '<stringified-json>'
Complete the parameters as follows:

Parameter

Description

--file-path <file>.json

[optional] Enter a path to a file with a .json extension containing your scoped role definition.

{
    "name": "<Name>",
    "description": "<Description>",  
    "inheritance": "<Role_Template_Name>"
}

--input '<stringified-json>'

[optional] Provide your input in stringified json format instead of via the --file-path option.

For example, to create the scoped role Sales_Modeler based on the role template Custom_Modeler, enter the following command and press Return:
datasphere scoped-roles create --file-path sales_modeler.json
Where the file sales_modeler.json contains the following:
{
    "name": "Sales_Modeler",  
    "description": "Modeler for Sales spaces",
    "inheritance": "Custom_Modeler"
}

Update Scoped Roles

You can update the description or template role of a scoped role by providing a new definition in a JSON file or an input string.

Enter the following command and press Return:
datasphere scoped-roles update
    --role <ID>
    --file-path <file>.json|--input '<stringified-json>'
Complete the parameters as follows:

Parameter

Description

--role <id>

Enter the ID of a scoped role.

--file-path <file>.json

[optional] Enter a path to a file with a .json extension containing your scoped role definition.

{
    "description": "<Description>",
    "inheritance": "<Role_Template_Name>"										
}

--input '<stringified-json>'

[optional] Provide your input in stringified json format instead of via the --file-path option.

Add Spaces to Scoped Roles

You can add spaces to a scoped role as a comma-separated list of space IDs.
Enter the following command and press Return:
datasphere scoped-roles scopes add
    --role <ID> 
    --scopes <ID[,ID...]>
Complete the parameters as follows:

Parameter

Description

--role <id>

Enter the ID of a scoped role.

--scopes <ID[,ID...]>

Enter a comma-separated list of space IDs.

For example, to add the two spaces SALES_EU and SALES_US to the scoped role Sales_Modeler, enter the following command and press Return:
datasphere scoped-roles scopes add --role Sales_Modeler --scopes SALES_EU,SALES_US

Add Users to Scoped Roles

You can add users to a scoped role (and specify the spaces they will be given access to) by providing a definition in a JSON file or an input string.
Enter the following command and press Return:
datasphere scoped-roles users add
    --role <ID> 
    --file-path <file>.json|--input '<stringified-json>'
Complete the parameters as follows:

Parameter

Description

--role <id>

Enter the ID of a scoped role.

--file-path <file>.json

Enter a path to a file with a .json extension containing the list of users to add and the scopes to add them to:
[
    {
        "id": "<userID>",
        "scopes": ["<spaceID>","<spaceID>"]
    },
    {
        "id": "<userID>",
        "scopes": ["<spaceID>","<spaceID>"]
    }
]

--input '<stringified-json>'

[optional] Provide your input in stringified json format instead of via the --file-path option.

For example, to add the users BBAXTER and JJONES to the spaces SALES_EU and SALES_US via the scoped role Sales_Modeler, enter the following command and press Return:
datasphere scoped-roles users add --role Sales_Modeler --file-path add.json
Where the file add.json contains the following:
[ 
    {
          "id": "BBAXTER",
          "scopes": ["SALES_EU", "SALES_US"]
    },
    {
          "id": "JJONES",
          "scopes": ["SALES_EU", "SALES_US"]
    }
]

Remove Users from Scoped Roles

Enter the following command and press Return:
datasphere scoped-roles users remove
    --role <ID>
    --file-path <file>.json|--input '<stringified-json>'
Complete the parameters as follows:

Parameter

Description

--role <id>

Enter the ID of a scoped role.

--file-path <file>.json

[optional] Enter a path to a file with a .json extension containing the list of users to remove and the spaces to remove them from:
[
    {
        "id": "<userID>",
        "scopes": ["<spaceID>","<spaceID>"]
    },
    {
        "id": "<userID>",
        "scopes": ["<spaceID>","<spaceID>"]
    }
]

--input '<stringified-json>'

[optional] Provide your input in stringified json format instead of via the --file-path option.

For example, to remove BBAXTER and JJONES from SALES_EU via the scoped role Sales_Modeler, enter the following command and press Return:
datasphere scoped-roles users remove --role Sales_Modeler --file-path remove.json
Where the file remove.json contains the following:
[
    {
        "id": "BBAXTER",
        "scopes": ["SALES_EU"]
    },
    {
        "id": "JJONES",
        "scopes": ["SALES_EU"]
    }
]

Remove Scopes from Scoped Roles

You can remove scopes from a scoped role.

Enter the following command and press Return:
datasphere scoped-roles scopes remove
    --role <ID>
    --scopes <ID[,ID...]>
Complete the parameters as follows:

Parameter

Description

--role <id>

Enter the ID of a scoped role.

--scopes <ID[,ID...]>

Enter a comma-separated list of space IDs.

For example, to remove the space SALES_EU from the scoped role Sales_Modeler, enter the following command and press Return:
datasphere scoped-roles scopes remove --role Sales_Modeler --scopes SALES_EU

Delete Scoped Roles

You can delete scoped roles.

Enter the following command and press Return:
datasphere scoped-roles delete
    --role <ID>
    [--force]
Complete the parameters as follows:

Parameter

Description

--role <id>

Enter the ID of a scoped role.

--force

[optional] Suppress the Confirm Deletion step and delete the scoped role without confirmation.

For example, to delete the scoped role Sales_Modeler and suppress the confirmation, enter the following command and press Enter:
datasphere scoped-roles delete --role Sales_Modeler --force