Beispiel #1
0
        static void Main(string[] args)
        {
            var nameId       = "*****@*****.**";
            var issuer       = "http://my.tokenissuer.com";
            var audience     = "http://my.website.com";
            var role         = "User";
            var subscription = Guid.NewGuid().ToString();

            var appConfig = new AppSettingsConfigReader();
            var kvUri     = appConfig["KeyVaultUri"];

            IConfigReader kvConfig   = new CredentialsKeyVaultConfigReader(appConfig);
            var           signingKey = kvConfig["JwtExample-SigningKey"];

            Console.WriteLine("Signing key: {0}", signingKey);

            var tokenData = JwtGen.GenerateToken(signingKey, nameId, audience, issuer, role, new Dictionary <string, string> {
                { nameof(subscription), subscription }
            });

            Console.WriteLine("Token data: {0}", tokenData);

            var token = JwtGen.ParseToken(tokenData);

            Console.WriteLine("Audience: {0}", token.Audiences.First());
            Console.WriteLine("Subscription: {0}", token.Claims.SingleOrDefault(c => c.Type == nameof(subscription)).Value);

            var principal = JwtGen.ValidateToken(tokenData, signingKey, new string[] { audience }, new string[] { issuer });

            Console.WriteLine("Principal: {0}", principal.Identity.Name);
            Console.WriteLine("Subscription: {0}", principal.Claims.SingleOrDefault(c => c.Type == nameof(subscription)).Value);

            Console.ReadLine();
        }
Beispiel #2
0
        public WorkbookManager()
        {
            appSettingReader = new AppSettingsConfigReader();

            if (!cacheMgr.Exists(wbMgrCacheKey))
            {
                cacheMgr.Add(wbMgrCacheKey, workbookDetails, null, null);
            }
            else
            {
                workbookDetails = cacheMgr.Get(wbMgrCacheKey) as Dictionary <string, WorkbookDetails>;
            }
        }
Beispiel #3
0
        private static void ExecuteCommand(Arguments arguments)
        {
            var config  = new AppSettingsConfigReader();
            var command = arguments.Command.ToLower();

            if (!validCommands.Contains(command))
            {
                throw new Exception($"Invalid command. Please use one of the following commands: {validCommands.Aggregate((res, item) => res + ", " + item)}");
            }
            if (!Help.Equals(command) && !Unassign.Equals(command))
            {
                if (!arguments.Parameters.ContainsKey("--name"))
                {
                    throw new KeyNotFoundException($"The command {arguments.Command} requires the blueprint name.");
                }
            }
            string blueprintName, assignmentName, artifactName;

            switch (command)
            {
            case Create:
                blueprintName = arguments.Parameters["--name"];
                CreateBlueprint(blueprintName, config);
                break;

            case Get:
                blueprintName = arguments.Parameters["--name"];
                GetBlueprint(blueprintName, config);
                break;

            case GetArtifacts:
                blueprintName = arguments.Parameters["--name"];
                GetBlueprintArtifacts(blueprintName, config);
                break;

            case GetArtifact:
                blueprintName = arguments.Parameters["--name"];
                if (!arguments.Parameters.ContainsKey("--artifact-name"))
                {
                    throw new KeyNotFoundException($"The command {arguments.Command} requires the artifact name.");
                }
                artifactName = arguments.Parameters["--artifact-name"];
                GetBlueprintArtifact(blueprintName, artifactName, config);
                break;

            case AddArtifact:
                blueprintName = arguments.Parameters["--name"];
                if (!arguments.Parameters.ContainsKey("--artifact-name"))
                {
                    throw new KeyNotFoundException($"The command {arguments.Command} requires the artifact name.");
                }
                artifactName = arguments.Parameters["--artifact-name"];
                AddBlueprintArtifact(blueprintName, artifactName, config);
                break;

            case Publish:
                blueprintName = arguments.Parameters["--name"];
                if (!arguments.Parameters.ContainsKey("--version"))
                {
                    throw new KeyNotFoundException($"The command {arguments.Command} requires the version.");
                }
                var version = arguments.Parameters["--version"];
                PublishBlueprint(blueprintName, version, config);
                break;

            case Assign:
                blueprintName = arguments.Parameters["--name"];
                if (!arguments.Parameters.ContainsKey("--assignment-name"))
                {
                    throw new KeyNotFoundException($"The command {arguments.Command} requires the assignment name.");
                }
                assignmentName = arguments.Parameters["--assignment-name"];
                AssignBlueprint(blueprintName, assignmentName, config);
                break;

            case Unassign:
                if (!arguments.Parameters.ContainsKey("--assignment-name"))
                {
                    throw new KeyNotFoundException($"The command {arguments.Command} requires the assignment name.");
                }
                assignmentName = arguments.Parameters["--assignment-name"];
                UnassignBlueprint(assignmentName, config);
                break;

            case Delete:
                blueprintName = arguments.Parameters["--name"];
                DeleteBlueprint(blueprintName, config);
                break;

            case Help:
            default:
                ShowHelp(config);
                break;
            }
        }