Skip to content

Commit b6f8a8c

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Move Service account create from users to service accounts (#1313)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 2362296 commit b6f8a8c

File tree

11 files changed

+97
-87
lines changed

11 files changed

+97
-87
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.4",
7-
"regenerated": "2023-02-01 12:21:34.015810",
8-
"spec_repo_commit": "0563dbc3"
7+
"regenerated": "2023-02-01 18:26:09.487215",
8+
"spec_repo_commit": "a7d9eeca"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.4",
12-
"regenerated": "2023-02-01 12:21:34.027079",
13-
"spec_repo_commit": "0563dbc3"
12+
"regenerated": "2023-02-01 18:26:09.498749",
13+
"spec_repo_commit": "a7d9eeca"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19082,7 +19082,7 @@ paths:
1908219082
$ref: '#/components/responses/TooManyRequestsResponse'
1908319083
summary: Create a service account
1908419084
tags:
19085-
- Users
19085+
- Service Accounts
1908619086
x-codegen-request-body-name: body
1908719087
/api/v2/service_accounts/{service_account_id}/application_keys:
1908819088
get:

examples/v2/users/CreateServiceAccount.py renamed to examples/v2/service-accounts/CreateServiceAccount.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from os import environ
66
from datadog_api_client import ApiClient, Configuration
7-
from datadog_api_client.v2.api.users_api import UsersApi
7+
from datadog_api_client.v2.api.service_accounts_api import ServiceAccountsApi
88
from datadog_api_client.v2.model.relationship_to_role_data import RelationshipToRoleData
99
from datadog_api_client.v2.model.relationship_to_roles import RelationshipToRoles
1010
from datadog_api_client.v2.model.roles_type import RolesType
@@ -40,7 +40,7 @@
4040

4141
configuration = Configuration()
4242
with ApiClient(configuration) as api_client:
43-
api_instance = UsersApi(api_client)
43+
api_instance = ServiceAccountsApi(api_client)
4444
response = api_instance.create_service_account(body=body)
4545

4646
print(response)

src/datadog_api_client/v2/api/service_accounts_api.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
UnsetType,
1212
unset,
1313
)
14+
from datadog_api_client.v2.model.user_response import UserResponse
15+
from datadog_api_client.v2.model.service_account_create_request import ServiceAccountCreateRequest
1416
from datadog_api_client.v2.model.list_application_keys_response import ListApplicationKeysResponse
1517
from datadog_api_client.v2.model.application_keys_sort import ApplicationKeysSort
1618
from datadog_api_client.v2.model.application_key_response import ApplicationKeyResponse
@@ -29,6 +31,27 @@ def __init__(self, api_client=None):
2931
api_client = ApiClient(Configuration())
3032
self.api_client = api_client
3133

34+
self._create_service_account_endpoint = _Endpoint(
35+
settings={
36+
"response_type": (UserResponse,),
37+
"auth": ["apiKeyAuth", "appKeyAuth"],
38+
"endpoint_path": "/api/v2/service_accounts",
39+
"operation_id": "create_service_account",
40+
"http_method": "POST",
41+
"version": "v2",
42+
"servers": None,
43+
},
44+
params_map={
45+
"body": {
46+
"required": True,
47+
"openapi_types": (ServiceAccountCreateRequest,),
48+
"location": "body",
49+
},
50+
},
51+
headers_map={"accept": ["application/json"], "content_type": ["application/json"]},
52+
api_client=api_client,
53+
)
54+
3255
self._create_service_account_application_key_endpoint = _Endpoint(
3356
settings={
3457
"response_type": (ApplicationKeyResponse,),
@@ -206,6 +229,22 @@ def __init__(self, api_client=None):
206229
api_client=api_client,
207230
)
208231

232+
def create_service_account(
233+
self,
234+
body: ServiceAccountCreateRequest,
235+
) -> UserResponse:
236+
"""Create a service account.
237+
238+
Create a service account for your organization.
239+
240+
:type body: ServiceAccountCreateRequest
241+
:rtype: UserResponse
242+
"""
243+
kwargs: Dict[str, Any] = {}
244+
kwargs["body"] = body
245+
246+
return self._create_service_account_endpoint.call_with_http_info(**kwargs)
247+
209248
def create_service_account_application_key(
210249
self,
211250
service_account_id: str,

src/datadog_api_client/v2/api/users_api.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
UnsetType,
1212
unset,
1313
)
14-
from datadog_api_client.v2.model.user_response import UserResponse
15-
from datadog_api_client.v2.model.service_account_create_request import ServiceAccountCreateRequest
1614
from datadog_api_client.v2.model.user_invitations_response import UserInvitationsResponse
1715
from datadog_api_client.v2.model.user_invitations_request import UserInvitationsRequest
1816
from datadog_api_client.v2.model.user_invitation_response import UserInvitationResponse
1917
from datadog_api_client.v2.model.users_response import UsersResponse
2018
from datadog_api_client.v2.model.query_sort_order import QuerySortOrder
19+
from datadog_api_client.v2.model.user_response import UserResponse
2120
from datadog_api_client.v2.model.user_create_request import UserCreateRequest
2221
from datadog_api_client.v2.model.user_update_request import UserUpdateRequest
2322
from datadog_api_client.v2.model.permissions_response import PermissionsResponse
@@ -33,27 +32,6 @@ def __init__(self, api_client=None):
3332
api_client = ApiClient(Configuration())
3433
self.api_client = api_client
3534

36-
self._create_service_account_endpoint = _Endpoint(
37-
settings={
38-
"response_type": (UserResponse,),
39-
"auth": ["apiKeyAuth", "appKeyAuth"],
40-
"endpoint_path": "/api/v2/service_accounts",
41-
"operation_id": "create_service_account",
42-
"http_method": "POST",
43-
"version": "v2",
44-
"servers": None,
45-
},
46-
params_map={
47-
"body": {
48-
"required": True,
49-
"openapi_types": (ServiceAccountCreateRequest,),
50-
"location": "body",
51-
},
52-
},
53-
headers_map={"accept": ["application/json"], "content_type": ["application/json"]},
54-
api_client=api_client,
55-
)
56-
5735
self._create_user_endpoint = _Endpoint(
5836
settings={
5937
"response_type": (UserResponse,),
@@ -297,22 +275,6 @@ def __init__(self, api_client=None):
297275
api_client=api_client,
298276
)
299277

300-
def create_service_account(
301-
self,
302-
body: ServiceAccountCreateRequest,
303-
) -> UserResponse:
304-
"""Create a service account.
305-
306-
Create a service account for your organization.
307-
308-
:type body: ServiceAccountCreateRequest
309-
:rtype: UserResponse
310-
"""
311-
kwargs: Dict[str, Any] = {}
312-
kwargs["body"] = body
313-
314-
return self._create_service_account_endpoint.call_with_http_info(**kwargs)
315-
316278
def create_user(
317279
self,
318280
body: UserCreateRequest,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2022-05-12T09:53:33.281Z
1+
2023-01-30T14:58:54.329Z

tests/v2/cassettes/test_scenarios/test_create_a_service_account_returns_ok_response.yaml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
interactions:
22
- request:
3-
body: '{"data":{"attributes":{"name":"Test-Create_a_service_account_returns_OK_response-1652349213"},"type":"roles"}}'
3+
body: '{"data":{"attributes":{"name":"Test-Create_a_service_account_returns_OK_response-1675090734"},"type":"roles"}}'
44
headers:
55
accept:
66
- application/json
@@ -10,16 +10,18 @@ interactions:
1010
uri: https://api.datadoghq.com/api/v2/roles
1111
response:
1212
body:
13-
string: '{"data":{"type":"roles","id":"62caae30-d1d9-11ec-ad3d-da7ad0900002","attributes":{"name":"Test-Create_a_service_account_returns_OK_response-1652349213","created_at":"2022-05-12T09:53:33.719840+00:00","modified_at":"2022-05-12T09:53:33.777510+00:00"},"relationships":{"permissions":{"data":[{"type":"permissions","id":"d90f6830-d3d8-11e9-a77a-b3404e5e9ee2"},{"type":"permissions","id":"4441648c-d8b1-11e9-a77a-1b899a04b304"},{"type":"permissions","id":"417ba636-2dce-11eb-84c0-6bce5b0d9de0"},{"type":"permissions","id":"12efc20e-d36c-11eb-a9b8-da7ad0900002"},{"type":"permissions","id":"97971c1c-e895-11eb-b13c-da7ad0900002"},{"type":"permissions","id":"7605ef24-f376-11eb-b90b-da7ad0900002"},{"type":"permissions","id":"b6bf9ac6-9a59-11ec-8480-da7ad0900002"}]}}}}'
13+
string: '{"data":{"type":"roles","id":"9d7c873e-a0ae-11ed-975e-da7ad0900002","attributes":{"name":"Test-Create_a_service_account_returns_OK_response-1675090734","created_at":"2023-01-30T14:58:54.528421+00:00","modified_at":"2023-01-30T14:58:54.566829+00:00"},"relationships":{"permissions":{"data":[{"type":"permissions","id":"d90f6830-d3d8-11e9-a77a-b3404e5e9ee2"},{"type":"permissions","id":"4441648c-d8b1-11e9-a77a-1b899a04b304"},{"type":"permissions","id":"417ba636-2dce-11eb-84c0-6bce5b0d9de0"},{"type":"permissions","id":"12efc20e-d36c-11eb-a9b8-da7ad0900002"},{"type":"permissions","id":"7605ef24-f376-11eb-b90b-da7ad0900002"},{"type":"permissions","id":"b6bf9ac6-9a59-11ec-8480-da7ad0900002"},{"type":"permissions","id":"f8e941cf-e746-11ec-b22d-da7ad0900002"},{"type":"permissions","id":"6c5ad874-7aff-11ed-a5cd-da7ad0900002"}]}}}}
14+
15+
'
1416
headers:
1517
content-type:
1618
- application/json
1719
status:
1820
code: 200
1921
message: OK
2022
- request:
21-
body: '{"data":{"attributes":{"email":"Test-Create_a_service_account_returns_OK_response-1652349213@datadoghq.com","name":"Test
22-
API Client","service_account":true},"relationships":{"roles":{"data":[{"id":"62caae30-d1d9-11ec-ad3d-da7ad0900002","type":"roles"}]}},"type":"users"}}'
23+
body: '{"data":{"attributes":{"email":"Test-Create_a_service_account_returns_OK_response-1675090734@datadoghq.com","name":"Test
24+
API Client","service_account":true},"relationships":{"roles":{"data":[{"id":"9d7c873e-a0ae-11ed-975e-da7ad0900002","type":"roles"}]}},"type":"users"}}'
2325
headers:
2426
accept:
2527
- application/json
@@ -29,18 +31,22 @@ interactions:
2931
uri: https://api.datadoghq.com/api/v2/service_accounts
3032
response:
3133
body:
32-
string: '{"included":[{"type":"permissions","id":"7605ef24-f376-11eb-b90b-da7ad0900002","attributes":{"name":"rum_apps_read","display_name":"RUM
34+
string: '{"data":{"type":"users","id":"9d9c0565-a0ae-11ed-88af-be56a8628f3f","attributes":{"name":"Test
35+
API Client","handle":"9d9c0565-a0ae-11ed-88af-be56a8628f3f","created_at":"2023-01-30T14:58:54.736093+00:00","modified_at":"2023-01-30T14:58:54.738680+00:00","email":"test-create_a_service_account_returns_ok_response-1675090734@datadoghq.com","icon":"https://secure.gravatar.com/avatar/5bf68b66c63c55ddb80602fc2d183c28?s=48&d=retro","title":null,"verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active"},"relationships":{"roles":{"data":[{"type":"roles","id":"9d7c873e-a0ae-11ed-975e-da7ad0900002"}]},"org":{"data":{"type":"orgs","id":"4dee724d-00cc-11ea-a77b-570c9d03c6c5"}}}},"included":[{"type":"roles","id":"9d7c873e-a0ae-11ed-975e-da7ad0900002","attributes":{"name":"Test-Create_a_service_account_returns_OK_response-1675090734","created_at":"2023-01-30T14:58:54.528421+00:00","modified_at":"2023-01-30T14:58:54.566829+00:00"},"relationships":{"permissions":{"data":[{"type":"permissions","id":"d90f6830-d3d8-11e9-a77a-b3404e5e9ee2"},{"type":"permissions","id":"4441648c-d8b1-11e9-a77a-1b899a04b304"},{"type":"permissions","id":"417ba636-2dce-11eb-84c0-6bce5b0d9de0"},{"type":"permissions","id":"12efc20e-d36c-11eb-a9b8-da7ad0900002"},{"type":"permissions","id":"7605ef24-f376-11eb-b90b-da7ad0900002"},{"type":"permissions","id":"b6bf9ac6-9a59-11ec-8480-da7ad0900002"},{"type":"permissions","id":"f8e941cf-e746-11ec-b22d-da7ad0900002"},{"type":"permissions","id":"6c5ad874-7aff-11ed-a5cd-da7ad0900002"}]}}},{"type":"permissions","id":"d90f6830-d3d8-11e9-a77a-b3404e5e9ee2","attributes":{"name":"dashboards_read","display_name":"Dashboards
36+
Read","description":"View dashboards.","created":"2019-09-10T14:39:51.955175+00:00","group_name":"Dashboards","display_type":"read","restricted":true}},{"type":"permissions","id":"4441648c-d8b1-11e9-a77a-1b899a04b304","attributes":{"name":"monitors_read","display_name":"Monitors
37+
Read","description":"View monitors.","created":"2019-09-16T18:39:07.744297+00:00","group_name":"Monitors","display_type":"read","restricted":true}},{"type":"permissions","id":"417ba636-2dce-11eb-84c0-6bce5b0d9de0","attributes":{"name":"apm_read","display_name":"APM
38+
Read","description":"Read and query APM and Trace Analytics.","created":"2020-11-23T20:55:45.006110+00:00","group_name":"APM","display_type":"read","restricted":true}},{"type":"permissions","id":"12efc20e-d36c-11eb-a9b8-da7ad0900002","attributes":{"name":"incident_read","display_name":"Incident
39+
Read","description":"View incidents in Datadog.","created":"2021-06-22T15:11:09.255499+00:00","group_name":"Case
40+
and Incident Management","display_type":"read","restricted":true}},{"type":"permissions","id":"7605ef24-f376-11eb-b90b-da7ad0900002","attributes":{"name":"rum_apps_read","display_name":"RUM
3341
Apps Read","description":"View RUM Applications data.","created":"2021-08-02T09:46:07.671535+00:00","group_name":"Real
34-
User Monitoring","display_type":"read","restricted":true}},{"type":"permissions","id":"12efc20e-d36c-11eb-a9b8-da7ad0900002","attributes":{"name":"incident_read","display_name":"Incident
35-
Read","description":"View incidents in Datadog.","created":"2021-06-22T15:11:09.255499+00:00","group_name":"Incidents","display_type":"read","restricted":true}},{"type":"roles","id":"62caae30-d1d9-11ec-ad3d-da7ad0900002","attributes":{"name":"Test-Create_a_service_account_returns_OK_response-1652349213","created_at":"2022-05-12T09:53:33.719840+00:00","modified_at":"2022-05-12T09:53:33.777510+00:00"},"relationships":{"permissions":{"data":[{"type":"permissions","id":"d90f6830-d3d8-11e9-a77a-b3404e5e9ee2"},{"type":"permissions","id":"4441648c-d8b1-11e9-a77a-1b899a04b304"},{"type":"permissions","id":"417ba636-2dce-11eb-84c0-6bce5b0d9de0"},{"type":"permissions","id":"12efc20e-d36c-11eb-a9b8-da7ad0900002"},{"type":"permissions","id":"97971c1c-e895-11eb-b13c-da7ad0900002"},{"type":"permissions","id":"7605ef24-f376-11eb-b90b-da7ad0900002"},{"type":"permissions","id":"b6bf9ac6-9a59-11ec-8480-da7ad0900002"}]}}},{"type":"permissions","id":"97971c1c-e895-11eb-b13c-da7ad0900002","attributes":{"name":"appsec_event_rule_read","display_name":"Application
36-
Security Event Rules Read","description":"View Application Security Event
37-
Rules.","created":"2021-07-19T13:31:15.595771+00:00","group_name":"Cloud Security
38-
Platform","display_type":"read","restricted":true}},{"type":"permissions","id":"d90f6830-d3d8-11e9-a77a-b3404e5e9ee2","attributes":{"name":"dashboards_read","display_name":"Dashboards
39-
Read","description":"View dashboards.","created":"2019-09-10T14:39:51.955175+00:00","group_name":"Dashboards","display_type":"read","restricted":true}},{"type":"permissions","id":"417ba636-2dce-11eb-84c0-6bce5b0d9de0","attributes":{"name":"apm_read","display_name":"APM
40-
Read","description":"Read and query APM and Trace Analytics.","created":"2020-11-23T20:55:45.006110+00:00","group_name":"APM","display_type":"read","restricted":true}},{"type":"permissions","id":"b6bf9ac6-9a59-11ec-8480-da7ad0900002","attributes":{"name":"notebooks_read","display_name":"Notebooks
41-
Read","description":"View notebooks.","created":"2022-03-02T18:51:05.040950+00:00","group_name":"Notebooks","display_type":"read","restricted":true}},{"type":"permissions","id":"4441648c-d8b1-11e9-a77a-1b899a04b304","attributes":{"name":"monitors_read","display_name":"Monitors
42-
Read","description":"View monitors.","created":"2019-09-16T18:39:07.744297+00:00","group_name":"Monitors","display_type":"read","restricted":true}}],"data":{"type":"users","id":"1ee25455-00f0-41f0-bd0f-2844f17acbf0","attributes":{"name":"Test
43-
API Client","handle":"1ee25455-00f0-41f0-bd0f-2844f17acbf0","created_at":"2022-05-12T09:53:34.261663+00:00","modified_at":"2022-05-12T09:53:34.298254+00:00","email":"test-create_a_service_account_returns_ok_response-1652349213@datadoghq.com","icon":"https://secure.gravatar.com/avatar/2b603941f3590a948fbfeb4debfce25f?s=48&d=retro","title":null,"verified":true,"service_account":true,"disabled":false,"allowed_login_methods":[],"status":"Active"},"relationships":{"roles":{"data":[{"type":"roles","id":"62caae30-d1d9-11ec-ad3d-da7ad0900002"}]},"org":{"data":{"type":"orgs","id":"4dee724d-00cc-11ea-a77b-570c9d03c6c5"}}}}}'
42+
User Monitoring","display_type":"read","restricted":true}},{"type":"permissions","id":"b6bf9ac6-9a59-11ec-8480-da7ad0900002","attributes":{"name":"notebooks_read","display_name":"Notebooks
43+
Read","description":"View notebooks.","created":"2022-03-02T18:51:05.040950+00:00","group_name":"Notebooks","display_type":"read","restricted":true}},{"type":"permissions","id":"f8e941cf-e746-11ec-b22d-da7ad0900002","attributes":{"name":"slos_read","display_name":"SLOs
44+
Read","description":"View SLOs and status corrections.","created":"2022-06-08T16:20:55.142591+00:00","group_name":"Service
45+
Level Objectives","display_type":"read","restricted":true}},{"type":"permissions","id":"6c5ad874-7aff-11ed-a5cd-da7ad0900002","attributes":{"name":"ci_visibility_read","display_name":"CI
46+
Visibility Read","description":"View CI Visibility.","created":"2022-12-13T16:01:37.149406+00:00","group_name":"CI
47+
Visibility","display_type":"read","restricted":true}}]}
48+
49+
'
4450
headers:
4551
content-type:
4652
- application/json
@@ -53,7 +59,7 @@ interactions:
5359
accept:
5460
- '*/*'
5561
method: DELETE
56-
uri: https://api.datadoghq.com/api/v2/users/1ee25455-00f0-41f0-bd0f-2844f17acbf0
62+
uri: https://api.datadoghq.com/api/v2/users/9d9c0565-a0ae-11ed-88af-be56a8628f3f
5763
response:
5864
body:
5965
string: ''
@@ -67,11 +73,13 @@ interactions:
6773
accept:
6874
- '*/*'
6975
method: DELETE
70-
uri: https://api.datadoghq.com/api/v2/roles/62caae30-d1d9-11ec-ad3d-da7ad0900002
76+
uri: https://api.datadoghq.com/api/v2/roles/9d7c873e-a0ae-11ed-975e-da7ad0900002
7177
response:
7278
body:
7379
string: ''
74-
headers: {}
80+
headers:
81+
content-type:
82+
- text/html; charset=utf-8
7583
status:
7684
code: 204
7785
message: No Content

tests/v2/features/given.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
],
358358
"step": "there is a valid \"service_account_user\" in the system",
359359
"key": "service_account_user",
360-
"tag": "Users",
360+
"tag": "Service Accounts",
361361
"operationId": "CreateServiceAccount"
362362
},
363363
{

tests/v2/features/service_accounts.feature

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ Feature: Service Accounts
77
And a valid "appKeyAuth" key in the system
88
And an instance of "ServiceAccounts" API
99

10+
@generated @skip @team:DataDog/team-aaa
11+
Scenario: Create a service account returns "Bad Request" response
12+
Given new "CreateServiceAccount" request
13+
And body with value {"data": {"attributes": {"email": "[email protected]", "service_account": true}, "relationships": {"roles": {"data": [{"id": "3653d3c6-0c75-11ea-ad28-fb5701eabc7d", "type": "roles"}]}}, "type": "users"}}
14+
When the request is sent
15+
Then the response status is 400 Bad Request
16+
17+
@team:DataDog/team-aaa
18+
Scenario: Create a service account returns "OK" response
19+
Given there is a valid "role" in the system
20+
And new "CreateServiceAccount" request
21+
And body with value {"data": {"type": "users", "attributes": {"name": "Test API Client", "email": "{{ unique }}@datadoghq.com", "service_account": true}, "relationships": {"roles": {"data": [{"id": "{{ role.data.id }}", "type": "roles"}]}}}}
22+
When the request is sent
23+
Then the response status is 201 OK
24+
And the response "data.attributes.email" is equal to "{{ unique_lower }}@datadoghq.com"
25+
And the response "data.attributes.name" is equal to "Test API Client"
26+
And the response "data.attributes.disabled" is false
27+
And the response "data.attributes.service_account" is equal to true
28+
And the response "data.relationships.roles.data[0].id" is equal to "{{ role.data.id }}"
29+
1030
@team:DataDog/team-aaa
1131
Scenario: Create an app key for this service account returns "Created" response
1232
Given there is a valid "service_account_user" in the system

tests/v2/features/undo.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@
11401140
}
11411141
},
11421142
"CreateServiceAccount": {
1143-
"tag": "Users",
1143+
"tag": "Service Accounts",
11441144
"undo": {
11451145
"operationId": "DisableUser",
11461146
"parameters": [
@@ -1149,6 +1149,7 @@
11491149
"source": "data.id"
11501150
}
11511151
],
1152+
"tag": "Users",
11521153
"type": "unsafe"
11531154
}
11541155
},

0 commit comments

Comments
 (0)