Beispiel #1
0
        /// <summary>
        /// Executes the command using the specified settings
        /// </summary>
        /// <param name="settings">The settings.</param>
        public void Execute(UniversalPackageInstallSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (string.IsNullOrEmpty(settings.Package))
            {
                throw new CakeException("Required setting Package not specified.");
            }

            if (string.IsNullOrEmpty(settings.Source))
            {
                throw new CakeException("Required setting Source not specified.");
            }

            if (settings.TargetDirectory == null)
            {
                throw new CakeException("Required setting TargetDirectory not specified.");
            }

            var builder = new ProcessArgumentBuilder();

            builder.Append("install");

            builder.Append(settings.Package);

            if (settings.HasVersion())
            {
                builder.Append(settings.Version);
            }

            builder.Append("--source={0}", settings.Source);
            builder.Append("--target=\"{0}\"", settings.TargetDirectory.MakeAbsolute(this.Environment));

            if (settings.Overwrite)
            {
                builder.Append("--overwrite");
            }

            if (settings.PreserveTimestamps)
            {
                builder.Append("--preserve-timestamps");
            }

            if (settings.HasCredentials())
            {
                if (!settings.AreCredentialsValid())
                {
                    throw new CakeException("Both username and password must be specified for authentication");
                }

                // this is a bit hacky.  ProGet Universal Package endpoints expect a particular format
                // in which we want to protect the secret, so we stitch together the switch syntax
                builder.AppendSwitchSecret($"--user={settings.UserName}", ":", settings.Password);
            }

            Run(settings, builder);
        }
        private static void AddValue(ProcessArgumentBuilder args, string key, string value)
        {
            var quote = value.IndexOfAny(new[] { ' ', '*' }) >= 0;

            if (key.StartsWith("!", StringComparison.OrdinalIgnoreCase))
            {
                if (quote)
                {
                    args.AppendSwitchQuotedSecret(key.TrimStart('!'), value);
                }
                else
                {
                    args.AppendSwitchSecret(key.TrimStart('!'), value);
                }
            }
            else
            {
                if (quote)
                {
                    args.AppendSwitchQuoted(key, value);
                }
                else
                {
                    args.AppendSwitch(key, value);
                }
            }
        }
Beispiel #3
0
        private static void AppendSecretArguments(object s, ProcessArgumentBuilder builder, PropertyInfo pi)
        {
            var attr = pi.GetCustomAttributes <SecretArgumentAttribute>().FirstOrDefault();

            if (attr != null)
            {
                var value = pi.GetValue(s);
                if (value != null)
                {
                    builder.AppendSwitchSecret(attr.Name, "", pi.GetValue(s).ToString());
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Executes the command using the specified settings
        /// </summary>
        /// <param name="settings">The settings.</param>
        public void Execute(UniversalPackagePushSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (settings.Package == null)
            {
                throw new CakeException("Required setting Package not specified.");
            }

            if (string.IsNullOrEmpty(settings.Target))
            {
                throw new CakeException("Required setting Target not specified.");
            }

            if (!this.FileSystem.GetFile(settings.Package).Exists)
            {
                throw new CakeException($"Universal package file does not exist at '{settings.Package.FullPath}'");
            }

            var builder = new ProcessArgumentBuilder();

            builder.Append("push");

            builder.AppendQuoted(settings.Package.MakeAbsolute(Environment).FullPath);
            builder.AppendQuoted(settings.Target);

            if (settings.HasCredentials())
            {
                if (!settings.AreCredentialsValid())
                {
                    throw new CakeException("Both username and password must be specified for authentication");
                }

                // this is a bit hacky.  ProGet Universal Package endpoints expect a particular format
                // in which we want to protect the secret, so we stitch together the switch syntax
                builder.AppendSwitchSecret($"--user={settings.UserName}", ":", settings.Password);
            }

            Run(settings, builder);
        }
        /// <summary>
        /// https://github.com/fastlane/fastlane/blob/master/pem/lib/pem/options.rb
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        private ProcessArgumentBuilder ArgumentBuilder(FastlanePemConfiguration configuration)
        {
            var builder = new ProcessArgumentBuilder();

            builder.Append("pem");

            if (configuration.Development)
            {
                builder.Append("--development");
            }

            if (configuration.ActiveDaysLimit.HasValue && configuration.ActiveDaysLimit != 30)
            {
                builder.AppendSwitch("--active_days_limit", configuration.ActiveDaysLimit.ToString());
            }

            if (configuration.GenerateP12)
            {
                builder.Append("--generate_p12");
            }

            if (configuration.Force)
            {
                builder.Append("--force");
            }

            if (configuration.SavePrivateKey)
            {
                builder.Append("--save_private_key");
            }

            if (!string.IsNullOrWhiteSpace(configuration.AppIdentifier))
            {
                builder.AppendSwitch("--app_identifier", configuration.AppIdentifier);
            }

            if (!string.IsNullOrEmpty(configuration.UserName))
            {
                builder.AppendSwitch("-u", configuration.UserName);
            }

            if (!string.IsNullOrEmpty(configuration.TeamId))
            {
                builder.AppendSwitch("-b", configuration.TeamId);
            }

            if (!string.IsNullOrEmpty(configuration.TeamName))
            {
                builder.AppendSwitch("-l", configuration.TeamName);
            }

            if (!string.IsNullOrEmpty(configuration.P12Password))
            {
                builder.AppendSwitchSecret("--p12_password", configuration.P12Password);
            }

            if (!string.IsNullOrEmpty(configuration.FileName))
            {
                builder.AppendSwitch("--pem_name", configuration.FileName);
            }

            if (configuration.OutputPath != null)
            {
                builder.AppendSwitchQuoted("--output_path",
                                           configuration.OutputPath.MakeAbsolute(_environment).FullPath);
            }

            return(builder.RenderSafe());
        }
        private ProcessArgumentBuilder BuildArguments(TravisCIUploadSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var builder = new ProcessArgumentBuilder();

            builder.Append("upload");

            if (settings.LogFormat != null)
            {
                builder.AppendSwitch("--log-format", settings.LogFormat);
            }

            if (settings.Debug)
            {
                builder.Append("--debug");
            }

            if (settings.Quiet)
            {
                builder.Append("--quiet");
            }

            if (!string.IsNullOrEmpty(settings.Key))
            {
                builder.AppendSwitchSecret("--key", settings.Key);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_KEY", out string key))
            {
                builder.AppendSwitchSecret("--key", key);
            }

            if (!string.IsNullOrEmpty(settings.Bucket))
            {
                builder.AppendSwitch("--bucket", settings.Bucket);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_BUCKET", out string bucket))
            {
                builder.AppendSwitch("--bucket", bucket);
            }

            if (!string.IsNullOrEmpty(settings.CacheControl))
            {
                builder.AppendSwitchSecret("--cache-control", settings.CacheControl);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_CACHE_CONTROL", out string cache))
            {
                builder.AppendSwitchSecret("--cache-control", cache);
            }

            if (!string.IsNullOrEmpty(settings.Permissions))
            {
                builder.AppendSwitchSecret("--permissions", settings.Permissions);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_PERMISSIONS", out string permissions))
            {
                builder.AppendSwitchSecret("--permissions", permissions);
            }

            if (!string.IsNullOrEmpty(settings.Secret))
            {
                builder.AppendSwitchSecret("--secret", settings.Secret);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_SECRET", out string secret))
            {
                builder.AppendSwitchSecret("--secret", secret);
            }

            if (!string.IsNullOrEmpty(settings.Region))
            {
                builder.AppendSwitch("--s", settings.Region);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_REGION", out string region))
            {
                builder.AppendSwitch("--s", region);
            }

            if (!string.IsNullOrEmpty(settings.Slug))
            {
                builder.AppendSwitch("--repo-slug", settings.Slug);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_REPO_SLUG", out string slug))
            {
                builder.AppendSwitch("--repo-slug", slug);
            }

            if (!string.IsNullOrEmpty(settings.BuildNumber))
            {
                builder.AppendSwitch("--build-number", settings.BuildNumber);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_BUILD_NUMBER", out string buildNumber))
            {
                builder.AppendSwitch("--build-number", buildNumber);
            }

            if (!string.IsNullOrEmpty(settings.BuildId))
            {
                builder.AppendSwitch("--build-id", settings.BuildId);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_BUILD_ID", out string buildId))
            {
                builder.AppendSwitch("--build-id", buildId);
            }

            if (!string.IsNullOrEmpty(settings.JobNumber))
            {
                builder.AppendSwitch("--job-number", settings.JobNumber);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_JOB_NUMBER", out string jobNumber))
            {
                builder.AppendSwitch("--job-number", jobNumber);
            }

            if (!string.IsNullOrEmpty(settings.JobId))
            {
                builder.AppendSwitch("--job-id", settings.JobId);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_JOB_ID", out string jobId))
            {
                builder.AppendSwitch("--job-id", jobId);
            }

            if (!string.IsNullOrEmpty(settings.Concurrency))
            {
                builder.AppendSwitch("--concurrency", settings.Concurrency);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_CONCURRENCY", out string concurrency))
            {
                builder.AppendSwitch("--concurrency", concurrency);
            }

            if (!string.IsNullOrEmpty(settings.MaxSize))
            {
                builder.AppendSwitch("--max-size", settings.MaxSize);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_MAX_SIZE", out string size))
            {
                builder.AppendSwitch("--max-size", size);
            }

            if (!string.IsNullOrEmpty(settings.UploadProvider))
            {
                builder.AppendSwitch("--upload-provider", settings.UploadProvider);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_UPLOAD_PROVIDER", out string provider))
            {
                builder.AppendSwitch("--upload-provider", provider);
            }

            if (settings.Retries != null)
            {
                builder.AppendSwitch("--retries", settings.Retries.ToString());
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_RETRIES", out string retries))
            {
                builder.AppendSwitch("--retries", retries);
            }

            if (settings.TargetPaths.Any())
            {
                var paths = string.Join(":",
                                        settings.TargetPaths.Select(x => $"\"{x.MakeAbsolute(_environment).FullPath}\""));
                builder.AppendSwitch("--target-paths", paths);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_TARGET_PATHS", out string paths))
            {
                builder.AppendSwitch("--target-paths", paths);
            }

            if (settings.WorkingDirectory != null)
            {
                builder.AppendSwitchQuoted("--working-dir",
                                           settings.WorkingDirectory.MakeAbsolute(_environment).FullPath);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_WORKING_DIR", out string directory))
            {
                builder.AppendSwitchQuoted("--working-dir",
                                           ((FilePath)directory).MakeAbsolute(_environment).FullPath);
            }

            if (!string.IsNullOrEmpty(settings.SaveHost))
            {
                builder.AppendSwitch("--save-host", settings.SaveHost);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_SAVE_HOST", out string host))
            {
                builder.AppendSwitch("--save-host", host);
            }

            if (!string.IsNullOrEmpty(settings.AuthToken))
            {
                builder.AppendSwitchSecret("--auth-token", settings.AuthToken);
            }
            else if (settings.EnvironmentVariables.TryGetValue("ARTIFACTS_AUTH_TOKEN", out string authToken))
            {
                builder.AppendSwitchSecret("--auth-token", authToken);
            }

            return(builder.RenderSafe());
        }
        /// <summary>
        /// https://github.com/fastlane/fastlane/blob/master/match/lib/match/options.rb
        /// Environment Variable to store Fastlane match password - MATCH_PASSWORD
        /// </summary>
        /// <param name="match"></param>
        /// <returns></returns>
        private ProcessArgumentBuilder ArgumentBuilder(FastlaneMatchConfiguration match)
        {
            var builder = new ProcessArgumentBuilder();

            builder.Append("match");

            if (match.CertificateType != null)
            {
                builder.Append($"{match.CertificateType.ToString().ToLowerInvariant()}");
            }

            if (!string.IsNullOrEmpty(match.AppIdentifier))
            {
                builder.AppendSwitch("-a", match.AppIdentifier);
            }

            if (!string.IsNullOrEmpty(match.UserName))
            {
                builder.AppendSwitch("-u", match.UserName);
            }

            if (!string.IsNullOrEmpty(match.KeyChainName))
            {
                builder.AppendSwitch("-s", match.KeyChainName);
            }

            if (!string.IsNullOrEmpty(match.KeyChainPassword))
            {
                builder.AppendSwitchSecret("-p", match.KeyChainPassword);
            }

            if (!string.IsNullOrEmpty(match.TeamId))
            {
                builder.AppendSwitch("-b", match.TeamId);
            }

            if (!string.IsNullOrEmpty(match.GitFullName))
            {
                builder.AppendSwitch("--git_full_name", match.GitFullName);
            }

            if (!string.IsNullOrEmpty(match.GitUserEmail))
            {
                builder.AppendSwitch("--git_user_email", match.GitUserEmail);
            }

            if (!string.IsNullOrEmpty(match.GitUrl))
            {
                builder.AppendSwitch("-r", match.GitUrl);
            }

            if (!string.IsNullOrEmpty(match.GitBranch))
            {
                builder.AppendSwitch("--git_branch", match.GitBranch);
            }

            if (!string.IsNullOrEmpty(match.TeamName))
            {
                builder.AppendSwitch("-l", match.TeamName);
            }

            if (match.Force)
            {
                builder.Append("--force");
            }

            if (match.SkipConfirmation)
            {
                builder.Append("--skip_confirmation");
            }

            if (match.ShallowClone)
            {
                builder.Append("--shallow_clone");
            }

            if (match.CloneBranchDirectly)
            {
                builder.Append("--clone_branch_directly");
            }

            if (match.Workspace != null)
            {
                builder.AppendSwitchQuoted("--workspace", match.Workspace.MakeAbsolute(_environment).FullPath);
            }

            if (match.ForceForNewDevices)
            {
                builder.Append("--force_for_new_devices");
            }

            if (match.SkipDocs)
            {
                builder.Append("--skip_docs");
            }

            if (match.ReadOnly)
            {
                builder.Append("--readonly");
            }

            if (match.Verbose)
            {
                builder.Append("--verbose");
            }

            if (match.Platform != null)
            {
                builder.AppendSwitch("-o", match.Platform);
            }

            return(builder.RenderSafe());
        }
        private ProcessArgumentBuilder BuildArguments(string command, TravisCISettings settings)
        {
            var builder = new ProcessArgumentBuilder();

            builder.Append(command);

            if (settings.Interactive)
            {
                builder.Append("-i");
            }

            if (settings.NoExplode)
            {
                builder.Append("-E");
            }

            if (settings.SkipVersionCheck)
            {
                builder.Append("--skip-version-check");
            }

            if (settings.SkipCompletionCheck)
            {
                builder.Append("--skip-completion-check");
            }

            if (!string.IsNullOrEmpty(settings.ApiEndpointUrl))
            {
                builder.AppendSwitch("-e", settings.ApiEndpointUrl);
            }

            if (settings.Insecure)
            {
                builder.Append("-I");
            }

            if (settings.Pro)
            {
                builder.Append("--api-endpoint https://api.travis-ci.com/");
            }

            if (settings.Org)
            {
                builder.Append("--api-endpoint https://api.travis-ci.org/");
            }

            if (!string.IsNullOrEmpty(settings.Token))
            {
                builder.AppendSwitchSecret("-t", settings.Token);
            }

            if (settings.Debug)
            {
                builder.Append("--debug");
            }

            if (!string.IsNullOrEmpty(settings.Enterprise))
            {
                builder.AppendSwitch("-X", settings.Enterprise);
            }

            if (!string.IsNullOrEmpty(settings.Repository))
            {
                builder.AppendSwitch("-r", settings.Repository);
            }

            if (!string.IsNullOrEmpty(settings.StoreRepository))
            {
                builder.AppendSwitch("-R", settings.StoreRepository);
            }

            if (settings.Delete)
            {
                builder.Append("-d");
            }

            if (!string.IsNullOrEmpty(settings.Branch))
            {
                builder.AppendSwitch("-b", settings.Branch);
            }

            if (!string.IsNullOrEmpty(settings.Match))
            {
                builder.AppendSwitch("-m", settings.Match);
            }

            if (settings.Force)
            {
                builder.Append("-f");
            }

            return(builder.RenderSafe());
        }