// TODO: better import syntax? import {BaseAPIRequestFactory, RequiredError, COLLECTION_FORMATS} from './baseapi'; import {Configuration} from '../configuration'; import {RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http'; import {ObjectSerializer} from '../models/ObjectSerializer'; import {ApiException} from './exception'; import {canConsumeForm, isCodeInRange} from '../util'; import {SecurityAuthentication} from '../auth/auth'; import { CreateUserGroupRequest } from '../models/CreateUserGroupRequest'; import { ErrorResponse } from '../models/ErrorResponse'; import { ImportUserGroupsRequest } from '../models/ImportUserGroupsRequest'; import { ImportUserGroupsResponse } from '../models/ImportUserGroupsResponse'; import { SearchUserGroupsRequest } from '../models/SearchUserGroupsRequest'; import { UpdateUserGroupRequest } from '../models/UpdateUserGroupRequest'; import { UserGroupResponse } from '../models/UserGroupResponse'; /** * no description */ export class GroupsApiRequestFactory extends BaseAPIRequestFactory { /** * Version: 9.0.0.cl or later Creates a group object in ThoughtSpot. Requires `ADMINISTRATION` (**Can administer ThoughtSpot**) privilege. If [Role-Based Access Control (RBAC)](https://developers.thoughtspot.com/docs/rbac) is enabled on your instance, the `GROUP_ADMINISTRATION` (**Can manage groups**) privilege is required. #### About groups Groups in ThoughtSpot are used by the administrators to define privileges and organize users based on their roles and access requirements. To know more about groups and privileges, see [ThoughtSpot Product Documentation](https://docs.thoughtspot.com/cloud/latest/groups-privileges). #### Supported operations The API endpoint lets you perform the following operations: * Assign privileges * Add users * Define sharing visibility * Add sub-groups * Assign a default Liveboard * @param createUserGroupRequest */ public async createUserGroup(createUserGroupRequest: CreateUserGroupRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'createUserGroupRequest' is not null or undefined if (createUserGroupRequest === null || createUserGroupRequest === undefined) { throw new RequiredError("GroupsApi", "createUserGroup", "createUserGroupRequest"); } // Path Params const localVarPath = '/api/rest/2.0/groups/create'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") requestContext.setHeaderParam("User-Agent", "ThoughtSpot-Client/typescript/2.23.0") requestContext.setHeaderParam("X-ThoughtSpot-Client", "ThoughtSpot-ts-client/2.23.0") // Body Params const contentType = ObjectSerializer.getPreferredMediaType([ "application/json" ]); requestContext.setHeaderParam("Content-Type", contentType); const serializedBody = ObjectSerializer.stringify( ObjectSerializer.serialize(createUserGroupRequest, "CreateUserGroupRequest", ""), contentType ); requestContext.setBody(serializedBody); let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["bearerAuth"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Version: 9.0.0.cl or later Removes the specified group object from the ThoughtSpot system. Requires `ADMINISTRATION` (**Can administer ThoughtSpot**) privilege. If [Role-Based Access Control (RBAC)](https://developers.thoughtspot.com/docs/rbac) is enabled on your instance, the `GROUP_ADMINISTRATION` (**Can manage groups**) privilege is required. * @param groupIdentifier GUID or name of the group. */ public async deleteUserGroup(groupIdentifier: string, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'groupIdentifier' is not null or undefined if (groupIdentifier === null || groupIdentifier === undefined) { throw new RequiredError("GroupsApi", "deleteUserGroup", "groupIdentifier"); } // Path Params const localVarPath = '/api/rest/2.0/groups/{group_identifier}/delete' .replace('{' + 'group_identifier' + '}', encodeURIComponent(String(groupIdentifier))); // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") requestContext.setHeaderParam("User-Agent", "ThoughtSpot-Client/typescript/2.23.0") requestContext.setHeaderParam("X-ThoughtSpot-Client", "ThoughtSpot-ts-client/2.23.0") let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["bearerAuth"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Version: 9.0.0.cl or later Imports group objects from external databases into ThoughtSpot. Requires `ADMINISTRATION` (**Can administer ThoughtSpot**) privilege. If [Role-Based Access Control (RBAC)](https://developers.thoughtspot.com/docs/rbac) is enabled on your instance, the `GROUP_ADMINISTRATION` (**Can manage groups**) privilege is required. During the import operation: * If the specified group is not available in ThoughtSpot, it will be added to ThoughtSpot. * If `delete_unspecified_groups` is set to `true`, the groups not specified in the API request, excluding administrator and system user groups, are deleted. * If the specified groups are already available in ThoughtSpot, the object properties of these groups are modified and synchronized as per the input data in the API request. A successful API call returns the object that represents the changes made in the ThoughtSpot system. * @param importUserGroupsRequest */ public async importUserGroups(importUserGroupsRequest: ImportUserGroupsRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'importUserGroupsRequest' is not null or undefined if (importUserGroupsRequest === null || importUserGroupsRequest === undefined) { throw new RequiredError("GroupsApi", "importUserGroups", "importUserGroupsRequest"); } // Path Params const localVarPath = '/api/rest/2.0/groups/import'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") requestContext.setHeaderParam("User-Agent", "ThoughtSpot-Client/typescript/2.23.0") requestContext.setHeaderParam("X-ThoughtSpot-Client", "ThoughtSpot-ts-client/2.23.0") // Body Params const contentType = ObjectSerializer.getPreferredMediaType([ "application/json" ]); requestContext.setHeaderParam("Content-Type", contentType); const serializedBody = ObjectSerializer.stringify( ObjectSerializer.serialize(importUserGroupsRequest, "ImportUserGroupsRequest", ""), contentType ); requestContext.setBody(serializedBody); let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["bearerAuth"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Version: 9.0.0.cl or later Gets a list of user group objects from the ThoughtSpot system. To get details of a specific user group, specify the user group GUID or name. You can also filter the API response based on User ID, Org ID, Role ID, type of group, sharing visibility, privileges assigned to the group, and the Liveboard IDs assigned to the users in the group. Available to all users. Users with `ADMINISTRATION` (**Can administer ThoughtSpot**) privileges can view all users properties. If [Role-Based Access Control (RBAC)](https://developers.thoughtspot.com/docs/rbac) is enabled on your instance, the `GROUP_ADMINISTRATION` (**Can manage groups**) privilege is required. **NOTE**: If you do not get precise results, try setting `record_size` to `-1` and `record_offset` to `0`. * @param searchUserGroupsRequest */ public async searchUserGroups(searchUserGroupsRequest: SearchUserGroupsRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'searchUserGroupsRequest' is not null or undefined if (searchUserGroupsRequest === null || searchUserGroupsRequest === undefined) { throw new RequiredError("GroupsApi", "searchUserGroups", "searchUserGroupsRequest"); } // Path Params const localVarPath = '/api/rest/2.0/groups/search'; // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") requestContext.setHeaderParam("User-Agent", "ThoughtSpot-Client/typescript/2.23.0") requestContext.setHeaderParam("X-ThoughtSpot-Client", "ThoughtSpot-ts-client/2.23.0") // Body Params const contentType = ObjectSerializer.getPreferredMediaType([ "application/json" ]); requestContext.setHeaderParam("Content-Type", contentType); const serializedBody = ObjectSerializer.stringify( ObjectSerializer.serialize(searchUserGroupsRequest, "SearchUserGroupsRequest", ""), contentType ); requestContext.setBody(serializedBody); let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["bearerAuth"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } /** * Version: 9.0.0.cl or later Updates the properties of a group object in ThoughtSpot. Requires `ADMINISTRATION` (**Can administer ThoughtSpot**) privilege. If [Role-Based Access Control (RBAC)](https://developers.thoughtspot.com/docs/rbac) is enabled on your instance, the `GROUP_ADMINISTRATION` (**Can manage groups**) privilege is required. #### Supported operations This API endpoint lets you perform the following operations in a single API request: * Edit [privileges](https://developers.thoughtspot.com/docs/?pageid=api-user-management#group-privileges) * Add or remove users * Change sharing visibility settings * Add or remove sub-groups * Assign a default Liveboard or update the existing settings * @param groupIdentifier GUID or name of the group. * @param updateUserGroupRequest */ public async updateUserGroup(groupIdentifier: string, updateUserGroupRequest: UpdateUserGroupRequest, _options?: Configuration): Promise { let _config = _options || this.configuration; // verify required parameter 'groupIdentifier' is not null or undefined if (groupIdentifier === null || groupIdentifier === undefined) { throw new RequiredError("GroupsApi", "updateUserGroup", "groupIdentifier"); } // verify required parameter 'updateUserGroupRequest' is not null or undefined if (updateUserGroupRequest === null || updateUserGroupRequest === undefined) { throw new RequiredError("GroupsApi", "updateUserGroup", "updateUserGroupRequest"); } // Path Params const localVarPath = '/api/rest/2.0/groups/{group_identifier}/update' .replace('{' + 'group_identifier' + '}', encodeURIComponent(String(groupIdentifier))); // Make Request Context const requestContext = _config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8") requestContext.setHeaderParam("User-Agent", "ThoughtSpot-Client/typescript/2.23.0") requestContext.setHeaderParam("X-ThoughtSpot-Client", "ThoughtSpot-ts-client/2.23.0") // Body Params const contentType = ObjectSerializer.getPreferredMediaType([ "application/json" ]); requestContext.setHeaderParam("Content-Type", contentType); const serializedBody = ObjectSerializer.stringify( ObjectSerializer.serialize(updateUserGroupRequest, "UpdateUserGroupRequest", ""), contentType ); requestContext.setBody(serializedBody); let authMethod: SecurityAuthentication | undefined; // Apply auth methods authMethod = _config.authMethods["bearerAuth"] if (authMethod?.applySecurityAuthentication) { await authMethod?.applySecurityAuthentication(requestContext); } const defaultAuth: SecurityAuthentication | undefined = _options?.authMethods?.default || this.configuration?.authMethods?.default if (defaultAuth?.applySecurityAuthentication) { await defaultAuth?.applySecurityAuthentication(requestContext); } return requestContext; } } export class GroupsApiResponseProcessor { /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to createUserGroup * @throws ApiException if the response code was not in [200, 299] */ public async createUserGroup(response: ResponseContext): Promise { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: UserGroupResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "UserGroupResponse", "" ) as UserGroupResponse; return body; } if (isCodeInRange("400", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Invalid request.", body, response.headers); } if (isCodeInRange("401", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unauthorized access.", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Forbidden access.", body, response.headers); } if (isCodeInRange("500", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unexpected error", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: UserGroupResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "UserGroupResponse", "" ) as UserGroupResponse; return body; } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to deleteUserGroup * @throws ApiException if the response code was not in [200, 299] */ public async deleteUserGroup(response: ResponseContext): Promise { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("204", response.httpStatusCode)) { return; } if (isCodeInRange("400", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Invalid request.", body, response.headers); } if (isCodeInRange("401", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unauthorized access.", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Forbidden access.", body, response.headers); } if (isCodeInRange("500", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unexpected error", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: void = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "void", "" ) as void; return body; } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to importUserGroups * @throws ApiException if the response code was not in [200, 299] */ public async importUserGroups(response: ResponseContext): Promise { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: ImportUserGroupsResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ImportUserGroupsResponse", "" ) as ImportUserGroupsResponse; return body; } if (isCodeInRange("400", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Invalid request.", body, response.headers); } if (isCodeInRange("401", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unauthorized access.", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Forbidden access.", body, response.headers); } if (isCodeInRange("500", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unexpected error", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: ImportUserGroupsResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ImportUserGroupsResponse", "" ) as ImportUserGroupsResponse; return body; } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to searchUserGroups * @throws ApiException if the response code was not in [200, 299] */ public async searchUserGroups(response: ResponseContext): Promise > { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("200", response.httpStatusCode)) { const body: Array = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "Array", "" ) as Array; return body; } if (isCodeInRange("400", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Invalid request.", body, response.headers); } if (isCodeInRange("401", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unauthorized access.", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Forbidden access.", body, response.headers); } if (isCodeInRange("500", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unexpected error", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: Array = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "Array", "" ) as Array; return body; } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } /** * Unwraps the actual response sent by the server from the response context and deserializes the response content * to the expected objects * * @params response Response returned by the server for a request to updateUserGroup * @throws ApiException if the response code was not in [200, 299] */ public async updateUserGroup(response: ResponseContext): Promise { const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]); if (isCodeInRange("204", response.httpStatusCode)) { return; } if (isCodeInRange("400", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Invalid request.", body, response.headers); } if (isCodeInRange("401", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unauthorized access.", body, response.headers); } if (isCodeInRange("403", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Forbidden access.", body, response.headers); } if (isCodeInRange("500", response.httpStatusCode)) { const body: ErrorResponse = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "ErrorResponse", "" ) as ErrorResponse; throw new ApiException(response.httpStatusCode, "Unexpected error", body, response.headers); } // Work around for missing responses in specification, e.g. for petstore.yaml if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { const body: void = ObjectSerializer.deserialize( ObjectSerializer.parse(await response.body.text(), contentType), "void", "" ) as void; return body; } throw new ApiException(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny(), response.headers); } }