feat: add Start-InfisicalProcess cmdlet and -Prefix support on Export-InfisicalSecrets #12
@@ -333,7 +333,7 @@ $ConvertToInfisicalSecretDictionaryResult = ConvertTo-InfisicalSecretDictionary
|
|||||||
<command:noun>InfisicalSecrets</command:noun>
|
<command:noun>InfisicalSecrets</command:noun>
|
||||||
</command:details>
|
</command:details>
|
||||||
<maml:description>
|
<maml:description>
|
||||||
<maml:para>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.</maml:para>
|
<maml:para>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.</maml:para>
|
||||||
</maml:description>
|
</maml:description>
|
||||||
<maml:alertSet>
|
<maml:alertSet>
|
||||||
<maml:title>Notes</maml:title>
|
<maml:title>Notes</maml:title>
|
||||||
@@ -361,6 +361,11 @@ $ExportInfisicalSecretsParameters.Verbose = $True
|
|||||||
$ExportInfisicalSecretsResult = Export-InfisicalSecrets @ExportInfisicalSecretsParameters</dev:code>
|
$ExportInfisicalSecretsResult = Export-InfisicalSecrets @ExportInfisicalSecretsParameters</dev:code>
|
||||||
<dev:remarks><maml:para>Projects the recursive secret result into Process-scope environment variables for the current PowerShell session.</maml:para></dev:remarks>
|
<dev:remarks><maml:para>Projects the recursive secret result into Process-scope environment variables for the current PowerShell session.</maml:para></dev:remarks>
|
||||||
</command:example>
|
</command:example>
|
||||||
|
<command:example>
|
||||||
|
<maml:title>EXAMPLE 3</maml:title>
|
||||||
|
<dev:code>Get-InfisicalSecret -ProjectId $ProjectId -Environment 'dev' | Export-InfisicalSecrets -Format EnvironmentVariables -Scope Process -Prefix 'MYAPP_'</dev:code>
|
||||||
|
<dev:remarks><maml:para>Imports secrets into the process environment with every variable name prefixed by 'MYAPP_' (e.g. API_KEY becomes MYAPP_API_KEY).</maml:para></dev:remarks>
|
||||||
|
</command:example>
|
||||||
</command:examples>
|
</command:examples>
|
||||||
</command:command>
|
</command:command>
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1213,7 +1213,8 @@ Export-InfisicalSecrets `
|
|||||||
[-Path <FileInfo>] `
|
[-Path <FileInfo>] `
|
||||||
[-Scope <Process|User|Machine>] `
|
[-Scope <Process|User|Machine>] `
|
||||||
[-Force] `
|
[-Force] `
|
||||||
[-Encoding <UTF8|UTF8Bom|Unicode>]
|
[-Encoding <UTF8|UTF8Bom|Unicode>] `
|
||||||
|
[-Prefix <string>]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Parameter Rules
|
## Parameter Rules
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ namespace PSInfisicalAPI.Cmdlets
|
|||||||
[Parameter]
|
[Parameter]
|
||||||
public InfisicalExportEncoding Encoding { get; set; } = InfisicalExportEncoding.UTF8;
|
public InfisicalExportEncoding Encoding { get; set; } = InfisicalExportEncoding.UTF8;
|
||||||
|
|
||||||
|
[Parameter]
|
||||||
|
public string Prefix { get; set; }
|
||||||
|
|
||||||
private readonly List<InfisicalSecret> _buffer = new List<InfisicalSecret>();
|
private readonly List<InfisicalSecret> _buffer = new List<InfisicalSecret>();
|
||||||
|
|
||||||
protected override void ProcessRecord()
|
protected override void ProcessRecord()
|
||||||
@@ -68,7 +71,7 @@ namespace PSInfisicalAPI.Cmdlets
|
|||||||
|
|
||||||
InfisicalExportRequest request = new InfisicalExportRequest
|
InfisicalExportRequest request = new InfisicalExportRequest
|
||||||
{
|
{
|
||||||
Secrets = _buffer.ToArray(),
|
Secrets = ApplyPrefix(_buffer, Prefix),
|
||||||
Format = Format,
|
Format = Format,
|
||||||
Path = Path,
|
Path = Path,
|
||||||
Scope = Scope,
|
Scope = Scope,
|
||||||
@@ -85,6 +88,38 @@ namespace PSInfisicalAPI.Cmdlets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static InfisicalSecret[] ApplyPrefix(List<InfisicalSecret> 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)
|
private static Encoding ResolveEncoding(InfisicalExportEncoding encoding)
|
||||||
{
|
{
|
||||||
switch (encoding)
|
switch (encoding)
|
||||||
|
|||||||
Reference in New Issue
Block a user