Skip to content

Commit e786842

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Document /api/v2/roles/templates (DataDog#3390)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent fa9ab2a commit e786842

11 files changed

Lines changed: 686 additions & 0 deletions

File tree

.generator/schemas/v2/openapi.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38435,6 +38435,49 @@ components:
3843538435
permissions:
3843638436
$ref: '#/components/schemas/RelationshipToPermissions'
3843738437
type: object
38438+
RoleTemplateArray:
38439+
description: The definition of `RoleTemplateArray` object.
38440+
properties:
38441+
data:
38442+
description: The `RoleTemplateArray` `data`.
38443+
items:
38444+
$ref: '#/components/schemas/RoleTemplateData'
38445+
type: array
38446+
required:
38447+
- data
38448+
type: object
38449+
RoleTemplateData:
38450+
description: The definition of `RoleTemplateData` object.
38451+
properties:
38452+
attributes:
38453+
$ref: '#/components/schemas/RoleTemplateDataAttributes'
38454+
id:
38455+
description: The `RoleTemplateData` `id`.
38456+
type: string
38457+
type:
38458+
$ref: '#/components/schemas/RoleTemplateDataType'
38459+
required:
38460+
- type
38461+
type: object
38462+
RoleTemplateDataAttributes:
38463+
description: The definition of `RoleTemplateDataAttributes` object.
38464+
properties:
38465+
description:
38466+
description: The `attributes` `description`.
38467+
type: string
38468+
name:
38469+
description: The `attributes` `name`.
38470+
type: string
38471+
type: object
38472+
RoleTemplateDataType:
38473+
default: roles
38474+
description: Roles resource type.
38475+
enum:
38476+
- roles
38477+
example: roles
38478+
type: string
38479+
x-enum-varnames:
38480+
- ROLES
3843838481
RoleUpdateAttributes:
3843938482
description: Attributes of the role.
3844038483
properties:
@@ -67658,6 +67701,28 @@ paths:
6765867701
operator: OR
6765967702
permissions:
6766067703
- user_access_manage
67704+
/api/v2/roles/templates:
67705+
get:
67706+
description: List all role templates
67707+
operationId: ListRoleTemplates
67708+
responses:
67709+
'200':
67710+
content:
67711+
application/json:
67712+
schema:
67713+
$ref: '#/components/schemas/RoleTemplateArray'
67714+
description: OK
67715+
'429':
67716+
$ref: '#/components/responses/TooManyRequestsResponse'
67717+
security:
67718+
- apiKeyAuth: []
67719+
appKeyAuth: []
67720+
- AuthZ:
67721+
- user_access_read
67722+
summary: List role templates
67723+
tags:
67724+
- Roles
67725+
x-unstable: '**Note**: This endpoint may be subject to changes.'
6766167726
/api/v2/roles/{role_id}:
6766267727
delete:
6766367728
description: Disables a role.

api/datadog/configuration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ func NewConfiguration() *Configuration {
674674
"v2.UpdateMonitorUserTemplate": false,
675675
"v2.ValidateExistingMonitorUserTemplate": false,
676676
"v2.ValidateMonitorUserTemplate": false,
677+
"v2.ListRoleTemplates": false,
677678
"v2.CreatePipeline": false,
678679
"v2.DeletePipeline": false,
679680
"v2.GetPipeline": false,

api/datadogV2/api_roles.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package datadogV2
66

77
import (
88
_context "context"
9+
_fmt "fmt"
10+
_log "log"
911
_nethttp "net/http"
1012
_neturl "net/url"
1113

@@ -639,6 +641,92 @@ func (a *RolesApi) ListRolePermissions(ctx _context.Context, roleId string) (Per
639641
return localVarReturnValue, localVarHTTPResponse, nil
640642
}
641643

644+
// ListRoleTemplates List role templates.
645+
// List all role templates
646+
func (a *RolesApi) ListRoleTemplates(ctx _context.Context) (RoleTemplateArray, *_nethttp.Response, error) {
647+
var (
648+
localVarHTTPMethod = _nethttp.MethodGet
649+
localVarPostBody interface{}
650+
localVarReturnValue RoleTemplateArray
651+
)
652+
653+
operationId := "v2.ListRoleTemplates"
654+
isOperationEnabled := a.Client.Cfg.IsUnstableOperationEnabled(operationId)
655+
if !isOperationEnabled {
656+
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)}
657+
}
658+
if isOperationEnabled && a.Client.Cfg.Debug {
659+
_log.Printf("WARNING: Using unstable operation '%s'", operationId)
660+
}
661+
662+
localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.RolesApi.ListRoleTemplates")
663+
if err != nil {
664+
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
665+
}
666+
667+
localVarPath := localBasePath + "/api/v2/roles/templates"
668+
669+
localVarHeaderParams := make(map[string]string)
670+
localVarQueryParams := _neturl.Values{}
671+
localVarFormParams := _neturl.Values{}
672+
localVarHeaderParams["Accept"] = "application/json"
673+
674+
if a.Client.Cfg.DelegatedTokenConfig != nil {
675+
err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig)
676+
if err != nil {
677+
return localVarReturnValue, nil, err
678+
}
679+
} else {
680+
datadog.SetAuthKeys(
681+
ctx,
682+
&localVarHeaderParams,
683+
[2]string{"apiKeyAuth", "DD-API-KEY"},
684+
[2]string{"appKeyAuth", "DD-APPLICATION-KEY"},
685+
)
686+
}
687+
req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil)
688+
if err != nil {
689+
return localVarReturnValue, nil, err
690+
}
691+
692+
localVarHTTPResponse, err := a.Client.CallAPI(req)
693+
if err != nil || localVarHTTPResponse == nil {
694+
return localVarReturnValue, localVarHTTPResponse, err
695+
}
696+
697+
localVarBody, err := datadog.ReadBody(localVarHTTPResponse)
698+
if err != nil {
699+
return localVarReturnValue, localVarHTTPResponse, err
700+
}
701+
702+
if localVarHTTPResponse.StatusCode >= 300 {
703+
newErr := datadog.GenericOpenAPIError{
704+
ErrorBody: localVarBody,
705+
ErrorMessage: localVarHTTPResponse.Status,
706+
}
707+
if localVarHTTPResponse.StatusCode == 429 {
708+
var v APIErrorResponse
709+
err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
710+
if err != nil {
711+
return localVarReturnValue, localVarHTTPResponse, newErr
712+
}
713+
newErr.ErrorModel = v
714+
}
715+
return localVarReturnValue, localVarHTTPResponse, newErr
716+
}
717+
718+
err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
719+
if err != nil {
720+
newErr := datadog.GenericOpenAPIError{
721+
ErrorBody: localVarBody,
722+
ErrorMessage: err.Error(),
723+
}
724+
return localVarReturnValue, localVarHTTPResponse, newErr
725+
}
726+
727+
return localVarReturnValue, localVarHTTPResponse, nil
728+
}
729+
642730
// ListRoleUsersOptionalParameters holds optional parameters for ListRoleUsers.
643731
type ListRoleUsersOptionalParameters struct {
644732
PageSize *int64

api/datadogV2/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@
430430
// - [RolesApi.GetRole]
431431
// - [RolesApi.ListPermissions]
432432
// - [RolesApi.ListRolePermissions]
433+
// - [RolesApi.ListRoleTemplates]
433434
// - [RolesApi.ListRoleUsers]
434435
// - [RolesApi.ListRoles]
435436
// - [RolesApi.RemovePermissionFromRole]
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
3+
// Copyright 2019-Present Datadog, Inc.
4+
5+
package datadogV2
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
11+
)
12+
13+
// RoleTemplateArray The definition of `RoleTemplateArray` object.
14+
type RoleTemplateArray struct {
15+
// The `RoleTemplateArray` `data`.
16+
Data []RoleTemplateData `json:"data"`
17+
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
18+
UnparsedObject map[string]interface{} `json:"-"`
19+
AdditionalProperties map[string]interface{} `json:"-"`
20+
}
21+
22+
// NewRoleTemplateArray instantiates a new RoleTemplateArray object.
23+
// This constructor will assign default values to properties that have it defined,
24+
// and makes sure properties required by API are set, but the set of arguments
25+
// will change when the set of required properties is changed.
26+
func NewRoleTemplateArray(data []RoleTemplateData) *RoleTemplateArray {
27+
this := RoleTemplateArray{}
28+
this.Data = data
29+
return &this
30+
}
31+
32+
// NewRoleTemplateArrayWithDefaults instantiates a new RoleTemplateArray object.
33+
// This constructor will only assign default values to properties that have it defined,
34+
// but it doesn't guarantee that properties required by API are set.
35+
func NewRoleTemplateArrayWithDefaults() *RoleTemplateArray {
36+
this := RoleTemplateArray{}
37+
return &this
38+
}
39+
40+
// GetData returns the Data field value.
41+
func (o *RoleTemplateArray) GetData() []RoleTemplateData {
42+
if o == nil {
43+
var ret []RoleTemplateData
44+
return ret
45+
}
46+
return o.Data
47+
}
48+
49+
// GetDataOk returns a tuple with the Data field value
50+
// and a boolean to check if the value has been set.
51+
func (o *RoleTemplateArray) GetDataOk() (*[]RoleTemplateData, bool) {
52+
if o == nil {
53+
return nil, false
54+
}
55+
return &o.Data, true
56+
}
57+
58+
// SetData sets field value.
59+
func (o *RoleTemplateArray) SetData(v []RoleTemplateData) {
60+
o.Data = v
61+
}
62+
63+
// MarshalJSON serializes the struct using spec logic.
64+
func (o RoleTemplateArray) MarshalJSON() ([]byte, error) {
65+
toSerialize := map[string]interface{}{}
66+
if o.UnparsedObject != nil {
67+
return datadog.Marshal(o.UnparsedObject)
68+
}
69+
toSerialize["data"] = o.Data
70+
71+
for key, value := range o.AdditionalProperties {
72+
toSerialize[key] = value
73+
}
74+
return datadog.Marshal(toSerialize)
75+
}
76+
77+
// UnmarshalJSON deserializes the given payload.
78+
func (o *RoleTemplateArray) UnmarshalJSON(bytes []byte) (err error) {
79+
all := struct {
80+
Data *[]RoleTemplateData `json:"data"`
81+
}{}
82+
if err = datadog.Unmarshal(bytes, &all); err != nil {
83+
return datadog.Unmarshal(bytes, &o.UnparsedObject)
84+
}
85+
if all.Data == nil {
86+
return fmt.Errorf("required field data missing")
87+
}
88+
additionalProperties := make(map[string]interface{})
89+
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
90+
datadog.DeleteKeys(additionalProperties, &[]string{"data"})
91+
} else {
92+
return err
93+
}
94+
o.Data = *all.Data
95+
96+
if len(additionalProperties) > 0 {
97+
o.AdditionalProperties = additionalProperties
98+
}
99+
100+
return nil
101+
}

0 commit comments

Comments
 (0)