|
| 1 | +--- |
| 2 | +title: "User Groups" |
| 3 | +linkTitle: "User Group" |
| 4 | +weight: 3 |
| 5 | +--- |
| 6 | + |
| 7 | +User group provisioning allows you to create, update, or delete user groups. |
| 8 | + |
| 9 | +User groups enable you to organize users and manage permissions at scale by assigning permissions to groups rather than individual users. |
| 10 | + |
| 11 | +You can provision user groups using full or incremental load methods. Each of these methods requires a specific input type. |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +Start by importing and initializing the UserGroupProvisioner. |
| 16 | + |
| 17 | +```python |
| 18 | + |
| 19 | +from gooddata_pipelines import UserGroupProvisioner |
| 20 | + |
| 21 | +host = "http://localhost:3000" |
| 22 | +token = "some_user_token" |
| 23 | + |
| 24 | +# Initialize the provisioner with GoodData credentials |
| 25 | +provisioner = UserGroupProvisioner.create(host=host, token=token) |
| 26 | + |
| 27 | +``` |
| 28 | + |
| 29 | + |
| 30 | +Then validate your data using an input model corresponding to the provisioned resource and selected workflow type, i.e., `UserGroupFullLoad` if you intend to run the provisioning in full load mode, or `UserGroupIncrementalLoad` if you want to provision incrementally. |
| 31 | + |
| 32 | +The models expect the following fields: |
| 33 | +- **user_group_id**: ID of the user group. |
| 34 | +- **user_group_name**: Name of the user group. |
| 35 | +- **parent_user_groups**: A list of parent user group IDs. |
| 36 | +- _**is_active**:_ Deletion flag. Present only in the IncrementalLoad models. |
| 37 | + |
| 38 | +{{% alert color="info" title="Note on IDs"%}} |
| 39 | +Each ID can only contain allowed characters. See [Workspace Object Identification](https://www.gooddata.com/docs/cloud/create-workspaces/objects-identification/) to learn more about object identifiers. |
| 40 | +{{% /alert %}} |
| 41 | + |
| 42 | +Use the appropriate model to validate your data: |
| 43 | + |
| 44 | +```python |
| 45 | +# Add the model to the imports |
| 46 | +from gooddata_pipelines import UserGroupFullLoad, UserGroupProvisioner |
| 47 | + |
| 48 | +host = "http://localhost:3000" |
| 49 | +token = "some_user_token" |
| 50 | + |
| 51 | +# Initialize the provisioner with GoodData credentials |
| 52 | +provisioner = UserGroupProvisioner.create(host=host, token=token) |
| 53 | + |
| 54 | +# Load your data |
| 55 | +raw_data = [ |
| 56 | + { |
| 57 | + "user_group_id": "user_group_1", |
| 58 | + "user_group_name": "User Group 1", |
| 59 | + "parent_user_groups": [], |
| 60 | + }, |
| 61 | +] |
| 62 | + |
| 63 | +# Validate the data |
| 64 | +validated_data = [ |
| 65 | + UserGroupFullLoad( |
| 66 | + user_group_id=item["user_group_id"], |
| 67 | + user_group_name=item["user_group_name"], |
| 68 | + parent_user_groups=item["parent_user_groups"], |
| 69 | + ) |
| 70 | + for item in raw_data |
| 71 | +] |
| 72 | + |
| 73 | +``` |
| 74 | + |
| 75 | +Now with the provisioner initialized and your data validated, you can run the provisioner: |
| 76 | + |
| 77 | +```python |
| 78 | +# Import, initialize, validate... |
| 79 | +... |
| 80 | + |
| 81 | +# Run the provisioning method |
| 82 | +provisioner.full_load(validated_data) |
| 83 | + |
| 84 | +``` |
| 85 | + |
| 86 | +## Examples |
| 87 | + |
| 88 | +Here are full examples of a full load and incremental load user group provisioning workflows: |
| 89 | + |
| 90 | +### Full Load |
| 91 | + |
| 92 | +```python |
| 93 | +import logging |
| 94 | + |
| 95 | +from gooddata_pipelines import UserGroupFullLoad, UserGroupProvisioner |
| 96 | + |
| 97 | +host = "http://localhost:3000" |
| 98 | +token = "some_user_token" |
| 99 | + |
| 100 | +# Initialize the provisioner |
| 101 | +provisioner = UserGroupProvisioner.create(host=host, token=token) |
| 102 | + |
| 103 | +# Optional: set up logging and subscribe to logs emitted by the provisioner |
| 104 | +logging.basicConfig(level=logging.INFO) |
| 105 | +logger = logging.getLogger(__name__) |
| 106 | + |
| 107 | +provisioner.logger.subscribe(logger) |
| 108 | + |
| 109 | +# Prepare your data |
| 110 | +raw_data = [ |
| 111 | + { |
| 112 | + "user_group_id": "user_group_1", |
| 113 | + "user_group_name": "User Group 1", |
| 114 | + "parent_user_groups": [], |
| 115 | + }, |
| 116 | +] |
| 117 | + |
| 118 | +# Validate the data |
| 119 | +validated_data = [ |
| 120 | + UserGroupFullLoad( |
| 121 | + user_group_id=item["user_group_id"], |
| 122 | + user_group_name=item["user_group_name"], |
| 123 | + parent_user_groups=item["parent_user_groups"], |
| 124 | + ) |
| 125 | + for item in raw_data |
| 126 | +] |
| 127 | + |
| 128 | +# Run the provisioning with the validated data |
| 129 | +provisioner.full_load(validated_data) |
| 130 | + |
| 131 | +``` |
| 132 | + |
| 133 | + |
| 134 | +### Incremental Load |
| 135 | + |
| 136 | +```python |
| 137 | +import logging |
| 138 | + |
| 139 | +from gooddata_pipelines import UserGroupIncrementalLoad, UserGroupProvisioner |
| 140 | + |
| 141 | +host = "http://localhost:3000" |
| 142 | +token = "some_user_token" |
| 143 | + |
| 144 | +# Initialize the provisioner |
| 145 | +provisioner = UserGroupProvisioner.create(host=host, token=token) |
| 146 | + |
| 147 | +# Optional: set up logging and subscribe to logs emitted by the provisioner |
| 148 | +logging.basicConfig(level=logging.INFO) |
| 149 | +logger = logging.getLogger(__name__) |
| 150 | + |
| 151 | +provisioner.logger.subscribe(logger) |
| 152 | + |
| 153 | +# Prepare your data |
| 154 | +raw_data = [ |
| 155 | + { |
| 156 | + "user_group_id": "user_group_1", |
| 157 | + "user_group_name": "User Group 1", |
| 158 | + "parent_user_groups": [], |
| 159 | + "is_active": True, |
| 160 | + }, |
| 161 | +] |
| 162 | + |
| 163 | +# Validate the data |
| 164 | +validated_data = [ |
| 165 | + UserGroupIncrementalLoad( |
| 166 | + user_group_id=item["user_group_id"], |
| 167 | + user_group_name=item["user_group_name"], |
| 168 | + parent_user_groups=item["parent_user_groups"], |
| 169 | + is_active=item["is_active"], |
| 170 | + ) |
| 171 | + for item in raw_data |
| 172 | +] |
| 173 | + |
| 174 | +# Run the provisioning with the validated data |
| 175 | +provisioner.incremental_load(validated_data) |
| 176 | + |
| 177 | +``` |
0 commit comments