Class Credentials
Username and password combination.
Inheritance
Namespace: Amazon.CDK.AWS.RDS
Assembly: Amazon.CDK.AWS.RDS.dll
Syntax (csharp)
public abstract class Credentials : DeputyBase
Syntax (vb)
Public MustInherit Class Credentials
Inherits DeputyBase
Remarks
ExampleMetadata: infused
Examples
// Build a data source for AppSync to access the database.
GraphqlApi api;
// Create username and password secret for DB Cluster
var secret = new DatabaseSecret(this, "AuroraSecret", new DatabaseSecretProps {
Username = "clusteradmin"
});
// The VPC to place the cluster in
var vpc = new Vpc(this, "AuroraVpc");
// Create the serverless cluster, provide all values needed to customise the database.
var cluster = new ServerlessCluster(this, "AuroraCluster", new ServerlessClusterProps {
Engine = DatabaseClusterEngine.AURORA_MYSQL,
Vpc = vpc,
Credentials = new Dictionary<string, string> { { "username", "clusteradmin" } },
ClusterIdentifier = "db-endpoint-test",
DefaultDatabaseName = "demos"
});
var rdsDS = api.AddRdsDataSource("rds", cluster, secret, "demos");
// Set up a resolver for an RDS query.
rdsDS.CreateResolver(new BaseResolverProps {
TypeName = "Query",
FieldName = "getDemosRds",
RequestMappingTemplate = MappingTemplate.FromString(@"
{
""version"": ""2018-05-29"",
""statements"": [
""SELECT * FROM demos""
]
}
"),
ResponseMappingTemplate = MappingTemplate.FromString(@"
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0])
")
});
// Set up a resolver for an RDS mutation.
rdsDS.CreateResolver(new BaseResolverProps {
TypeName = "Mutation",
FieldName = "addDemoRds",
RequestMappingTemplate = MappingTemplate.FromString(@"
{
""version"": ""2018-05-29"",
""statements"": [
""INSERT INTO demos VALUES (:id, :version)"",
""SELECT * WHERE id = :id""
],
""variableMap"": {
"":id"": $util.toJson($util.autoId()),
"":version"": $util.toJson($ctx.args.version)
}
}
"),
ResponseMappingTemplate = MappingTemplate.FromString(@"
$utils.toJson($utils.rds.toJsonObject($ctx.result)[1][0])
")
});
Synopsis
Constructors
Credentials() | |
Credentials(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Credentials(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Properties
EncryptionKey | KMS encryption key to encrypt the generated secret. |
ExcludeCharacters | |
Password | Password. |
ReplicaRegions | A list of regions where to replicate the generated secret. |
Secret | Secret used to instantiate this Login. |
SecretName | The name to use for the Secret if a new Secret is to be generated in SecretsManager for these Credentials. |
Username | Username. |
UsernameAsString | Whether the username should be referenced as a string and not as a dynamic reference to the username in the secret. |
Methods
FromGeneratedSecret(String, ICredentialsBaseOptions) | Creates Credentials with a password generated and stored in Secrets Manager. |
FromPassword(String, SecretValue) | Creates Credentials from a password. |
FromSecret(ISecret, String) | Creates Credentials from an existing Secrets Manager |
FromUsername(String, ICredentialsFromUsernameOptions) | Creates Credentials for the given username, and optional password and key. |
Constructors
Credentials()
protected Credentials()
Credentials(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected Credentials(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
Credentials(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected Credentials(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Properties
EncryptionKey
KMS encryption key to encrypt the generated secret.
public abstract IKey EncryptionKey { get; }
Property Value
Remarks
Default: - default master key
ExcludeCharacters
public abstract string ExcludeCharacters { get; }
Property Value
System.String
Password
Password.
public abstract SecretValue Password { get; }
Property Value
Remarks
Do not put passwords in your CDK code directly.
Default: - a Secrets Manager generated password
ReplicaRegions
A list of regions where to replicate the generated secret.
public abstract IReplicaRegion[] ReplicaRegions { get; }
Property Value
Remarks
Default: - Secret is not replicated
Secret
Secret used to instantiate this Login.
public abstract ISecret Secret { get; }
Property Value
Remarks
Default: - none
SecretName
The name to use for the Secret if a new Secret is to be generated in SecretsManager for these Credentials.
public abstract string SecretName { get; }
Property Value
System.String
Remarks
Default: - A name is generated by CloudFormation.
Username
Username.
public abstract string Username { get; }
Property Value
System.String
UsernameAsString
Whether the username should be referenced as a string and not as a dynamic reference to the username in the secret.
public abstract Nullable<bool> UsernameAsString { get; }
Property Value
System.Nullable<System.Boolean>
Remarks
Default: false
Methods
FromGeneratedSecret(String, ICredentialsBaseOptions)
Creates Credentials with a password generated and stored in Secrets Manager.
public static Credentials FromGeneratedSecret(string username, ICredentialsBaseOptions options = null)
Parameters
- username System.String
- options ICredentialsBaseOptions
Returns
FromPassword(String, SecretValue)
Creates Credentials from a password.
public static Credentials FromPassword(string username, SecretValue password)
Parameters
- username System.String
- password SecretValue
Returns
Remarks
Do not put passwords in your CDK code directly.
FromSecret(ISecret, String)
Creates Credentials from an existing Secrets Manager Secret
(or DatabaseSecret
).
public static Credentials FromSecret(ISecret secret, string username = null)
Parameters
- secret ISecret
The secret where the credentials are stored.
- username System.String
The username defined in the secret.
Returns
Remarks
The Secret must be a JSON string with a username
and password
field:
{
...
"username": <required: username>,
"password": <required: password>,
}
FromUsername(String, ICredentialsFromUsernameOptions)
Creates Credentials for the given username, and optional password and key.
public static Credentials FromUsername(string username, ICredentialsFromUsernameOptions options = null)
Parameters
- username System.String
- options ICredentialsFromUsernameOptions
Returns
Remarks
If no password is provided, one will be generated and stored in Secrets Manager.