Added assembly name and root namespace to project file; updated session and vlan classes with new properties; modified module manifest to reference DLL and updated exported cmdlets; corrected property name in address class.
This commit is contained in:
81
classlib/Cmdlets/NewSessionCmdlet.cs
Normal file
81
classlib/Cmdlets/NewSessionCmdlet.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
namespace PS.IPAM.Cmdlets;
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Threading.Tasks;
|
||||
using PS.IPAM;
|
||||
using PS.IPAM.Helpers;
|
||||
|
||||
[Cmdlet(VerbsCommon.New, "Session", DefaultParameterSetName = "Credentials")]
|
||||
public class NewSessionCmdlet : PSCmdlet
|
||||
{
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
Position = 0)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[ValidatePattern("^https?://")]
|
||||
public string URL { get; set; } = string.Empty;
|
||||
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
Position = 1)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public string AppID { get; set; } = string.Empty;
|
||||
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
Position = 2,
|
||||
ParameterSetName = "Credentials")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public PSCredential? Credentials { get; set; }
|
||||
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
Position = 2,
|
||||
ParameterSetName = "Token")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public string? Token { get; set; }
|
||||
|
||||
[Parameter(
|
||||
Mandatory = false,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
Position = 3)]
|
||||
public SwitchParameter IgnoreSSL { get; set; }
|
||||
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
try
|
||||
{
|
||||
Session session;
|
||||
if (ParameterSetName == "Credentials" && Credentials != null)
|
||||
{
|
||||
session = SessionManager.CreateSessionWithCredentials(
|
||||
URL,
|
||||
AppID,
|
||||
Credentials,
|
||||
IgnoreSSL.IsPresent
|
||||
).GetAwaiter().GetResult();
|
||||
}
|
||||
else if (ParameterSetName == "Token" && Token != null)
|
||||
{
|
||||
session = SessionManager.CreateSessionWithToken(URL, AppID, Token);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Invalid parameter set");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteError(new ErrorRecord(ex, "NewSessionError", ErrorCategory.InvalidOperation, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user