protected override void ProcessRecord()
{
using (var vlt = Util.VaultHelper.GetVault(VaultProfile))
{
vlt.OpenStorage();
var v = vlt.LoadVault();
if (v.Registrations == null || v.Registrations.Count < 1)
throw new InvalidOperationException("No registrations found");
var ri = v.Registrations[0];
var r = ri.Registration;
if (v.Identifiers == null || v.Identifiers.Count < 1)
throw new InvalidOperationException("No identifiers found");
var ii = v.Identifiers.GetByRef(IdentifierRef, throwOnMissing: false);
if (ii == null)
throw new Exception("Unable to find an Identifier for the given reference");
// If we're renaming the Alias, do that
// first in case there are any problems
if (NewAlias != null)
{
v.Identifiers.Rename(IdentifierRef, NewAlias);
ii.Alias = NewAlias == "" ? null : NewAlias;
}
var authzState = ii.Authorization;
if (!LocalOnly)
{
try {
using (var c = ClientHelper.GetClient(v, ri))
{
c.Init();
c.GetDirectory(true);
if (string.IsNullOrEmpty(ChallengeType))
{
authzState = c.RefreshIdentifierAuthorization(authzState, UseBaseUri);
}
else
{
c.RefreshAuthorizeChallenge(authzState, ChallengeType, UseBaseUri);
}
}
ii.Authorization = authzState;
}
catch (AcmeClient.AcmeWebException ex)
{
ThrowTerminatingError(PoshHelper.CreateErrorRecord(ex, ii));
return;
}
}
ii.Label = StringHelper.IfNullOrEmpty(Label);
ii.Memo = StringHelper.IfNullOrEmpty(Memo);
vlt.SaveVault(v);
WriteObject(authzState);
}
}