-
Notifications
You must be signed in to change notification settings - Fork 270
/
instance_principals_examples.py
34 lines (28 loc) · 1.94 KB
/
instance_principals_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# coding: utf-8
# Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
import oci
compartment_id = '<your compartment id here>'
# By default this will hit the auth service in the region returned by http://169.254.169.254/opc/v2/instance/region on the instance.
#
# To customize timeouts while retrieving certificates from identity, you can now provide a custom retry strategy
# while creating the signer. For example:
#
# custom_strategy = oci.retry.RetryStrategyBuilder().add_max_attempts(4).get_retry_strategy()
# signer_kwargs = {'retry_strategy': custom_strategy}
# signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner(**signer_kwargs)
signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
# In the base case, configuration does not need to be provided as the region and tenancy are obtained from the InstancePrincipalsSecurityTokenSigner
identity_client = oci.identity.IdentityClient(config={}, signer=signer)
print(identity_client.list_regions().data)
print(identity_client.list_availability_domains(compartment_id=compartment_id).data)
# If you explicitly specify a region in configuration, it will be honoured. In the below example, you can also change the region later by doing:
#
# object_storage_client.base_client.set_region('us-ashburn-1')
#
# You can also explicitly set an endpoint via:
#
# object_storage_client.base_client.set_endpoint('https://<some endpoint>')
object_storage_client = oci.object_storage.ObjectStorageClient(config={'region': 'us-ashburn-1'}, signer=signer)
print(object_storage_client.get_namespace().data)
print(object_storage_client.list_buckets(namespace_name=object_storage_client.get_namespace().data, compartment_id=compartment_id).data)