Ejemplo n.º 1
0
        public void ApplySettings(IActivityMonitor m)
        {
            if (!this.CheckCurrentBranch(m))
            {
                return;
            }

            var solution = _solutionDriver.GetSolution(m, allowInvalidSolution: true);

            if (solution == null)
            {
                return;
            }

            EnsureDocument();
            PackageSources.EnsureFirstElement("clear");
            foreach (var s in solution.ArtifactSources.OfType <INuGetFeed>())
            {
                EnsureFeed(m, s.Name, s.Url);
                if (s.Credentials != null)
                {
                    string password = s.Credentials.IsSecretKeyName
                                        ? _secretStore.GetSecretKey(m, s.Credentials.PasswordOrSecretKeyName, throwOnUnavailable: false)
                                        : s.Credentials.PasswordOrSecretKeyName;
                    if (password != null)
                    {
                        EnsureFeedCredentials(m, s.Name, s.Credentials.UserName, password);
                    }
                    else
                    {
                        if (s.Credentials.IsSecretKeyName)
                        {
                            m.Warn($"Secret '{s.Credentials.PasswordOrSecretKeyName}' is not known. Configuration for feed '{s.Name}' skipped.");
                        }
                        else
                        {
                            m.Warn($"Empty feed password. Configuration for feed '{s.Name}' skipped.");
                        }
                    }
                }
                else
                {
                    DeleteFeedCredentials(m, s.Name);
                }
            }
            var packages = EnsureDocument().Root.Element("packageSourceCredentials");

            if (!packages?.Nodes().Any() ?? false)
            {
                packages.Remove();
            }
            foreach (var name in _solutionSpec.RemoveNuGetSourceNames)
            {
                RemoveFeed(m, name, withCredentials: true);
            }
            // Cleanup if ever needed.
            RemoveFeed(m, "ZeroBuild-Feed");
            if (IsOnLocalBranch)
            {
                EnsureLocalFeeds(m);
            }
            else
            {
                RemoveLocalFeeds(m);
            }
            Save(m);
        }