Init commit.
This commit is contained in:
Коммит
aeb0f101f4
|
@ -0,0 +1,3 @@
|
||||||
|
bin
|
||||||
|
obj
|
||||||
|
.vs
|
|
@ -0,0 +1,20 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="HPC.ACM.API" Version="2.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="4.4.2" />
|
||||||
|
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-preview-06">
|
||||||
|
<PrivateAssets>All</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="src/**/*.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,158 @@
|
||||||
|
#
|
||||||
|
# Module manifest for module 'HPC.ACM.PS'
|
||||||
|
#
|
||||||
|
# Generated by: leizhan
|
||||||
|
#
|
||||||
|
# Generated on: 1/15/2019
|
||||||
|
#
|
||||||
|
|
||||||
|
@{
|
||||||
|
|
||||||
|
# Script module or binary module file associated with this manifest.
|
||||||
|
RootModule = 'HPC.ACM.PS.dll'
|
||||||
|
|
||||||
|
# Version number of this module.
|
||||||
|
ModuleVersion = '0.1.0'
|
||||||
|
|
||||||
|
# Supported PSEditions
|
||||||
|
# CompatiblePSEditions = @()
|
||||||
|
|
||||||
|
# ID used to uniquely identify this module
|
||||||
|
GUID = '419c8502-1d6f-42a2-89d2-0c54425732a8'
|
||||||
|
|
||||||
|
# Author of this module
|
||||||
|
Author = 'Microsoft HPC Pack Team'
|
||||||
|
|
||||||
|
# Company or vendor of this module
|
||||||
|
CompanyName = 'Microsoft'
|
||||||
|
|
||||||
|
# Copyright statement for this module
|
||||||
|
Copyright = '(c) 2019 leizhan. All rights reserved.'
|
||||||
|
|
||||||
|
# Description of the functionality provided by this module
|
||||||
|
Description = 'Cmdlets of HPC ACM API'
|
||||||
|
|
||||||
|
# Minimum version of the Windows PowerShell engine required by this module
|
||||||
|
# PowerShellVersion = ''
|
||||||
|
|
||||||
|
# Name of the Windows PowerShell host required by this module
|
||||||
|
# PowerShellHostName = ''
|
||||||
|
|
||||||
|
# Minimum version of the Windows PowerShell host required by this module
|
||||||
|
# PowerShellHostVersion = ''
|
||||||
|
|
||||||
|
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||||
|
# DotNetFrameworkVersion = ''
|
||||||
|
|
||||||
|
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||||
|
# CLRVersion = ''
|
||||||
|
|
||||||
|
# Processor architecture (None, X86, Amd64) required by this module
|
||||||
|
# ProcessorArchitecture = ''
|
||||||
|
|
||||||
|
# Modules that must be imported into the global environment prior to importing this module
|
||||||
|
# RequiredModules = @()
|
||||||
|
|
||||||
|
# Assemblies that must be loaded prior to importing this module
|
||||||
|
RequiredAssemblies = @(
|
||||||
|
'.\HPC.ACM.API.dll',
|
||||||
|
'.\Microsoft.CSharp.dll',
|
||||||
|
'.\Microsoft.IdentityModel.Clients.ActiveDirectory.dll',
|
||||||
|
'.\Microsoft.Rest.ClientRuntime.dll',
|
||||||
|
'.\Newtonsoft.Json.dll',
|
||||||
|
'.\System.Collections.Concurrent.dll',
|
||||||
|
'.\System.Collections.NonGeneric.dll',
|
||||||
|
'.\System.Collections.Specialized.dll',
|
||||||
|
'.\System.ComponentModel.dll',
|
||||||
|
'.\System.ComponentModel.Primitives.dll',
|
||||||
|
'.\System.ComponentModel.TypeConverter.dll',
|
||||||
|
'.\System.Dynamic.Runtime.dll',
|
||||||
|
'.\System.IO.FileSystem.Primitives.dll',
|
||||||
|
'.\System.Linq.dll',
|
||||||
|
'.\System.Linq.Expressions.dll',
|
||||||
|
'.\System.ObjectModel.dll',
|
||||||
|
'.\System.Private.DataContractSerialization.dll',
|
||||||
|
'.\System.Reflection.Emit.dll',
|
||||||
|
'.\System.Reflection.Emit.ILGeneration.dll',
|
||||||
|
'.\System.Reflection.Emit.Lightweight.dll',
|
||||||
|
'.\System.Reflection.TypeExtensions.dll',
|
||||||
|
'.\System.Runtime.Numerics.dll',
|
||||||
|
'.\System.Runtime.Serialization.Formatters.dll',
|
||||||
|
'.\System.Runtime.Serialization.Json.dll',
|
||||||
|
'.\System.Runtime.Serialization.Primitives.dll',
|
||||||
|
'.\System.Security.Cryptography.OpenSsl.dll',
|
||||||
|
'.\System.Security.Cryptography.Primitives.dll',
|
||||||
|
'.\System.Text.RegularExpressions.dll',
|
||||||
|
'.\System.Threading.dll',
|
||||||
|
'.\System.Threading.Tasks.Extensions.dll',
|
||||||
|
'.\System.Xml.ReaderWriter.dll',
|
||||||
|
'.\System.Xml.XDocument.dll',
|
||||||
|
'.\System.Xml.XmlDocument.dll',
|
||||||
|
'.\System.Xml.XmlSerializer.dll'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||||
|
# ScriptsToProcess = @()
|
||||||
|
|
||||||
|
# Type files (.ps1xml) to be loaded when importing this module
|
||||||
|
# TypesToProcess = @()
|
||||||
|
|
||||||
|
# Format files (.ps1xml) to be loaded when importing this module
|
||||||
|
# FormatsToProcess = @()
|
||||||
|
|
||||||
|
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||||
|
# NestedModules = @()
|
||||||
|
|
||||||
|
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||||
|
# FunctionsToExport = @()
|
||||||
|
|
||||||
|
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||||
|
CmdletsToExport = @('*')
|
||||||
|
|
||||||
|
# Variables to export from this module
|
||||||
|
# VariablesToExport = '*'
|
||||||
|
|
||||||
|
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
|
||||||
|
AliasesToExport = @()
|
||||||
|
|
||||||
|
# DSC resources to export from this module
|
||||||
|
# DscResourcesToExport = @()
|
||||||
|
|
||||||
|
# List of all modules packaged with this module
|
||||||
|
# ModuleList = @()
|
||||||
|
|
||||||
|
# List of all files packaged with this module
|
||||||
|
# FileList = @()
|
||||||
|
|
||||||
|
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||||
|
PrivateData = @{
|
||||||
|
|
||||||
|
PSData = @{
|
||||||
|
|
||||||
|
# Tags applied to this module. These help with module discovery in online galleries.
|
||||||
|
# Tags = @()
|
||||||
|
|
||||||
|
# A URL to the license for this module.
|
||||||
|
# LicenseUri = ''
|
||||||
|
|
||||||
|
# A URL to the main website for this project.
|
||||||
|
# ProjectUri = ''
|
||||||
|
|
||||||
|
# A URL to an icon representing this module.
|
||||||
|
# IconUri = ''
|
||||||
|
|
||||||
|
# ReleaseNotes of this module
|
||||||
|
# ReleaseNotes = ''
|
||||||
|
|
||||||
|
} # End of PSData hashtable
|
||||||
|
|
||||||
|
} # End of PrivateData hashtable
|
||||||
|
|
||||||
|
# HelpInfo URI of this module
|
||||||
|
# HelpInfoURI = ''
|
||||||
|
|
||||||
|
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
|
||||||
|
# DefaultCommandPrefix = ''
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using HPC.ACM.API;
|
||||||
|
|
||||||
|
namespace HPC.ACM.PS
|
||||||
|
{
|
||||||
|
class ApiClientFactory
|
||||||
|
{
|
||||||
|
public static HPCWebAPI Create(Connection connection)
|
||||||
|
{
|
||||||
|
var client = new HttpClient();
|
||||||
|
var headers = client.DefaultRequestHeaders;
|
||||||
|
var accessToken = connection.Profile.AccessToken;
|
||||||
|
|
||||||
|
headers.Remove("Authorization");
|
||||||
|
headers.Add("Authorization", $"Bearer {accessToken}");
|
||||||
|
|
||||||
|
return new HPCWebAPI(new Uri(connection.ApiBasePoint), client, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
using System;
|
||||||
|
using System.Management.Automation;
|
||||||
|
using System.Management.Automation.Runspaces;
|
||||||
|
using Microsoft.IdentityModel.Clients.ActiveDirectory;
|
||||||
|
|
||||||
|
namespace HPC.ACM.PS
|
||||||
|
{
|
||||||
|
public class Connection
|
||||||
|
{
|
||||||
|
public AuthenticationResult Profile { get; set; }
|
||||||
|
public string ApiBasePoint { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Cmdlet("Connect", "Acm")]
|
||||||
|
[OutputType(typeof(Connection))]
|
||||||
|
public class ConnectAcmCommand : PSCmdlet
|
||||||
|
{
|
||||||
|
[Parameter(
|
||||||
|
Mandatory = true,
|
||||||
|
ValueFromPipelineByPropertyName = true
|
||||||
|
)]
|
||||||
|
public string IssuerUrl { get; set; }
|
||||||
|
|
||||||
|
[Parameter(
|
||||||
|
Mandatory = true,
|
||||||
|
ValueFromPipelineByPropertyName = true
|
||||||
|
)]
|
||||||
|
public string ClientId { get; set; }
|
||||||
|
|
||||||
|
[Parameter(
|
||||||
|
Mandatory = true,
|
||||||
|
ValueFromPipelineByPropertyName = true
|
||||||
|
)]
|
||||||
|
public string ClientSecret { get; set; }
|
||||||
|
|
||||||
|
[Parameter(
|
||||||
|
Mandatory = true,
|
||||||
|
ValueFromPipelineByPropertyName = true
|
||||||
|
)]
|
||||||
|
public string ApiBasePoint { get; set; }
|
||||||
|
|
||||||
|
// This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called
|
||||||
|
protected override void ProcessRecord()
|
||||||
|
{
|
||||||
|
var authenticationContext = new AuthenticationContext(IssuerUrl);
|
||||||
|
var authenticationResult = authenticationContext.AcquireTokenAsync(
|
||||||
|
ClientId, new ClientCredential(ClientId, ClientSecret)).GetAwaiter().GetResult();
|
||||||
|
|
||||||
|
WriteObject(new Connection { Profile = authenticationResult, ApiBasePoint = ApiBasePoint });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
using System;
|
||||||
|
using System.Management.Automation;
|
||||||
|
using System.Management.Automation.Runspaces;
|
||||||
|
using HPC.ACM.API;
|
||||||
|
|
||||||
|
namespace HPC.ACM.PS
|
||||||
|
{
|
||||||
|
[Cmdlet("Get", "AcmNode")]
|
||||||
|
[OutputType(typeof(API.Models.Node))]
|
||||||
|
public class GetAcmNodeCommand : PSCmdlet
|
||||||
|
{
|
||||||
|
[Parameter(
|
||||||
|
Mandatory = true,
|
||||||
|
ValueFromPipelineByPropertyName = true
|
||||||
|
)]
|
||||||
|
public Connection Connection { get; set; }
|
||||||
|
|
||||||
|
private HPCWebAPI ApiClient { get; set; }
|
||||||
|
|
||||||
|
// This method gets called once for each cmdlet in the pipeline when the pipeline starts executing
|
||||||
|
protected override void BeginProcessing()
|
||||||
|
{
|
||||||
|
ApiClient = ApiClientFactory.Create(Connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called
|
||||||
|
protected override void ProcessRecord()
|
||||||
|
{
|
||||||
|
var nodes = ApiClient.GetNodes();
|
||||||
|
WriteObject(nodes, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
using System;
|
||||||
|
using System.Management.Automation;
|
||||||
|
using System.Management.Automation.Runspaces;
|
||||||
|
|
||||||
|
namespace HPC.ACM.PS
|
||||||
|
{
|
||||||
|
[Cmdlet(VerbsDiagnostic.Test,"SampleCmdlet")]
|
||||||
|
[OutputType(typeof(FavoriteStuff))]
|
||||||
|
public class TestSampleCmdletCommand : PSCmdlet
|
||||||
|
{
|
||||||
|
[Parameter(
|
||||||
|
Mandatory = true,
|
||||||
|
Position = 0,
|
||||||
|
ValueFromPipeline = true,
|
||||||
|
ValueFromPipelineByPropertyName = true)]
|
||||||
|
public int FavoriteNumber { get; set; }
|
||||||
|
|
||||||
|
[Parameter(
|
||||||
|
Position = 1,
|
||||||
|
ValueFromPipelineByPropertyName = true)]
|
||||||
|
[ValidateSet("Cat", "Dog", "Horse")]
|
||||||
|
public string FavoritePet { get; set; } = "Dog";
|
||||||
|
|
||||||
|
// This method gets called once for each cmdlet in the pipeline when the pipeline starts executing
|
||||||
|
// protected override void BeginProcessing()
|
||||||
|
// {
|
||||||
|
// WriteVerbose("Begin!");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// This method will be called for each input received from the pipeline to this cmdlet; if no input is received, this method is not called
|
||||||
|
protected override void ProcessRecord()
|
||||||
|
{
|
||||||
|
WriteObject(new FavoriteStuff {
|
||||||
|
FavoriteNumber = FavoriteNumber,
|
||||||
|
FavoritePet = FavoritePet
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method will be called once at the end of pipeline execution; if no input is received, this method is not called
|
||||||
|
// protected override void EndProcessing()
|
||||||
|
// {
|
||||||
|
// WriteVerbose("End!");
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FavoriteStuff
|
||||||
|
{
|
||||||
|
public int FavoriteNumber { get; set; }
|
||||||
|
public string FavoritePet { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Загрузка…
Ссылка в новой задаче