Skip to content
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

Add endpoint for cloning roles #1107

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.5.1.dev2",
"regenerated": "2021-12-21 22:39:24.049387",
"spec_repo_commit": "90bc255"
"regenerated": "2021-12-21 23:32:26.271475",
"spec_repo_commit": "4bb7a8e"
},
"v2": {
"apigentools_version": "1.5.1.dev2",
"regenerated": "2021-12-21 22:39:24.859715",
"spec_repo_commit": "90bc255"
"regenerated": "2021-12-21 23:32:27.301839",
"spec_repo_commit": "4bb7a8e"
}
}
}
92 changes: 92 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3927,6 +3927,36 @@ components:
readOnly: true
type: integer
type: object
RoleClone:
description: Data for the clone role request.
properties:
attributes:
$ref: '#/components/schemas/RoleCloneAttributes'
type:
$ref: '#/components/schemas/RolesType'
required:
- type
- attributes
type: object
RoleCloneAttributes:
description: Attributes required to create a new role by cloning an existing
one.
properties:
name:
description: Name of the new role that is cloned.
example: cloned-role
type: string
required:
- name
type: object
RoleCloneRequest:
description: Request to create a role by cloning an existing role.
properties:
data:
$ref: '#/components/schemas/RoleClone'
required:
- data
type: object
RoleCreateAttributes:
description: Attributes of the created role.
properties:
Expand Down Expand Up @@ -8028,6 +8058,68 @@ paths:
x-menu-order: 4
x-undo:
type: idempotent
/api/v2/roles/{role_id}/clone:
post:
description: Clone an existing role
operationId: CloneRole
parameters:
- $ref: '#/components/parameters/RoleID'
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/RoleCloneRequest'
required: true
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/RoleResponse'
description: OK
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: Bad Request
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: Authentication error
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: Not found
'409':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: Conflict
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
security:
- apiKeyAuth: []
appKeyAuth: []
- AuthZ:
- user_access_manage
summary: Create a new role by cloning an existing role
tags:
- Roles
x-codegen-request-body-name: body
x-menu-order: 12
x-permission: OR(USER_ACCESS_MANAGE)
x-undo:
operationId: DeleteRole
parameters:
- name: role_id
source: data.id
type: unsafe
/api/v2/roles/{role_id}/permissions:
delete:
description: Removes a permission from a role.
Expand Down
4 changes: 4 additions & 0 deletions api_docs/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ All URIs are relative to *https://api.datadoghq.com*
| _ProcessesApi_ | [**listProcesses**](ProcessesApi.md#listProcesses) | **GET** /api/v2/processes | Get all processes |
| _RolesApi_ | [**addPermissionToRole**](RolesApi.md#addPermissionToRole) | **POST** /api/v2/roles/{role_id}/permissions | Grant permission to a role |
| _RolesApi_ | [**addUserToRole**](RolesApi.md#addUserToRole) | **POST** /api/v2/roles/{role_id}/users | Add a user to a role |
| _RolesApi_ | [**cloneRole**](RolesApi.md#cloneRole) | **POST** /api/v2/roles/{role_id}/clone | Create a new role by cloning an existing role |
| _RolesApi_ | [**createRole**](RolesApi.md#createRole) | **POST** /api/v2/roles | Create role |
| _RolesApi_ | [**deleteRole**](RolesApi.md#deleteRole) | **DELETE** /api/v2/roles/{role_id} | Delete role |
| _RolesApi_ | [**getRole**](RolesApi.md#getRole) | **GET** /api/v2/roles/{role_id} | Get a role |
Expand Down Expand Up @@ -349,6 +350,9 @@ All URIs are relative to *https://api.datadoghq.com*
- [ResponseMetaAttributes](ResponseMetaAttributes.md)
- [Role](Role.md)
- [RoleAttributes](RoleAttributes.md)
- [RoleClone](RoleClone.md)
- [RoleCloneAttributes](RoleCloneAttributes.md)
- [RoleCloneRequest](RoleCloneRequest.md)
- [RoleCreateAttributes](RoleCreateAttributes.md)
- [RoleCreateData](RoleCreateData.md)
- [RoleCreateRequest](RoleCreateRequest.md)
Expand Down
15 changes: 15 additions & 0 deletions api_docs/v2/RoleClone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


# RoleClone

Data for the clone role request.

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**attributes** | [**RoleCloneAttributes**](RoleCloneAttributes.md) | |
**type** | **RolesType** | |



14 changes: 14 additions & 0 deletions api_docs/v2/RoleCloneAttributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


# RoleCloneAttributes

Attributes required to create a new role by cloning an existing one.

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**name** | **String** | Name of the new role that is cloned. |



14 changes: 14 additions & 0 deletions api_docs/v2/RoleCloneRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


# RoleCloneRequest

Request to create a role by cloning an existing role.

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**data** | [**RoleClone**](RoleClone.md) | |



97 changes: 83 additions & 14 deletions api_docs/v2/RolesApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

All URIs are relative to *https://api.datadoghq.com*

| Method | HTTP request | Description |
| -------------------------------------------------------------------- | ---------------------------------------------- | --------------------------- |
| [**addPermissionToRole**](RolesApi.md#addPermissionToRole) | **POST** /api/v2/roles/{role_id}/permissions | Grant permission to a role |
| [**addUserToRole**](RolesApi.md#addUserToRole) | **POST** /api/v2/roles/{role_id}/users | Add a user to a role |
| [**createRole**](RolesApi.md#createRole) | **POST** /api/v2/roles | Create role |
| [**deleteRole**](RolesApi.md#deleteRole) | **DELETE** /api/v2/roles/{role_id} | Delete role |
| [**getRole**](RolesApi.md#getRole) | **GET** /api/v2/roles/{role_id} | Get a role |
| [**listPermissions**](RolesApi.md#listPermissions) | **GET** /api/v2/permissions | List permissions |
| [**listRolePermissions**](RolesApi.md#listRolePermissions) | **GET** /api/v2/roles/{role_id}/permissions | List permissions for a role |
| [**listRoleUsers**](RolesApi.md#listRoleUsers) | **GET** /api/v2/roles/{role_id}/users | Get all users of a role |
| [**listRoles**](RolesApi.md#listRoles) | **GET** /api/v2/roles | List roles |
| [**removePermissionFromRole**](RolesApi.md#removePermissionFromRole) | **DELETE** /api/v2/roles/{role_id}/permissions | Revoke permission |
| [**removeUserFromRole**](RolesApi.md#removeUserFromRole) | **DELETE** /api/v2/roles/{role_id}/users | Remove a user from a role |
| [**updateRole**](RolesApi.md#updateRole) | **PATCH** /api/v2/roles/{role_id} | Update a role |
| Method | HTTP request | Description |
| -------------------------------------------------------------------- | ---------------------------------------------- | --------------------------------------------- |
| [**addPermissionToRole**](RolesApi.md#addPermissionToRole) | **POST** /api/v2/roles/{role_id}/permissions | Grant permission to a role |
| [**addUserToRole**](RolesApi.md#addUserToRole) | **POST** /api/v2/roles/{role_id}/users | Add a user to a role |
| [**cloneRole**](RolesApi.md#cloneRole) | **POST** /api/v2/roles/{role_id}/clone | Create a new role by cloning an existing role |
| [**createRole**](RolesApi.md#createRole) | **POST** /api/v2/roles | Create role |
| [**deleteRole**](RolesApi.md#deleteRole) | **DELETE** /api/v2/roles/{role_id} | Delete role |
| [**getRole**](RolesApi.md#getRole) | **GET** /api/v2/roles/{role_id} | Get a role |
| [**listPermissions**](RolesApi.md#listPermissions) | **GET** /api/v2/permissions | List permissions |
| [**listRolePermissions**](RolesApi.md#listRolePermissions) | **GET** /api/v2/roles/{role_id}/permissions | List permissions for a role |
| [**listRoleUsers**](RolesApi.md#listRoleUsers) | **GET** /api/v2/roles/{role_id}/users | Get all users of a role |
| [**listRoles**](RolesApi.md#listRoles) | **GET** /api/v2/roles | List roles |
| [**removePermissionFromRole**](RolesApi.md#removePermissionFromRole) | **DELETE** /api/v2/roles/{role_id}/permissions | Revoke permission |
| [**removeUserFromRole**](RolesApi.md#removeUserFromRole) | **DELETE** /api/v2/roles/{role_id}/users | Remove a user from a role |
| [**updateRole**](RolesApi.md#updateRole) | **PATCH** /api/v2/roles/{role_id} | Update a role |

## addPermissionToRole

Expand Down Expand Up @@ -151,6 +152,74 @@ public class Example {
| **404** | Not found | - |
| **429** | Too many requests | - |

## cloneRole

> RoleResponse cloneRole(roleId, body);

Clone an existing role

### Example

```java
import java.util.*;
import com.datadog.api.v2.client.ApiClient;
import com.datadog.api.v2.client.ApiException;
import com.datadog.api.v2.client.Configuration;
import com.datadog.api.v2.client.model.*;
import com.datadog.api.v2.client.api.RolesApi;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();

RolesApi apiInstance = new RolesApi(defaultClient);
String roleId = "roleId_example"; // String | The ID of the role.
RoleCloneRequest body = new RoleCloneRequest(); // RoleCloneRequest |
try {
RoleResponse result = apiInstance.cloneRole(roleId, body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling RolesApi#cloneRole");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
```

### Parameters

| Name | Type | Description | Notes |
| ---------- | ------------------------------------------- | ------------------- | ----- |
| **roleId** | **String** | The ID of the role. |
| **body** | [**RoleCloneRequest**](RoleCloneRequest.md) | |

### Return type

[**RoleResponse**](RoleResponse.md)

### Authorization

[AuthZ](README.md#AuthZ), [apiKeyAuth](README.md#apiKeyAuth), [appKeyAuth](README.md#appKeyAuth)

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json

### HTTP response details

| Status code | Description | Response headers |
| ----------- | -------------------- | ---------------- |
| **200** | OK | - |
| **400** | Bad Request | - |
| **403** | Authentication error | - |
| **404** | Not found | - |
| **409** | Conflict | - |
| **429** | Too many requests | - |

## createRole

> RoleCreateResponse createRole(body);
Expand Down
45 changes: 45 additions & 0 deletions examples/v2/roles/CloneRole.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Create a new role by cloning an existing role returns "OK" response

import com.datadog.api.v2.client.ApiClient;
import com.datadog.api.v2.client.ApiException;
import com.datadog.api.v2.client.Configuration;
import com.datadog.api.v2.client.api.RolesApi;
import com.datadog.api.v2.client.model.RoleClone;
import com.datadog.api.v2.client.model.RoleCloneAttributes;
import com.datadog.api.v2.client.model.RoleCloneRequest;
import com.datadog.api.v2.client.model.RoleResponse;
import com.datadog.api.v2.client.model.RolesType;
import java.time.*;
import java.util.*;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
RolesApi apiInstance = new RolesApi(defaultClient);

// there is a valid "role" in the system
String ROLE_DATA_ID = System.getenv("ROLE_DATA_ID");

RoleCloneRequest body =
new RoleCloneRequest()
.data(
new RoleClone()
.attributes(
new RoleCloneAttributes()
.name(
"Example-Create_a_new_role_by_cloning_an_existing_role_returns_OK_response"
+ " clone"))
.type(RolesType.ROLES));

try {
RoleResponse result = apiInstance.cloneRole(ROLE_DATA_ID, body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling DowntimesApi#updateDowntime");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Loading