diff --git a/Module/PSInfisicalAPI/en-US/PSInfisicalAPI.dll-Help.xml b/Module/PSInfisicalAPI/en-US/PSInfisicalAPI.dll-Help.xml
index f67e148..bf7d41e 100644
--- a/Module/PSInfisicalAPI/en-US/PSInfisicalAPI.dll-Help.xml
+++ b/Module/PSInfisicalAPI/en-US/PSInfisicalAPI.dll-Help.xml
@@ -333,7 +333,7 @@ $ConvertToInfisicalSecretDictionaryResult = ConvertTo-InfisicalSecretDictionary
InfisicalSecrets
- Buffers an incoming pipeline of InfisicalSecret objects and writes them to a file in the requested format (DotEnv, Json, Yaml, EnvironmentVariables, etc.) or sets them as environment variables on the chosen scope (Process, User, Machine). -Encoding controls text encoding for file outputs.
+ Buffers an incoming pipeline of InfisicalSecret objects and writes them to a file in the requested format (DotEnv, Json, Yaml, EnvironmentVariables, etc.) or sets them as environment variables on the chosen scope (Process, User, Machine). -Encoding controls text encoding for file outputs. -Prefix prepends a string to every emitted variable name regardless of format.
Notes
@@ -361,6 +361,11 @@ $ExportInfisicalSecretsParameters.Verbose = $True
$ExportInfisicalSecretsResult = Export-InfisicalSecrets @ExportInfisicalSecretsParameters
Projects the recursive secret result into Process-scope environment variables for the current PowerShell session.
+
+ EXAMPLE 3
+ Get-InfisicalSecret -ProjectId $ProjectId -Environment 'dev' | Export-InfisicalSecrets -Format EnvironmentVariables -Scope Process -Prefix 'MYAPP_'
+ Imports secrets into the process environment with every variable name prefixed by 'MYAPP_' (e.g. API_KEY becomes MYAPP_API_KEY).
+
diff --git a/docs/DesignSpec.md b/docs/DesignSpec.md
index a7124fd..eeff9c9 100644
--- a/docs/DesignSpec.md
+++ b/docs/DesignSpec.md
@@ -1213,7 +1213,8 @@ Export-InfisicalSecrets `
[-Path ] `
[-Scope ] `
[-Force] `
- [-Encoding ]
+ [-Encoding ] `
+ [-Prefix ]
```
## Parameter Rules
diff --git a/src/PSInfisicalAPI/Cmdlets/ExportInfisicalSecretsCmdlet.cs b/src/PSInfisicalAPI/Cmdlets/ExportInfisicalSecretsCmdlet.cs
index 6a3f19f..59bb694 100644
--- a/src/PSInfisicalAPI/Cmdlets/ExportInfisicalSecretsCmdlet.cs
+++ b/src/PSInfisicalAPI/Cmdlets/ExportInfisicalSecretsCmdlet.cs
@@ -37,6 +37,9 @@ namespace PSInfisicalAPI.Cmdlets
[Parameter]
public InfisicalExportEncoding Encoding { get; set; } = InfisicalExportEncoding.UTF8;
+ [Parameter]
+ public string Prefix { get; set; }
+
private readonly List _buffer = new List();
protected override void ProcessRecord()
@@ -68,7 +71,7 @@ namespace PSInfisicalAPI.Cmdlets
InfisicalExportRequest request = new InfisicalExportRequest
{
- Secrets = _buffer.ToArray(),
+ Secrets = ApplyPrefix(_buffer, Prefix),
Format = Format,
Path = Path,
Scope = Scope,
@@ -85,6 +88,38 @@ namespace PSInfisicalAPI.Cmdlets
}
}
+ private static InfisicalSecret[] ApplyPrefix(List source, string prefix)
+ {
+ if (string.IsNullOrEmpty(prefix)) { return source.ToArray(); }
+
+ InfisicalSecret[] result = new InfisicalSecret[source.Count];
+ for (int i = 0; i < source.Count; i++)
+ {
+ InfisicalSecret original = source[i];
+ result[i] = new InfisicalSecret
+ {
+ Id = original.Id,
+ InternalId = original.InternalId,
+ Workspace = original.Workspace,
+ Environment = original.Environment,
+ Version = original.Version,
+ Type = original.Type,
+ SecretName = string.Concat(prefix, original.SecretName),
+ SecretValue = original.SecretValue,
+ SecretValueHidden = original.SecretValueHidden,
+ SecretPath = original.SecretPath,
+ SecretComment = original.SecretComment,
+ CreatedAtUtc = original.CreatedAtUtc,
+ UpdatedAtUtc = original.UpdatedAtUtc,
+ IsRotatedSecret = original.IsRotatedSecret,
+ RotationId = original.RotationId,
+ Tags = original.Tags,
+ SecretMetadata = original.SecretMetadata
+ };
+ }
+ return result;
+ }
+
private static Encoding ResolveEncoding(InfisicalExportEncoding encoding)
{
switch (encoding)