コード例 #1
0
        public static async Task MainInstancePrincipal()
        {
            // expose the tenancyId for the environment variable OCI_COMPARTMENT_ID
            string tenantId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID");

            // Creates an Instance Principal provider that holds authentication details of the OCI Instance
            // This helps in making API requests by the Instance without user involvement
            var instanceProvider = new InstancePrincipalsAuthenticationDetailsProvider();

            // Create a client for the service to enable using its APIs
            var client = new IdentityClient(instanceProvider, new ClientConfiguration());

            try
            {
                await ListOciRegions(client);
                await ListOciRegionSubscriptions(client, tenantId);
            }
            catch (Exception e)
            {
                logger.Info($"Received exception due to {e.Message}");
            }
            finally
            {
                client.Dispose();
            }
        }
コード例 #2
0
        public static async Task <GetSecretBundleResponse> getSecretResponse(string vaultSecretOCID, string ociRegion)
        {
            var getSecretBundleRequest = new Oci.SecretsService.Requests.GetSecretBundleRequest
            {
                // SecretId = "ocid1.vaultsecret.oc1.iad.amaaaaaaq33dybya5qo2jtafngz7krbqdt64fygvm4v5ml7dnamg6ct7vaza"
                SecretId = vaultSecretOCID
            };
            var provider = new InstancePrincipalsAuthenticationDetailsProvider();

            try
            {
                using (var client = new SecretsClient(provider, new ClientConfiguration()))
                {
                    // client.SetRegion("us-ashburn-1");
                    client.SetRegion(ociRegion);
                    return(await client.GetSecretBundle(getSecretBundleRequest));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"GetSecretBundle Failed with {e.Message}");
                throw e;
            }
        }