Example #1
0
        void EnsureSecrets(IActivityMonitor m)
        {
            if (_secretEnsured)
            {
                return;
            }
            _secretEnsured = true;
            string secret;
            var    secretOrName = Feed.Credentials?.PasswordOrSecretKeyName;

            if (Feed.Credentials.IsSecretKeyName)
            {
                secret = Client.SecretKeyStore.GetSecretKey(m, secretOrName, false);
                if (secret == null)
                {
                    m.Error($"Missing secret key. No available secret available for {secretOrName}.");
                    throw new InvalidOperationException();
                }
            }
            else
            {
                secret = secretOrName;
            }
            NuGetClient.EnsureVSSFeedEndPointCredentials(m, PackageSource.Source, secret);
        }
Example #2
0
            public bool CheckSecret(IActivityMonitor m, bool throwOnMissing)
            {
                if (_checkedSecret.HasValue)
                {
                    return(_checkedSecret.Value);
                }
                // If we are bound to a repository that has a secret, its configuration, if available, is the one to use!
                INuGetRepository repo = _baseFeed as INuGetRepository;
                bool             isBoundToProtectedRepository = repo != null && !String.IsNullOrEmpty(repo.SecretKeyName);

                if (isBoundToProtectedRepository)
                {
                    var fromRepo = !String.IsNullOrEmpty(repo.ResolveSecret(m, false));
                    if (fromRepo)
                    {
                        m.Trace($"Feed '{Name}' uses secret from repository '{repo.Name}'.");
                        _checkedSecret = true;
                        return(true);
                    }
                }
                if (Credentials != null)
                {
                    string secret;
                    if (Credentials.IsSecretKeyName == true)
                    {
                        secret         = _baseFeed.Client.SecretKeyStore.GetSecretKey(m, Credentials.PasswordOrSecretKeyName, throwOnMissing);
                        _checkedSecret = secret != null;
                        if (_checkedSecret == true)
                        {
                            m.Trace($"Feed '{Name}' uses its configured credential '{Credentials.PasswordOrSecretKeyName}'.");
                        }
                    }
                    else
                    {
                        secret         = Credentials.PasswordOrSecretKeyName;
                        _checkedSecret = true;
                        m.Trace($"Feed '{Name}' uses its configured password.");
                    }
                    if (_checkedSecret == true)
                    {
                        NuGetClient.EnsureVSSFeedEndPointCredentials(m, Url, secret);
                    }
                    else
                    {
                        m.Error($"Feed '{Name}': unable to resolve the credentials.");
                    }
                }
                else
                {
                    // There is no credential: let it be and hope it works.
                    m.Trace($"Feed '{Name}' has no available secret. It must be a public feed.");
                }
                return(_checkedSecret ?? false);
            }
Example #3
0
 protected override void OnSecretResolved(IActivityMonitor m, string secret)
 {
     NuGetClient.EnsureVSSFeedEndPointCredentials(m, Url, secret);
 }