69 lines
2.5 KiB
C#
69 lines
2.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Alkami.Ops.SecretServer.Enum;
|
|
using Alkami.Ops.SecretServer.SSWebService;
|
|
|
|
namespace Alkami.Ops.SecretServer.Model
|
|
{
|
|
/// <summary>
|
|
/// Represents a Certificate or SSL Certificate secret
|
|
/// </summary>
|
|
public class Certificate : SecretBase
|
|
{
|
|
/// <summary>
|
|
/// The Certificate name from the "Certificate Name" field on the secret
|
|
/// </summary>
|
|
public string Name => SecretItems.FirstOrDefault(p => string.Equals(p.FieldName, "Certificate Name", StringComparison.OrdinalIgnoreCase))?.Value;
|
|
|
|
/// <summary>
|
|
/// The Certificate password from the "Import Password" field on the secret
|
|
/// </summary>
|
|
public string Password => SecretItems.FirstOrDefault(p => string.Equals(p.FieldName, "Import Password", StringComparison.OrdinalIgnoreCase) && p.IsPassword)?.Value;
|
|
|
|
/// <summary>
|
|
/// The FileID of the attachment on the secret from the "Pfx File" field
|
|
/// </summary>
|
|
public int? FileId => SecretItems.FirstOrDefault(p => string.Equals(p.FieldName, "Pfx File", StringComparison.OrdinalIgnoreCase) && p.IsFile)?.Id;
|
|
|
|
/// <summary>
|
|
/// The secret type
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Returns <seealso cref="SecretType"/>.Certificate
|
|
/// </remarks>
|
|
public new SecretType SecretType => SecretType.Certificate;
|
|
|
|
/// <summary>
|
|
/// The FileName of the attachment. Added externally from a subsequent call to SecretServer
|
|
/// </summary>
|
|
public string FileName { get; set; }
|
|
|
|
/// <summary>
|
|
/// The FileAttachment as a byte array. Added externally from a subsequent call to SecretServer
|
|
/// </summary>
|
|
public byte[] FileAttachment { get; set; }
|
|
|
|
/// <summary>
|
|
/// Saves the <see cref="FileAttachment"/> to disk
|
|
/// </summary>
|
|
/// <param name="outputPath">The path to save the file to. The FileName is appended from <seealso cref="FileName"/></param>
|
|
/// <returns></returns>
|
|
public string SaveFileToDisk(string outputPath)
|
|
{
|
|
var outFile = Path.Combine(outputPath, FileName);
|
|
File.WriteAllBytes(outFile, FileAttachment);
|
|
|
|
return outFile;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Instantiates a new instance of the Certificate class
|
|
/// </summary>
|
|
/// <param name="secret"></param>
|
|
public Certificate(Secret secret) : base(secret)
|
|
{
|
|
}
|
|
}
|
|
}
|