diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index d9c6aa1ce1f1..8e5da58d0b6e 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -81676,55 +81676,57 @@ components: description: Attributes of user object returned by the API. properties: created_at: - description: Creation time of the user. + description: The ISO 8601 timestamp of when the user account was created. format: date-time type: string disabled: - description: Whether the user is disabled. + description: Whether the user account is deactivated. Disabled users cannot log in. type: boolean email: - description: Email of the user. + description: The email address of the user, used for login and notifications. type: string handle: - description: Handle of the user. + description: The unique handle (username) of the user, typically matching their email prefix. type: string icon: - description: URL of the user's icon. + description: URL of the user's profile icon, typically a Gravatar URL derived from the email address. type: string last_login_time: - description: The last time the user logged in. + description: The ISO 8601 timestamp of the user's most recent login, or null if the user has never logged in. format: date-time nullable: true readOnly: true type: string mfa_enabled: - description: If user has MFA enabled. + description: Whether multi-factor authentication (MFA) is enabled for the user's account. readOnly: true type: boolean modified_at: - description: Time that the user was last modified. + description: The ISO 8601 timestamp of when the user account was last modified. format: date-time type: string name: - description: Name of the user. + description: The full display name of the user as shown in the Datadog UI. nullable: true type: string service_account: - description: Whether the user is a service account. + description: |- + Whether this is a service account rather than a human user. + Service accounts are used for programmatic API access. type: boolean status: - description: Status of the user. + description: The current status of the user account (for example, `Active`, `Pending`, or `Disabled`). type: string title: - description: Title of the user. + description: The job title of the user (for example, "Senior Engineer" or "Product Manager"). nullable: true type: string uuid: - description: UUID of the user. + description: The globally unique identifier (UUID) of the user. readOnly: true type: string verified: - description: Whether the user is verified. + description: Whether the user's email address has been verified. type: boolean type: object UserAttributesStatus: @@ -82126,13 +82128,23 @@ components: description: Attributes of the edited user. properties: disabled: - description: If the user is enabled or disabled. + description: |- + When set to `true`, the user is deactivated and can no longer log in. + When `false`, the user is active. type: boolean email: - description: The email of the user. + description: |- + The email address of the user, used for login and notifications. + Must be a valid email format. type: string name: - description: The name of the user. + description: |- + The full display name of the user as shown in the Datadog UI. + Maximum 55 characters, cannot contain `<` or `>`. + type: string + title: + description: The job title of the user (for example, "Senior Engineer" or "Product Manager"). + nullable: true type: string type: object UserUpdateData: @@ -96994,6 +97006,144 @@ paths: $ref: "#/components/responses/TooManyRequestsResponse" summary: Get all CSM Serverless Agents tags: ["CSM Agents"] + /api/v2/current_user: + get: + description: |- + Get the user associated with the current authentication context. + The response includes the user's profile attributes (name, email, handle, + status, MFA state), along with related resources: the user's organization, + assigned roles with their granted permissions, and team-scoped roles. + No additional permissions are required beyond valid authentication. + operationId: GetCurrentUser + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + created_at: "2024-01-15T10:30:00+00:00" + disabled: false + email: jane.doe@example.com + handle: jane.doe + icon: "https://secure.gravatar.com/avatar/abc123" + mfa_enabled: true + modified_at: "2024-06-01T12:00:00+00:00" + name: Jane Doe + service_account: false + status: Active + title: Senior Engineer + verified: true + id: 00000000-0000-9999-0000-000000000000 + type: users + included: [] + schema: + $ref: "#/components/schemas/UserResponse" + description: OK + "403": + content: + application/json: + schema: + $ref: "#/components/schemas/APIErrorResponse" + description: Authentication error + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + summary: Get current user + tags: + - Users + patch: + description: |- + Edit the profile of the currently authenticated user. Updatable fields + include `name`, `title`, `email`, and `disabled` status. The `id` field + in the request body must match the authenticated user's UUID; a mismatch + returns a 422 error. Email address changes are recorded in the audit trail. + Requires the `user_self_profile_write` permission. + operationId: UpdateCurrentUser + requestBody: + content: + application/json: + examples: + default: + value: + data: + attributes: + email: jane.doe@example.com + name: Jane Doe + title: Staff Engineer + id: 00000000-0000-9999-0000-000000000000 + type: users + schema: + $ref: "#/components/schemas/UserUpdateRequest" + required: true + responses: + "200": + content: + application/json: + examples: + default: + value: + data: + attributes: + created_at: "2024-01-15T10:30:00+00:00" + disabled: false + email: jane.doe@example.com + handle: jane.doe + icon: "https://secure.gravatar.com/avatar/abc123" + mfa_enabled: true + modified_at: "2024-06-01T12:00:00+00:00" + name: Jane Doe + service_account: false + status: Active + title: Staff Engineer + verified: true + id: 00000000-0000-9999-0000-000000000000 + type: users + included: [] + schema: + $ref: "#/components/schemas/UserResponse" + 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 + "422": + content: + application/json: + schema: + $ref: "#/components/schemas/APIErrorResponse" + description: Unprocessable Entity + "429": + $ref: "#/components/responses/TooManyRequestsResponse" + security: + - apiKeyAuth: [] + appKeyAuth: [] + summary: Update current user + tags: + - Users + x-codegen-request-body-name: body + "x-permission": + operator: OR + permissions: + - user_self_profile_write /api/v2/current_user/application_keys: get: description: List all application keys available for current user diff --git a/examples/v2/users/GetCurrentUser.rb b/examples/v2/users/GetCurrentUser.rb new file mode 100644 index 000000000000..624cfafea1f6 --- /dev/null +++ b/examples/v2/users/GetCurrentUser.rb @@ -0,0 +1,5 @@ +# Get current user returns "OK" response + +require "datadog_api_client" +api_instance = DatadogAPIClient::V2::UsersAPI.new +p api_instance.get_current_user() diff --git a/examples/v2/users/UpdateCurrentUser.rb b/examples/v2/users/UpdateCurrentUser.rb new file mode 100644 index 000000000000..de8e99dceb36 --- /dev/null +++ b/examples/v2/users/UpdateCurrentUser.rb @@ -0,0 +1,15 @@ +# Update current user returns "OK" response + +require "datadog_api_client" +api_instance = DatadogAPIClient::V2::UsersAPI.new + +body = DatadogAPIClient::V2::UserUpdateRequest.new({ + data: DatadogAPIClient::V2::UserUpdateData.new({ + attributes: DatadogAPIClient::V2::UserUpdateAttributes.new({ + title: nil, + }), + id: "00000000-0000-feed-0000-000000000000", + type: DatadogAPIClient::V2::UsersType::USERS, + }), +}) +p api_instance.update_current_user(body) diff --git a/features/scenarios_model_mapping.rb b/features/scenarios_model_mapping.rb index 2845caa14151..dfd972fe94af 100644 --- a/features/scenarios_model_mapping.rb +++ b/features/scenarios_model_mapping.rb @@ -1141,6 +1141,9 @@ "v2.AnonymizeUsers" => { "body" => "AnonymizeUsersRequest", }, + "v2.UpdateCurrentUser" => { + "body" => "UserUpdateRequest", + }, "v2.SendInvitations" => { "body" => "UserInvitationsRequest", }, diff --git a/features/v2/undo.json b/features/v2/undo.json index b09c0b4eb02a..8b88a21bedae 100644 --- a/features/v2/undo.json +++ b/features/v2/undo.json @@ -1506,6 +1506,19 @@ "type": "safe" } }, + "GetCurrentUser": { + "tag": "Users", + "undo": { + "type": "safe" + } + }, + "UpdateCurrentUser": { + "tag": "Users", + "undo": { + "operationId": "GetCurrentUser", + "type": "idempotent" + } + }, "ListCurrentUserApplicationKeys": { "tag": "Key Management", "undo": { diff --git a/features/v2/users.feature b/features/v2/users.feature index 2fee7ffedcef..9d9fa4896358 100644 --- a/features/v2/users.feature +++ b/features/v2/users.feature @@ -118,6 +118,12 @@ Feature: Users Then the response status is 200 OK And the response "data" has length 0 + @generated @skip @team:DataDog/org-management + Scenario: Get current user returns "OK" response + Given new "GetCurrentUser" request + When the request is sent + Then the response status is 200 OK + @generated @skip @team:DataDog/org-management Scenario: Get user details returns "Not found" response Given new "GetUser" request @@ -181,7 +187,7 @@ Feature: Users Scenario: Update a user returns "Bad Request" response Given new "UpdateUser" request And request contains "user_id" parameter from "REPLACE.ME" - And body with value {"data": {"attributes": {}, "id": "00000000-0000-feed-0000-000000000000", "type": "users"}} + And body with value {"data": {"attributes": {"title": null}, "id": "00000000-0000-feed-0000-000000000000", "type": "users"}} When the request is sent Then the response status is 400 Bad Request @@ -219,6 +225,34 @@ Feature: Users Scenario: Update a user returns "Unprocessable Entity" response Given new "UpdateUser" request And request contains "user_id" parameter from "REPLACE.ME" - And body with value {"data": {"attributes": {}, "id": "00000000-0000-feed-0000-000000000000", "type": "users"}} + And body with value {"data": {"attributes": {"title": null}, "id": "00000000-0000-feed-0000-000000000000", "type": "users"}} + When the request is sent + Then the response status is 422 Unprocessable Entity + + @generated @skip @team:DataDog/org-management + Scenario: Update current user returns "Bad Request" response + Given new "UpdateCurrentUser" request + And body with value {"data": {"attributes": {"title": null}, "id": "00000000-0000-feed-0000-000000000000", "type": "users"}} + When the request is sent + Then the response status is 400 Bad Request + + @generated @skip @team:DataDog/org-management + Scenario: Update current user returns "Not found" response + Given new "UpdateCurrentUser" request + And body with value {"data": {"attributes": {"title": null}, "id": "00000000-0000-feed-0000-000000000000", "type": "users"}} + When the request is sent + Then the response status is 404 Not found + + @generated @skip @team:DataDog/org-management + Scenario: Update current user returns "OK" response + Given new "UpdateCurrentUser" request + And body with value {"data": {"attributes": {"title": null}, "id": "00000000-0000-feed-0000-000000000000", "type": "users"}} + When the request is sent + Then the response status is 200 OK + + @generated @skip @team:DataDog/org-management + Scenario: Update current user returns "Unprocessable Entity" response + Given new "UpdateCurrentUser" request + And body with value {"data": {"attributes": {"title": null}, "id": "00000000-0000-feed-0000-000000000000", "type": "users"}} When the request is sent Then the response status is 422 Unprocessable Entity diff --git a/lib/datadog_api_client/v2/api/users_api.rb b/lib/datadog_api_client/v2/api/users_api.rb index 50e2fefa27ef..489e0c333b7d 100644 --- a/lib/datadog_api_client/v2/api/users_api.rb +++ b/lib/datadog_api_client/v2/api/users_api.rb @@ -296,6 +296,70 @@ def disable_user_with_http_info(user_id, opts = {}) return data, status_code, headers end + # Get current user. + # + # @see #get_current_user_with_http_info + def get_current_user(opts = {}) + data, _status_code, _headers = get_current_user_with_http_info(opts) + data + end + + # Get current user. + # + # Get the user associated with the current authentication context. + # The response includes the user's profile attributes (name, email, handle, + # status, MFA state), along with related resources: the user's organization, + # assigned roles with their granted permissions, and team-scoped roles. + # No additional permissions are required beyond valid authentication. + # + # @param opts [Hash] the optional parameters + # @return [Array<(UserResponse, Integer, Hash)>] UserResponse data, response status code and response headers + def get_current_user_with_http_info(opts = {}) + + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: UsersAPI.get_current_user ...' + end + # resource path + local_var_path = '/api/v2/current_user' + + # query parameters + query_params = opts[:query_params] || {} + + # header parameters + header_params = opts[:header_params] || {} + # HTTP header 'Accept' (if needed) + header_params['Accept'] = @api_client.select_header_accept(['application/json']) + + # form parameters + form_params = opts[:form_params] || {} + + # http body (model) + post_body = opts[:debug_body] + + # return_type + return_type = opts[:debug_return_type] || 'UserResponse' + + # auth_names + auth_names = opts[:debug_auth_names] || [:apiKeyAuth, :appKeyAuth] + + new_options = opts.merge( + :operation => :get_current_user, + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names, + :return_type => return_type, + :api_version => "V2" + ) + + data, status_code, headers = @api_client.call_api(Net::HTTP::Get, local_var_path, new_options) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: UsersAPI#get_current_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + # Get a user invitation. # # @see #get_invitation_with_http_info @@ -724,6 +788,77 @@ def send_invitations_with_http_info(body, opts = {}) return data, status_code, headers end + # Update current user. + # + # @see #update_current_user_with_http_info + def update_current_user(body, opts = {}) + data, _status_code, _headers = update_current_user_with_http_info(body, opts) + data + end + + # Update current user. + # + # Edit the profile of the currently authenticated user. Updatable fields + # include `name`, `title`, `email`, and `disabled` status. The `id` field + # in the request body must match the authenticated user's UUID; a mismatch + # returns a 422 error. Email address changes are recorded in the audit trail. + # Requires the `user_self_profile_write` permission. + # + # @param body [UserUpdateRequest] + # @param opts [Hash] the optional parameters + # @return [Array<(UserResponse, Integer, Hash)>] UserResponse data, response status code and response headers + def update_current_user_with_http_info(body, opts = {}) + + if @api_client.config.debugging + @api_client.config.logger.debug 'Calling API: UsersAPI.update_current_user ...' + end + # verify the required parameter 'body' is set + if @api_client.config.client_side_validation && body.nil? + fail ArgumentError, "Missing the required parameter 'body' when calling UsersAPI.update_current_user" + end + # resource path + local_var_path = '/api/v2/current_user' + + # query parameters + query_params = opts[:query_params] || {} + + # header parameters + header_params = opts[:header_params] || {} + # HTTP header 'Accept' (if needed) + header_params['Accept'] = @api_client.select_header_accept(['application/json']) + # HTTP header 'Content-Type' + header_params['Content-Type'] = @api_client.select_header_content_type(['application/json']) + + # form parameters + form_params = opts[:form_params] || {} + + # http body (model) + post_body = opts[:debug_body] || @api_client.object_to_http_body(body) + + # return_type + return_type = opts[:debug_return_type] || 'UserResponse' + + # auth_names + auth_names = opts[:debug_auth_names] || [:apiKeyAuth, :appKeyAuth] + + new_options = opts.merge( + :operation => :update_current_user, + :header_params => header_params, + :query_params => query_params, + :form_params => form_params, + :body => post_body, + :auth_names => auth_names, + :return_type => return_type, + :api_version => "V2" + ) + + data, status_code, headers = @api_client.call_api(Net::HTTP::Patch, local_var_path, new_options) + if @api_client.config.debugging + @api_client.config.logger.debug "API called: UsersAPI#update_current_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" + end + return data, status_code, headers + end + # Update a user. # # @see #update_user_with_http_info diff --git a/lib/datadog_api_client/v2/models/user_attributes.rb b/lib/datadog_api_client/v2/models/user_attributes.rb index f15a2014c001..2bee6b32bd83 100644 --- a/lib/datadog_api_client/v2/models/user_attributes.rb +++ b/lib/datadog_api_client/v2/models/user_attributes.rb @@ -21,46 +21,47 @@ module DatadogAPIClient::V2 class UserAttributes include BaseGenericModel - # Creation time of the user. + # The ISO 8601 timestamp of when the user account was created. attr_accessor :created_at - # Whether the user is disabled. + # Whether the user account is deactivated. Disabled users cannot log in. attr_accessor :disabled - # Email of the user. + # The email address of the user, used for login and notifications. attr_accessor :email - # Handle of the user. + # The unique handle (username) of the user, typically matching their email prefix. attr_accessor :handle - # URL of the user's icon. + # URL of the user's profile icon, typically a Gravatar URL derived from the email address. attr_accessor :icon - # The last time the user logged in. + # The ISO 8601 timestamp of the user's most recent login, or null if the user has never logged in. attr_accessor :last_login_time - # If user has MFA enabled. + # Whether multi-factor authentication (MFA) is enabled for the user's account. attr_accessor :mfa_enabled - # Time that the user was last modified. + # The ISO 8601 timestamp of when the user account was last modified. attr_accessor :modified_at - # Name of the user. + # The full display name of the user as shown in the Datadog UI. attr_accessor :name - # Whether the user is a service account. + # Whether this is a service account rather than a human user. + # Service accounts are used for programmatic API access. attr_accessor :service_account - # Status of the user. + # The current status of the user account (for example, `Active`, `Pending`, or `Disabled`). attr_accessor :status - # Title of the user. + # The job title of the user (for example, "Senior Engineer" or "Product Manager"). attr_accessor :title - # UUID of the user. + # The globally unique identifier (UUID) of the user. attr_accessor :uuid - # Whether the user is verified. + # Whether the user's email address has been verified. attr_accessor :verified attr_accessor :additional_properties diff --git a/lib/datadog_api_client/v2/models/user_update_attributes.rb b/lib/datadog_api_client/v2/models/user_update_attributes.rb index 393e1e27b4a6..c16e3e8a690a 100644 --- a/lib/datadog_api_client/v2/models/user_update_attributes.rb +++ b/lib/datadog_api_client/v2/models/user_update_attributes.rb @@ -21,15 +21,21 @@ module DatadogAPIClient::V2 class UserUpdateAttributes include BaseGenericModel - # If the user is enabled or disabled. + # When set to `true`, the user is deactivated and can no longer log in. + # When `false`, the user is active. attr_accessor :disabled - # The email of the user. + # The email address of the user, used for login and notifications. + # Must be a valid email format. attr_accessor :email - # The name of the user. + # The full display name of the user as shown in the Datadog UI. + # Maximum 55 characters, cannot contain `<` or `>`. attr_accessor :name + # The job title of the user (for example, "Senior Engineer" or "Product Manager"). + attr_accessor :title + attr_accessor :additional_properties # Attribute mapping from ruby-style variable name to JSON key. @@ -38,7 +44,8 @@ def self.attribute_map { :'disabled' => :'disabled', :'email' => :'email', - :'name' => :'name' + :'name' => :'name', + :'title' => :'title' } end @@ -48,10 +55,19 @@ def self.openapi_types { :'disabled' => :'Boolean', :'email' => :'String', - :'name' => :'String' + :'name' => :'String', + :'title' => :'String' } end + # List of attributes with nullable: true + # @!visibility private + def self.openapi_nullable + Set.new([ + :'title', + ]) + end + # Initializes the object # @param attributes [Hash] Model attributes in the form of hash # @!visibility private @@ -81,6 +97,10 @@ def initialize(attributes = {}) if attributes.key?(:'name') self.name = attributes[:'name'] end + + if attributes.key?(:'title') + self.title = attributes[:'title'] + end end # Returns the object in the form of hash, with additionalProperties support. @@ -112,6 +132,7 @@ def ==(o) disabled == o.disabled && email == o.email && name == o.name && + title == o.title && additional_properties == o.additional_properties end @@ -119,7 +140,7 @@ def ==(o) # @return [Integer] Hash code # @!visibility private def hash - [disabled, email, name, additional_properties].hash + [disabled, email, name, title, additional_properties].hash end end end