protected override void ProcessRecord()
{
using (var vlt = Util.VaultHelper.GetVault(VaultProfile))
{
vlt.OpenStorage();
var v = vlt.LoadVault();
// branch based on whether an ID ref was specified
if (string.IsNullOrEmpty(IdentifierRef))
{
if (v.Identifiers == null || v.Identifiers.Count < 1)
{
// just return null if there are no IDs
WriteObject(null);
}
else
{
// otherwise, return all IDs
int seq = 0;
WriteObject(v.Identifiers.Values.Select(x => new
{
Seq = seq++,
x.Id,
x.Alias,
x.Label,
x.Dns,
x.Authorization.Status
}), true);
}
}
else
{
if (v.Identifiers == null || v.Identifiers.Count < 1)
{
// throw because none exist (and thus, we couldn't find the one specified)
throw new ItemNotFoundException("Unable to find an Identifier for the given reference");
}
else
{
var ii = v.Identifiers.GetByRef(IdentifierRef, throwOnMissing: false);
if (ii == null)
throw new ItemNotFoundException("Unable to find an Identifier for the given reference");
var authzState = ii.Authorization;
WriteObject(authzState);
}
}
}
}