Пример #1
0
        internal LocalWorkspace(
            IPulumiCmd cmd,
            LocalWorkspaceOptions?options,
            CancellationToken cancellationToken)
            : base(cmd)
        {
            string?dir        = null;
            var    readyTasks = new List <Task>();

            if (options != null)
            {
                if (!string.IsNullOrWhiteSpace(options.WorkDir))
                {
                    dir = options.WorkDir;
                }

                this.PulumiHome      = options.PulumiHome;
                this.Program         = options.Program;
                this.Logger          = options.Logger;
                this.SecretsProvider = options.SecretsProvider;

                if (options.EnvironmentVariables != null)
                {
                    this.EnvironmentVariables = new Dictionary <string, string?>(options.EnvironmentVariables);
                }
            }

            if (string.IsNullOrWhiteSpace(dir))
            {
                // note that csharp doesn't guarantee that Path.GetRandomFileName returns a name
                // for a file or folder that doesn't already exist.
                // we should be OK with the "automation-" prefix but a collision is still
                // theoretically possible
                dir = Path.Combine(Path.GetTempPath(), $"automation-{Path.GetRandomFileName()}");
                Directory.CreateDirectory(dir);
                this._ownsWorkingDir = true;
            }

            this.WorkDir = dir;

            readyTasks.Add(this.PopulatePulumiVersionAsync(cancellationToken));

            if (options?.ProjectSettings != null)
            {
                readyTasks.Add(this.InitializeProjectSettingsAsync(options.ProjectSettings, cancellationToken));
            }

            if (options?.StackSettings != null && options.StackSettings.Any())
            {
                foreach (var pair in options.StackSettings)
                {
                    readyTasks.Add(this.SaveStackSettingsAsync(pair.Key, pair.Value, cancellationToken));
                }
            }

            this._readyTask = Task.WhenAll(readyTasks);
        }
Пример #2
0
 internal Workspace(IPulumiCmd cmd)
 {
     this._cmd = cmd;
 }