├── renovate.json ├── AltinnCLITest ├── Properties │ └── launchSettings.json ├── AltinnCLITest.csproj ├── TestDataBuilder.cs ├── ApplicationManagerTest.cs ├── Commands.json └── OptionBuilderTest.cs ├── AltinnCLI ├── Properties │ └── launchSettings.json ├── Services │ ├── Interfaces │ │ └── IInstantiation.cs │ └── InstantiationService.cs ├── Models │ ├── schemas.altinn.no.services.intermediary.serviceinitiation.2009.10.xsd │ ├── SentItems.cs │ ├── CfgCommandList.cs │ ├── CfgSubCommand.cs │ ├── CfgCommand.cs │ ├── CfgOption.cs │ ├── InstanceResponseMessage.cs │ └── ServiceOwner.cs ├── Commands │ ├── Core │ │ ├── IHelp.cs │ │ ├── IValidate.cs │ │ ├── ICommand.cs │ │ ├── NumberOption.cs │ │ ├── IOption.cs │ │ ├── ISubCommandHandler.cs │ │ ├── Option.cs │ │ ├── SubCommandHandlerBase.cs │ │ └── OptionBuilder.cs │ ├── Quit │ │ └── QuitCommand.cs │ ├── Batch │ │ ├── BatchCommand.cs │ │ └── SubCommandHandlers │ │ │ └── CreateInstancesA2Handler.cs │ ├── Application │ │ ├── ApplicationCommand.cs │ │ └── SubCommandHandlers │ │ │ ├── GetInstancesSubCommandHandler.cs │ │ │ └── CreateInstanceSubCommandHandler.cs │ ├── Storage │ │ ├── StorageCommand.cs │ │ └── SubCommandHandlers │ │ │ ├── UploadData.cs │ │ │ ├── GetInstanceHandler.cs │ │ │ └── GetDataHandler.cs │ ├── Help │ │ └── HelpCommand.cs │ └── DefinitionFiles │ │ └── Commands.json ├── Helpers │ ├── IFileWrapper.cs │ ├── Globals.cs │ ├── FileOption.cs │ ├── ThumbPrintOption.cs │ ├── MultipartContentBuilder.cs │ ├── FileWrapper.cs │ └── Validator.cs ├── Configurations │ └── InstantiationConfig.cs ├── Extensions │ └── Extensions.cs ├── AltinnCLI.csproj ├── appsettings.json ├── Clients │ ├── DataClient.cs │ └── InstanceClient.cs ├── Program.cs └── ApplicationManager.cs ├── README.md ├── LICENSE ├── AltinnCLI.sln └── .gitignore /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "enabled": false 3 | } 4 | -------------------------------------------------------------------------------- /AltinnCLITest/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "WSL": { 4 | "commandName": "WSL2", 5 | "distributionName": "" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /AltinnCLI/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "AltinnCli": { 4 | "commandName": "Project", 5 | "commandLineArgs": "Storage" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /AltinnCLI/Services/Interfaces/IInstantiation.cs: -------------------------------------------------------------------------------- 1 | namespace AltinnCLI.Services.Interfaces 2 | { 3 | public interface IInstantiation 4 | { 5 | public bool Altinn2BatchInstantiation(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /AltinnCLI/Models/schemas.altinn.no.services.intermediary.serviceinitiation.2009.10.xsd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/altinn/altinn-cli/main/AltinnCLI/Models/schemas.altinn.no.services.intermediary.serviceinitiation.2009.10.xsd -------------------------------------------------------------------------------- /AltinnCLI/Commands/Core/IHelp.cs: -------------------------------------------------------------------------------- 1 | namespace AltinnCLI.Commands.Core 2 | { 3 | public interface IHelp 4 | { 5 | string Name { get; } 6 | 7 | string Description { get; } 8 | 9 | string Usage { get; } 10 | 11 | string GetHelp(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /AltinnCLI/Commands/Core/IValidate.cs: -------------------------------------------------------------------------------- 1 | namespace AltinnCLI.Commands.Core 2 | { 3 | public interface IValidate 4 | { 5 | public bool Validate(); 6 | 7 | public bool IsValid { get; set; } 8 | 9 | public string ErrorMessage { get; set; } 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AltinnCLI/Models/SentItems.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace AltinnCLI.Models 5 | { 6 | public class SentItems 7 | { 8 | [JsonPropertyName("reference")] 9 | public List Reference; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AltinnCLI/Models/CfgCommandList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace AltinnCLI.Models 5 | { 6 | public class CfgCommandList 7 | { 8 | [JsonPropertyName("Commands")] 9 | public List Commands { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AltinnCLI/Helpers/IFileWrapper.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace AltinnCLI.Helpers 4 | { 5 | public interface IFileWrapper 6 | { 7 | bool SaveToFile(string filePath, string fileName, Stream stream); 8 | 9 | bool SaveToFile(string filePath, string fileName, string content); 10 | 11 | MemoryStream GetFile(string fullFileName); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /AltinnCLI/Models/CfgSubCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace AltinnCLI.Models 5 | { 6 | public class CfgSubCommand 7 | { 8 | [JsonPropertyName("Name")] 9 | public string Name { get; set; } 10 | 11 | [JsonPropertyName("Options")] 12 | public List Options { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AltinnCLI/Models/CfgCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace AltinnCLI.Models 5 | { 6 | public class CfgCommand 7 | { 8 | [JsonPropertyName("Name")] 9 | public string Name { get; set; } 10 | 11 | [JsonPropertyName("SubCommands")] 12 | public List SubCommands { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Altinn CLI 2 | 3 | ### This project is discontinued! 4 | 5 | As of 05. september 2023 we will stop maintaining this project. Dependencies will not be updated and issues will remain unhandled and unresolved. We will no longer watch the reposotitory for updates. 6 | 7 | A reference implementation for using APIs as an application owner can be found here: 8 | https://github.com/Altinn/altinn-application-owner-system 9 | 10 | 11 | --- 12 | 13 | Command line tool for manual interaction with Altinn 3 applications through their APIs. 14 | -------------------------------------------------------------------------------- /AltinnCLI/Configurations/InstantiationConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace AltinnCLI.Configurations 4 | { 5 | public class InstantiationConfig 6 | { 7 | public Dictionary ApplicationIdLookup { get; set; } = new Dictionary(); 8 | public Dictionary DataTypeLookup { get; set; } = new Dictionary(); 9 | public string InputFolder { get; set; } 10 | public string OutputFolder { get; set; } 11 | public string ErrorFolder { get; set; } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /AltinnCLI/Helpers/Globals.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.Json; 6 | using System.Text.Json.Serialization; 7 | using System.Threading.Tasks; 8 | 9 | namespace AltinnCLI.Helpers 10 | { 11 | public static class Globals 12 | { 13 | 14 | public static JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions 15 | { 16 | WriteIndented = true, 17 | PropertyNameCaseInsensitive = true, 18 | Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) } 19 | }; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /AltinnCLI/Models/CfgOption.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace AltinnCLI.Models 4 | { 5 | public class CfgOption 6 | { 7 | [JsonPropertyName("Name")] 8 | public string Name { get; set; } 9 | 10 | [JsonPropertyName("type")] 11 | public string DataType { get; set; } 12 | 13 | [JsonPropertyName("valuerangeange")] 14 | public string Valuerangeange { get; set; } 15 | 16 | [JsonPropertyName("description")] 17 | public string Description { get; set; } 18 | 19 | [JsonPropertyName("apiname")] 20 | public string Apiname { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /AltinnCLI/Helpers/FileOption.cs: -------------------------------------------------------------------------------- 1 | using AltinnCLI.Commands.Core; 2 | using System.IO; 3 | 4 | namespace AltinnCLI.Helpers 5 | { 6 | public class FileOption : Option 7 | { 8 | /// 9 | /// Verifies if the input parameters are valid. 10 | /// 11 | /// 12 | public override bool Validate() 13 | { 14 | if (File.Exists(Value)) 15 | { 16 | return true; 17 | } 18 | 19 | ErrorMessage = $"Invalid value for parameter: {Name}, file: {Value} was not found"; 20 | return false; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /AltinnCLI/Commands/Quit/QuitCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using AltinnCLI.Commands.Core; 4 | 5 | namespace AltinnCLI.Commands.Quit 6 | { 7 | class QuitCommand : ICommand, IHelp 8 | { 9 | public string Name => "Quit"; 10 | 11 | public string Description => "\tCommand for exiting Altinn CLI."; 12 | 13 | public string Usage => "Quit"; 14 | 15 | public string GetHelp() 16 | { 17 | return "Quit"; 18 | } 19 | 20 | public void Run(ISubCommandHandler commandHandler = null) 21 | { 22 | Environment.Exit(0); 23 | } 24 | 25 | public void Run(Dictionary input) 26 | { 27 | throw new NotImplementedException(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /AltinnCLI/Commands/Core/ICommand.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace AltinnCLI.Commands.Core 4 | { 5 | /// 6 | /// Interface that defines required method and properties for a cli command 7 | /// 8 | public interface ICommand 9 | { 10 | /// 11 | /// Run the supported command handler 12 | /// 13 | /// the command handler to execute 14 | void Run(ISubCommandHandler commandHandler = null); 15 | 16 | /// 17 | /// Parses the dictionary and run command. Used mainly by Help 18 | /// 19 | /// Dictionary with the cli input paramters 20 | void Run(Dictionary input); 21 | 22 | /// 23 | /// Gets the name of the service 24 | /// 25 | string Name { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AltinnCLI/Helpers/ThumbPrintOption.cs: -------------------------------------------------------------------------------- 1 | using AltinnCLI.Commands.Core; 2 | using System; 3 | using System.Security.Cryptography.X509Certificates; 4 | 5 | namespace AltinnCLI.Helpers 6 | { 7 | public class ThumbPrintOption : Option 8 | { 9 | /// 10 | /// Verifies if the input parameters are valid. 11 | /// 12 | /// 13 | public override bool Validate() 14 | { 15 | var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); 16 | store.Open(OpenFlags.ReadOnly); 17 | var certificates = store.Certificates; 18 | 19 | foreach (var certificate in certificates) 20 | { 21 | if (string.Equals(certificate.Thumbprint, Value, StringComparison.OrdinalIgnoreCase)) 22 | { 23 | return true; 24 | } 25 | } 26 | 27 | ErrorMessage = $"No ceriticate was found for the thumbprint:{Value}"; 28 | return false; 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Altinn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /AltinnCLI/Commands/Batch/BatchCommand.cs: -------------------------------------------------------------------------------- 1 | using AltinnCLI.Commands.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace AltinnCLI.Commands.Batch 6 | { 7 | public class BatchCommand : ICommand, IHelp 8 | { 9 | public string Name => "Batch"; 10 | 11 | public string Description => $"\tProvides different prefill options."; 12 | 13 | public string Usage => $@"Batch "; 14 | 15 | public string GetHelp() 16 | { 17 | throw new NotImplementedException(); 18 | } 19 | 20 | public void Run(ISubCommandHandler commandHandler = null) 21 | { 22 | if (commandHandler == null) 23 | { 24 | Console.WriteLine(); 25 | Console.WriteLine(Usage); 26 | Console.WriteLine(); 27 | } 28 | else 29 | { 30 | commandHandler.Run(); 31 | } 32 | } 33 | 34 | public void Run(Dictionary input) 35 | { 36 | Console.WriteLine(); 37 | Console.WriteLine(Usage); 38 | Console.WriteLine(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /AltinnCLI/Commands/Core/NumberOption.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace AltinnCLI.Commands.Core 5 | { 6 | public class NumberOption : Option 7 | { 8 | public override bool Validate() 9 | { 10 | try 11 | { 12 | if (EqualityComparer.Default.Equals(TryParse(Value))) 13 | { 14 | IsValid = false; 15 | ErrorMessage = $"The value for Option :{Name} is not on correct format.\n"; 16 | return false; 17 | } 18 | else if (CheckRange() == false) 19 | { 20 | IsValid = false; 21 | ErrorMessage = $"The value for Option :{Name} is not out of range. Valid range is {Range} \n"; 22 | } 23 | 24 | isValid = true; 25 | } 26 | catch (Exception ex) 27 | { 28 | IsValid = false; 29 | ErrorMessage = $"Invalid Parameter value for paramter: <{Name}>, {ex.Message}"; 30 | return false; 31 | } 32 | return true; 33 | } 34 | 35 | protected override bool CheckRange() 36 | { 37 | return true; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /AltinnCLI/Models/InstanceResponseMessage.cs: -------------------------------------------------------------------------------- 1 | using Altinn.Platform.Storage.Interface.Models; 2 | using System; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace AltinnCLI.Models 6 | { 7 | /// 8 | /// Entity that represents the respons on a Instance request 9 | /// 10 | public class InstanceResponseMessage 11 | { 12 | /// 13 | /// Gets or sets the total number of instances found 14 | /// 15 | [JsonPropertyName("totalHits")] 16 | public long TotalHits { get; set; } 17 | 18 | /// 19 | /// Gets or sets the number of instances in "this" response 20 | /// 21 | [JsonPropertyName("count")] 22 | public long Count { get; set; } 23 | 24 | /// 25 | /// URL to fetch next page with instances 26 | /// 27 | [JsonPropertyName("next")] 28 | public Uri Next { get; set; } 29 | 30 | /// 31 | /// Gets or sets the Self link 32 | /// 33 | [JsonPropertyName("self")] 34 | public Uri Self { get; set; } 35 | 36 | /// 37 | /// Gets or sets the instances 38 | /// 39 | [JsonPropertyName("instances")] 40 | public Instance[] Instances { get; set; } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /AltinnCLI/Commands/Core/IOption.cs: -------------------------------------------------------------------------------- 1 | namespace AltinnCLI.Commands.Core 2 | { 3 | /// 4 | /// Interface that defines the propertioes and methods that 5 | /// shall be implemented by an Option class 6 | /// 7 | public interface IOption : IValidate 8 | { 9 | /// 10 | /// The Name og the oprtion that must match the Name 11 | /// of the otion in the CommandDefinition file 12 | /// 13 | public string Name { get; set; } 14 | 15 | /// 16 | /// The name of the opsjon in ther API. 17 | /// 18 | public string ApiName { get; set; } 19 | 20 | /// 21 | /// The value of the option as a string 22 | /// 23 | string Value { get; set; } 24 | 25 | /// 26 | /// Defines if the option is defined with a vlue in 27 | /// the command line 28 | /// 29 | bool IsAssigned { get; set; } 30 | 31 | /// 32 | /// The description of the option that will be used by help 33 | /// 34 | string Description { get; set; } 35 | 36 | /// 37 | /// Valid range for the paramtere. 38 | /// 39 | string Range { get; set; } 40 | 41 | /// 42 | /// Gets the typed value of the option as defined 43 | /// in the option definition 44 | /// 45 | /// 46 | object GetValue(); 47 | 48 | } 49 | } -------------------------------------------------------------------------------- /AltinnCLITest/AltinnCLITest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Library 5 | net6.0 6 | 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | PreserveNewest 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /AltinnCLI/Helpers/MultipartContentBuilder.cs: -------------------------------------------------------------------------------- 1 | using Altinn.Platform.Storage.Interface.Models; 2 | using System.IO; 3 | using System.Net.Http; 4 | using System.Net.Http.Headers; 5 | using System.Text; 6 | using System.Text.Json; 7 | 8 | namespace AltinnCLI.Helpers 9 | { 10 | public class MultipartContentBuilder 11 | { 12 | private readonly MultipartFormDataContent _builder; 13 | 14 | public MultipartContentBuilder(Instance instanceTemplate) 15 | { 16 | _builder = new MultipartFormDataContent(); 17 | if (instanceTemplate != null) 18 | { 19 | StringContent instanceContent = new(JsonSerializer.Serialize(instanceTemplate), Encoding.UTF8, "application/json"); 20 | 21 | _builder.Add(instanceContent, "instance"); 22 | } 23 | } 24 | 25 | public MultipartContentBuilder AddDataElement(string elementType, Stream stream, string contentType) 26 | { 27 | StreamContent streamContent = new(stream); 28 | streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse(contentType); 29 | 30 | _builder.Add(streamContent, elementType); 31 | 32 | return this; 33 | } 34 | 35 | public MultipartContentBuilder AddDataElement(string elementType, StringContent content) 36 | { 37 | _builder.Add(content, elementType); 38 | 39 | return this; 40 | } 41 | 42 | public MultipartFormDataContent Build() 43 | { 44 | return _builder; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AltinnCLI/Extensions/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | 4 | namespace AltinnCLI.Extensions 5 | { 6 | using System; 7 | 8 | /// 9 | /// Extension methods for finding type that implements specific Interface in an Assembly 10 | /// 11 | public static class Extension 12 | { 13 | /// 14 | /// Get all Types that implments type T in the assembly 15 | /// 16 | /// 17 | /// 18 | /// 19 | public static List GetTypesAssignableFrom(this Assembly assembly) 20 | { 21 | return assembly.GetTypesAssignableFrom(typeof(T)); 22 | } 23 | 24 | /// 25 | /// Get all Types that implements the compareType 26 | /// 27 | /// Assembly to search for types 28 | /// Type to search for 29 | /// List of types that is of requested type 30 | public static List GetTypesAssignableFrom(this Assembly assembly, Type compareType) 31 | { 32 | List ret = new(); 33 | foreach (var type in assembly.DefinedTypes) 34 | { 35 | if (compareType.IsAssignableFrom(type) && compareType != type) 36 | { 37 | ret.Add(type); 38 | } 39 | } 40 | return ret; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /AltinnCLI/Commands/Application/ApplicationCommand.cs: -------------------------------------------------------------------------------- 1 | using AltinnCLI.Commands.Core; 2 | using Microsoft.Extensions.Logging; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace AltinnCLI.Commands.Application 8 | { 9 | class ApplicationCommand : ICommand, IHelp 10 | { 11 | /// 12 | /// Application logger 13 | /// 14 | private static ILogger _logger; 15 | 16 | public ApplicationCommand(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | public string Name 22 | { 23 | get 24 | { 25 | return "Application"; 26 | } 27 | } 28 | 29 | public string Description 30 | { 31 | get 32 | { 33 | return "Tools for creating an application"; 34 | } 35 | } 36 | 37 | public string Usage 38 | { 39 | get 40 | { 41 | return "DO NOT USE!"; 42 | } 43 | } 44 | 45 | public string GetHelp() 46 | { 47 | return ""; 48 | } 49 | 50 | public virtual void Run(ISubCommandHandler subCommandHandler) 51 | { 52 | if (subCommandHandler != null) 53 | { 54 | subCommandHandler.Run(); 55 | } 56 | } 57 | 58 | public void Run(Dictionary input) 59 | { 60 | throw new NotImplementedException(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /AltinnCLI/Commands/Core/ISubCommandHandler.cs: -------------------------------------------------------------------------------- 1 | using AltinnCLI.Helpers; 2 | using System.Collections.Generic; 3 | 4 | namespace AltinnCLI.Commands.Core 5 | { 6 | /// 7 | /// Interface that defines required method and properties for a SubCommandHandler 8 | /// 9 | public interface ISubCommandHandler : IValidate 10 | { 11 | /// 12 | /// 13 | /// 14 | /// 15 | bool Run(); 16 | 17 | /// 18 | /// Name of the command handler 19 | /// 20 | string Name { get; } 21 | 22 | /// 23 | /// Name of the command for which the command is implemented 24 | /// 25 | string CommandProvider { get; } 26 | 27 | /// 28 | /// Dictionary with cli input options 29 | /// 30 | Dictionary DictOptions { get; set; } 31 | 32 | /// 33 | /// 34 | /// 35 | public List SelectableCliOptions { get; set; } 36 | 37 | /// 38 | /// Dictionary with cli input options 39 | /// 40 | List CliOptions { get; set; } 41 | 42 | /// 43 | /// Dictionary with cli input options 44 | /// 45 | IFileWrapper CliFileWrapper { get; set; } 46 | 47 | /// 48 | /// Builds the options that can control the command. 49 | /// 50 | void BuildSelectableCommands(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /AltinnCLI.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29326.143 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AltinnCLI", "AltinnCLI\AltinnCLI.csproj", "{1E3B916E-2F07-4B8E-AF20-118DCDDE8993}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AltinnCLITest", "AltinnCLITest\AltinnCLITest.csproj", "{187D84CF-2B1C-4082-86C7-842C80E18AC3}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1E3B916E-2F07-4B8E-AF20-118DCDDE8993}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {1E3B916E-2F07-4B8E-AF20-118DCDDE8993}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {1E3B916E-2F07-4B8E-AF20-118DCDDE8993}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {1E3B916E-2F07-4B8E-AF20-118DCDDE8993}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {187D84CF-2B1C-4082-86C7-842C80E18AC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {187D84CF-2B1C-4082-86C7-842C80E18AC3}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {187D84CF-2B1C-4082-86C7-842C80E18AC3}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {187D84CF-2B1C-4082-86C7-842C80E18AC3}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {4F2E92CC-992B-4E97-8A15-922D8EFAF81B} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /AltinnCLI/Commands/Storage/StorageCommand.cs: -------------------------------------------------------------------------------- 1 | using AltinnCLI.Commands.Core; 2 | using Microsoft.Extensions.Logging; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace AltinnCLI.Commands.Storage 7 | { 8 | public class StorageCommand : ICommand, IHelp 9 | { 10 | /// 11 | /// Application logger 12 | /// 13 | private static ILogger _logger; 14 | 15 | public StorageCommand(ILogger logger) 16 | { 17 | _logger = logger; 18 | } 19 | 20 | /// 21 | /// 22 | /// 23 | /// 24 | public virtual void Run(ISubCommandHandler subCommandHandler) 25 | { 26 | if (subCommandHandler != null) 27 | { 28 | subCommandHandler.Run(); 29 | } 30 | else 31 | { 32 | _logger.LogError($"Missing sub command, use help to find avilable sub commands."); 33 | } 34 | } 35 | 36 | public string Name 37 | { 38 | get 39 | { 40 | return "Storage"; 41 | } 42 | } 43 | 44 | public string Description 45 | { 46 | get 47 | { 48 | return "\tCommands for interacting with the Storage"; 49 | } 50 | } 51 | 52 | public string Usage 53 | { 54 | get 55 | { 56 | return "storage -