/// <summary> /// Generation mode - create a new token for testing /// </summary> /// <param name="commandLine">Options from the command line.</param> /// <returns>Exit code to return from this process.</returns> public static int Generate(GenerateCommandLine commandLine) { var entitlement = NodeEntitlementsBuilder.Build(commandLine); var signingCert = FindCertificate("signing", commandLine.SignatureThumbprint); var encryptionCert = FindCertificate("encryption", commandLine.EncryptionThumbprint); var result = entitlement.Combine(signingCert, encryptionCert, GenerateToken); if (!result.HasValue) { return(LogErrors(result.Errors)); } var token = result.Value; if (string.IsNullOrEmpty(commandLine.TokenFile)) { _logger.LogInformation("Token: {JWT}", token); return(0); } var fileInfo = new FileInfo(commandLine.TokenFile); _logger.LogInformation("Token file: {FileName}", fileInfo.FullName); try { File.WriteAllText(fileInfo.FullName, token); return(0); } catch (Exception ex) { _logger.LogError(0, ex, ex.Message); return(-1); } }
/// <summary> /// Build an instance of <see cref="NodeEntitlements"/> from the information supplied on the /// command line by the user /// </summary> /// <param name="commandLine">Command line parameters supplied by the user.</param> /// <returns>Either a usable (and completely valid) <see cref="NodeEntitlements"/> or a set /// of errors.</returns> public static Errorable <NodeEntitlements> Build(GenerateCommandLine commandLine) { var builder = new NodeEntitlementsBuilder(commandLine); return(builder.Build()); }