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

Move Service account create from users to service accounts #1841

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.6.4",
"regenerated": "2023-02-01 12:21:07.288764",
"spec_repo_commit": "0563dbc3"
"regenerated": "2023-02-01 18:25:28.917567",
"spec_repo_commit": "a7d9eeca"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2023-02-01 12:21:07.303722",
"spec_repo_commit": "0563dbc3"
"regenerated": "2023-02-01 18:25:28.929658",
"spec_repo_commit": "a7d9eeca"
}
}
}
2 changes: 1 addition & 1 deletion .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19082,7 +19082,7 @@ paths:
$ref: '#/components/responses/TooManyRequestsResponse'
summary: Create a service account
tags:
- Users
- Service Accounts
x-codegen-request-body-name: body
/api/v2/service_accounts/{service_account_id}/application_keys:
get:
Expand Down
100 changes: 100 additions & 0 deletions api/datadogV2/api_service_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,106 @@ import (
// ServiceAccountsApi service type
type ServiceAccountsApi datadog.Service

type apiCreateServiceAccountRequest struct {
ctx _context.Context
body *ServiceAccountCreateRequest
}

func (a *ServiceAccountsApi) buildCreateServiceAccountRequest(ctx _context.Context, body ServiceAccountCreateRequest) (apiCreateServiceAccountRequest, error) {
req := apiCreateServiceAccountRequest{
ctx: ctx,
body: &body,
}
return req, nil
}

// CreateServiceAccount Create a service account.
// Create a service account for your organization.
func (a *ServiceAccountsApi) CreateServiceAccount(ctx _context.Context, body ServiceAccountCreateRequest) (UserResponse, *_nethttp.Response, error) {
req, err := a.buildCreateServiceAccountRequest(ctx, body)
if err != nil {
var localVarReturnValue UserResponse
return localVarReturnValue, nil, err
}

return a.createServiceAccountExecute(req)
}

// createServiceAccountExecute executes the request.
func (a *ServiceAccountsApi) createServiceAccountExecute(r apiCreateServiceAccountRequest) (UserResponse, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodPost
localVarPostBody interface{}
localVarReturnValue UserResponse
)

localBasePath, err := a.Client.Cfg.ServerURLWithContext(r.ctx, "v2.ServiceAccountsApi.CreateServiceAccount")
if err != nil {
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
}

localVarPath := localBasePath + "/api/v2/service_accounts"

localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
if r.body == nil {
return localVarReturnValue, nil, datadog.ReportError("body is required and must be specified")
}
localVarHeaderParams["Content-Type"] = "application/json"
localVarHeaderParams["Accept"] = "application/json"

// body params
localVarPostBody = r.body
datadog.SetAuthKeys(
r.ctx,
&localVarHeaderParams,
[2]string{"apiKeyAuth", "DD-API-KEY"},
[2]string{"appKeyAuth", "DD-APPLICATION-KEY"},
)
req, err := a.Client.PrepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil)
if err != nil {
return localVarReturnValue, nil, err
}

localVarHTTPResponse, err := a.Client.CallAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}

localVarBody, err := datadog.ReadBody(localVarHTTPResponse)
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}

if localVarHTTPResponse.StatusCode >= 300 {
newErr := datadog.GenericOpenAPIError{
ErrorBody: localVarBody,
ErrorMessage: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 429 {
var v APIErrorResponse
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.ErrorModel = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := datadog.GenericOpenAPIError{
ErrorBody: localVarBody,
ErrorMessage: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

return localVarReturnValue, localVarHTTPResponse, nil
}

type apiCreateServiceAccountApplicationKeyRequest struct {
ctx _context.Context
serviceAccountId string
Expand Down
100 changes: 0 additions & 100 deletions api/datadogV2/api_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,106 +16,6 @@ import (
// UsersApi service type
type UsersApi datadog.Service

type apiCreateServiceAccountRequest struct {
ctx _context.Context
body *ServiceAccountCreateRequest
}

func (a *UsersApi) buildCreateServiceAccountRequest(ctx _context.Context, body ServiceAccountCreateRequest) (apiCreateServiceAccountRequest, error) {
req := apiCreateServiceAccountRequest{
ctx: ctx,
body: &body,
}
return req, nil
}

// CreateServiceAccount Create a service account.
// Create a service account for your organization.
func (a *UsersApi) CreateServiceAccount(ctx _context.Context, body ServiceAccountCreateRequest) (UserResponse, *_nethttp.Response, error) {
req, err := a.buildCreateServiceAccountRequest(ctx, body)
if err != nil {
var localVarReturnValue UserResponse
return localVarReturnValue, nil, err
}

return a.createServiceAccountExecute(req)
}

// createServiceAccountExecute executes the request.
func (a *UsersApi) createServiceAccountExecute(r apiCreateServiceAccountRequest) (UserResponse, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodPost
localVarPostBody interface{}
localVarReturnValue UserResponse
)

localBasePath, err := a.Client.Cfg.ServerURLWithContext(r.ctx, "v2.UsersApi.CreateServiceAccount")
if err != nil {
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
}

localVarPath := localBasePath + "/api/v2/service_accounts"

localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
if r.body == nil {
return localVarReturnValue, nil, datadog.ReportError("body is required and must be specified")
}
localVarHeaderParams["Content-Type"] = "application/json"
localVarHeaderParams["Accept"] = "application/json"

// body params
localVarPostBody = r.body
datadog.SetAuthKeys(
r.ctx,
&localVarHeaderParams,
[2]string{"apiKeyAuth", "DD-API-KEY"},
[2]string{"appKeyAuth", "DD-APPLICATION-KEY"},
)
req, err := a.Client.PrepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil)
if err != nil {
return localVarReturnValue, nil, err
}

localVarHTTPResponse, err := a.Client.CallAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}

localVarBody, err := datadog.ReadBody(localVarHTTPResponse)
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}

if localVarHTTPResponse.StatusCode >= 300 {
newErr := datadog.GenericOpenAPIError{
ErrorBody: localVarBody,
ErrorMessage: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 429 {
var v APIErrorResponse
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.ErrorModel = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := datadog.GenericOpenAPIError{
ErrorBody: localVarBody,
ErrorMessage: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

return localVarReturnValue, localVarHTTPResponse, nil
}

type apiCreateUserRequest struct {
ctx _context.Context
body *UserCreateRequest
Expand Down
2 changes: 1 addition & 1 deletion api/datadogV2/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
// - [SensitiveDataScannerApi.ReorderScanningGroups]
// - [SensitiveDataScannerApi.UpdateScanningGroup]
// - [SensitiveDataScannerApi.UpdateScanningRule]
// - [ServiceAccountsApi.CreateServiceAccount]
// - [ServiceAccountsApi.CreateServiceAccountApplicationKey]
// - [ServiceAccountsApi.DeleteServiceAccountApplicationKey]
// - [ServiceAccountsApi.GetServiceAccountApplicationKey]
Expand All @@ -192,7 +193,6 @@
// - [UsageMeteringApi.GetUsageApplicationSecurityMonitoring]
// - [UsageMeteringApi.GetUsageLambdaTracedInvocations]
// - [UsageMeteringApi.GetUsageObservabilityPipelines]
// - [UsersApi.CreateServiceAccount]
// - [UsersApi.CreateUser]
// - [UsersApi.DisableUser]
// - [UsersApi.GetInvitation]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ func main() {
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewUsersApi(apiClient)
api := datadogV2.NewServiceAccountsApi(apiClient)
resp, r, err := api.CreateServiceAccount(ctx, body)

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `UsersApi.CreateServiceAccount`: %v\n", err)
fmt.Fprintf(os.Stderr, "Error when calling `ServiceAccountsApi.CreateServiceAccount`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}

responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `UsersApi.CreateServiceAccount`:\n%s\n", responseContent)
fmt.Fprintf(os.Stdout, "Response from `ServiceAccountsApi.CreateServiceAccount`:\n%s\n", responseContent)
}
2 changes: 1 addition & 1 deletion tests/scenarios/api_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ var apiMappings = map[string]map[string]reflect.Value{
"CloudWorkloadSecurityApi": reflect.ValueOf(datadogV2.NewCloudWorkloadSecurityApi),
"SecurityMonitoringApi": reflect.ValueOf(datadogV2.NewSecurityMonitoringApi),
"SensitiveDataScannerApi": reflect.ValueOf(datadogV2.NewSensitiveDataScannerApi),
"UsersApi": reflect.ValueOf(datadogV2.NewUsersApi),
"ServiceAccountsApi": reflect.ValueOf(datadogV2.NewServiceAccountsApi),
"IncidentServicesApi": reflect.ValueOf(datadogV2.NewIncidentServicesApi),
"ServiceDefinitionApi": reflect.ValueOf(datadogV2.NewServiceDefinitionApi),
"IncidentTeamsApi": reflect.ValueOf(datadogV2.NewIncidentTeamsApi),
"UsageMeteringApi": reflect.ValueOf(datadogV2.NewUsageMeteringApi),
"UsersApi": reflect.ValueOf(datadogV2.NewUsersApi),
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-01-30T14:58:54.329Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
interactions:
- request:
body: |
{"data":{"attributes":{"name":"Test-Create_a_service_account_returns_OK_response-1675090734"},"type":"roles"}}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: POST
url: https://api.datadoghq.com/api/v2/roles
response:
body: '{"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"}]}}}}

'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
- request:
body: |
{"data":{"attributes":{"email":"Test-Create_a_service_account_returns_OK_response-1675090734@datadoghq.com","name":"Test API Client","service_account":true},"relationships":{"roles":{"data":[{"id":"9d7c873e-a0ae-11ed-975e-da7ad0900002","type":"roles"}]}},"type":"users"}}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: POST
url: https://api.datadoghq.com/api/v2/service_accounts
response:
body: '{"data":{"type":"users","id":"9d9c0565-a0ae-11ed-88af-be56a8628f3f","attributes":{"name":"Test
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
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
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
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
Read","description":"View incidents in Datadog.","created":"2021-06-22T15:11:09.255499+00:00","group_name":"Case
and Incident Management","display_type":"read","restricted":true}},{"type":"permissions","id":"7605ef24-f376-11eb-b90b-da7ad0900002","attributes":{"name":"rum_apps_read","display_name":"RUM
Apps Read","description":"View RUM Applications data.","created":"2021-08-02T09:46:07.671535+00:00","group_name":"Real
User Monitoring","display_type":"read","restricted":true}},{"type":"permissions","id":"b6bf9ac6-9a59-11ec-8480-da7ad0900002","attributes":{"name":"notebooks_read","display_name":"Notebooks
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
Read","description":"View SLOs and status corrections.","created":"2022-06-08T16:20:55.142591+00:00","group_name":"Service
Level Objectives","display_type":"read","restricted":true}},{"type":"permissions","id":"6c5ad874-7aff-11ed-a5cd-da7ad0900002","attributes":{"name":"ci_visibility_read","display_name":"CI
Visibility Read","description":"View CI Visibility.","created":"2022-12-13T16:01:37.149406+00:00","group_name":"CI
Visibility","display_type":"read","restricted":true}}]}

'
code: 201
duration: ''
headers:
Content-Type:
- application/json
status: 201 Created
- request:
body: ''
form: {}
headers:
Accept:
- '*/*'
method: DELETE
url: https://api.datadoghq.com/api/v2/users/9d9c0565-a0ae-11ed-88af-be56a8628f3f
response:
body: ''
code: 204
duration: ''
headers: {}
status: 204 No Content
- request:
body: ''
form: {}
headers:
Accept:
- '*/*'
method: DELETE
url: https://api.datadoghq.com/api/v2/roles/9d7c873e-a0ae-11ed-975e-da7ad0900002
response:
body: ''
code: 204
duration: ''
headers:
Content-Type:
- text/html; charset=utf-8
status: 204 No Content
version: 1

This file was deleted.

Loading