// This is an automatically generated code sample.
// To make this code sample work in your Oracle Cloud tenancy,
// please replace the values for any parameters whose current values do not fit
// your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
// boolean, number, and enum parameters with values not fitting your use case).
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Oci.VaultService;
using Oci.Common;
using Oci.Common.Auth;
namespace Oci.Sdk.DotNet.Example.Vault
{
public class CreateSecretExample
{
public static async Task Main()
{
// Create a request and dependent object(s).
var createSecretDetails = new Oci.VaultService.Models.CreateSecretDetails
{
CompartmentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
DefinedTags = new Dictionary<string, Dictionary<string, Object>>()
{
{
"EXAMPLE_KEY_tW6S5",
new Dictionary<string, Object>()
{
{
"EXAMPLE_KEY_xoPFl",
"EXAMPLE--Value"
}
}
}
},
Description = "EXAMPLE-description-Value",
FreeformTags = new Dictionary<string, string>()
{
{
"EXAMPLE_KEY_sa1Nf",
"EXAMPLE_VALUE_KWpUwwSV4GUMxOnpT22Z"
}
},
KeyId = "ocid1.test.oc1..<unique_ID>EXAMPLE-keyId-Value",
Metadata = new Dictionary<string, Object>()
{
{
"EXAMPLE_KEY_Mdg06",
"EXAMPLE--Value"
}
},
SecretContent = new Oci.VaultService.Models.Base64SecretContentDetails
{
Content = "EXAMPLE-content-Value",
Name = "EXAMPLE-name-Value",
Stage = Oci.VaultService.Models.SecretContentDetails.StageEnum.Current
},
ReplicationConfig = new Oci.VaultService.Models.ReplicationConfig
{
ReplicationTargets = new List<Oci.VaultService.Models.ReplicationTarget>
{
new Oci.VaultService.Models.ReplicationTarget
{
TargetKeyId = "ocid1.test.oc1..<unique_ID>EXAMPLE-targetKeyId-Value",
TargetRegion = "EXAMPLE-targetRegion-Value",
TargetVaultId = "ocid1.test.oc1..<unique_ID>EXAMPLE-targetVaultId-Value"
}
},
IsWriteForwardEnabled = true
},
RotationConfig = new Oci.VaultService.Models.RotationConfig
{
RotationInterval = "EXAMPLE-rotationInterval-Value",
TargetSystemDetails = new Oci.VaultService.Models.FunctionTargetSystemDetails
{
FunctionId = "ocid1.test.oc1..<unique_ID>EXAMPLE-functionId-Value"
},
IsScheduledRotationEnabled = false
},
SecretName = "EXAMPLE-secretName-Value",
SecretRules = new List<Oci.VaultService.Models.SecretRule>
{
new Oci.VaultService.Models.SecretExpiryRule
{
SecretVersionExpiryInterval = "EXAMPLE-secretVersionExpiryInterval-Value",
TimeOfAbsoluteExpiry = DateTime.Parse("11/14/2004 10:47:18"),
IsSecretContentRetrievalBlockedOnExpiry = true
}
},
VaultId = "ocid1.test.oc1..<unique_ID>EXAMPLE-vaultId-Value",
SecretGenerationContext = new Oci.VaultService.Models.BytesGenerationContext
{
GenerationTemplate = Oci.VaultService.Models.BytesGenerationContext.GenerationTemplateEnum.Bytes512,
SecretTemplate = "EXAMPLE-secretTemplate-Value"
},
EnableAutoGeneration = true
};
var createSecretRequest = new Oci.VaultService.Requests.CreateSecretRequest
{
CreateSecretDetails = createSecretDetails,
OpcRequestId = "IIKSKDYXGCWCHUQB6SAE<unique_ID>",
OpcRetryToken = "EXAMPLE-opcRetryToken-Value"
};
// Create a default authentication provider that uses the DEFAULT
// profile in the configuration file.
// Refer to <see href="https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File>the public documentation</see> on how to prepare a configuration file.
var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
try
{
// Create a service client and send the request.
using (var client = new VaultsClient(provider, new ClientConfiguration()))
{
var response = await client.CreateSecret(createSecretRequest);
// Retrieve value from the response.
var id = response.Secret.Id;
}
}
catch (Exception e)
{
Console.WriteLine($"CreateSecret Failed with {e.Message}");
throw e;
}
}
}
}