Method: OCI::Identity::IdentityClient#list_compartments
- Defined in:
- lib/oci/identity/identity_client.rb
#list_compartments(compartment_id, opts = {}) ⇒ Response
Lists the compartments in a specified compartment. The members of the list returned depends on the values set for several parameters.
With the exception of the tenancy (root compartment), the ListCompartments operation returns only the first-level child compartments in the parent compartment specified in compartmentId. The list does not include any subcompartments of the child compartments (grandchildren).
The parameter accessLevel specifies whether to return only those compartments for which the requestor has INSPECT permissions on at least one resource directly or indirectly (the resource can be in a subcompartment).
The parameter compartmentIdInSubtree applies only when you perform ListCompartments on the tenancy (root compartment). When set to true, the entire hierarchy of compartments can be returned. To get a full list of all compartments and subcompartments in the tenancy (root compartment), set the parameter compartmentIdInSubtree to true and accessLevel to ANY.
See [Where to Get the Tenancy’s OCID and User’s OCID](docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#five).
4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 |
# File 'lib/oci/identity/identity_client.rb', line 4477 def list_compartments(compartment_id, opts = {}) logger.debug 'Calling operation IdentityClient#list_compartments.' if logger raise "Missing the required parameter 'compartment_id' when calling list_compartments." if compartment_id.nil? if opts[:access_level] && !%w[ANY ACCESSIBLE].include?(opts[:access_level]) raise 'Invalid value for "access_level", must be one of ANY, ACCESSIBLE.' end if opts[:sort_by] && !%w[TIMECREATED NAME].include?(opts[:sort_by]) raise 'Invalid value for "sort_by", must be one of TIMECREATED, NAME.' end if opts[:sort_order] && !%w[ASC DESC].include?(opts[:sort_order]) raise 'Invalid value for "sort_order", must be one of ASC, DESC.' end if opts[:lifecycle_state] && !OCI::Identity::Models::Compartment::LIFECYCLE_STATE_ENUM.include?(opts[:lifecycle_state]) raise 'Invalid value for "lifecycle_state", must be one of the values in OCI::Identity::Models::Compartment::LIFECYCLE_STATE_ENUM.' end path = '/compartments/' operation_signing_strategy = :standard # rubocop:disable Style/NegatedIf # Query Params query_params = {} query_params[:compartmentId] = compartment_id query_params[:page] = opts[:page] if opts[:page] query_params[:limit] = opts[:limit] if opts[:limit] query_params[:accessLevel] = opts[:access_level] if opts[:access_level] query_params[:compartmentIdInSubtree] = opts[:compartment_id_in_subtree] if !opts[:compartment_id_in_subtree].nil? query_params[:name] = opts[:name] if opts[:name] query_params[:sortBy] = opts[:sort_by] if opts[:sort_by] query_params[:sortOrder] = opts[:sort_order] if opts[:sort_order] query_params[:lifecycleState] = opts[:lifecycle_state] if opts[:lifecycle_state] # Header Params header_params = {} header_params[:accept] = 'application/json' header_params[:'content-type'] = 'application/json' # rubocop:enable Style/NegatedIf post_body = nil # rubocop:disable Metrics/BlockLength OCI::Retry.(applicable_retry_config(opts), call_name: 'IdentityClient#list_compartments') do @api_client.call_api( :GET, path, endpoint, header_params: header_params, query_params: query_params, operation_signing_strategy: operation_signing_strategy, body: post_body, return_type: 'Array<OCI::Identity::Models::Compartment>' ) end # rubocop:enable Metrics/BlockLength end |