Exemple #1
0
 public Registry(RegistryCredentials credentials, RegistrySettings config)
 {
     Settings = config;
     Settings.AuthHandler.Login(credentials.Registry, credentials.Username, credentials.Password);
     DistributionClient = Settings.DistributionFactory(credentials.Registry, Settings.AuthHandler);
     CatalogClient      = Settings.DistributionFactory(credentials.Registry, Settings.CatalogAuthHandler ?? Settings.AuthHandler);
 }
Exemple #2
0
        /// <summary>
        /// Hash a credential object, including username, password, and target regsitry
        /// </summary>
        /// <param name="credentials"></param>
        /// <returns></returns>
        public static string GetCredentialHash(this RegistryCredentials credentials)
        {
            var uidBytes = Encoding.UTF8.GetBytes(credentials.Username + credentials.Password + credentials.Registry);
            var hash     = System.Security.Cryptography.SHA256.Create().ComputeHash(uidBytes);

            return(Convert.ToBase64String(hash));
        }
Exemple #3
0
        public IDockerClient GetClient(IAuthHandler auth)
        {
            var host = auth.GetRegistryHost(config.IgnoreInternalAlias);

            if (string.IsNullOrEmpty(config.RegistryRoot))
            {
                /* this is convoluted. The local client needs to call back to the remote client to fetch layers or other blobs as needed, but the remote client needs to call down
                 * to the local client to actually load data, interperet manifests, etc. So, a circular dependency exists. Still waiting on an epiphany to make it cleaner.
                 */

                var httpClient = new HttpClient(new AuthenticatedParameterizedHttpClientHandler(ClientTokenCallback(auth)))
                {
                    BaseAddress = new Uri(RegistryCredentials.HostToEndpoint(host))
                };
                var service     = RestService.For <IDockerDistribution>(httpClient);
                var localClient = new LocalDockerClient(config, indexer, extractor, auth, loggerFactory.CreateLogger <LocalDockerClient>())
                {
                    RegistryRoot = config.RegistryCache, Host = host
                };
                var remoteClient = new RemoteDockerClient(config, auth, service, localClient, cacheFactory)
                {
                    Host = host
                };
                localClient.RecurseClient = remoteClient;

                var cachedClient = new CachedDockerClient(config, remoteClient, cacheFactory, auth)
                {
                    Host = host, CacheLocalData = config.LocalCache
                };

                return(cachedClient);
            }
            else if (config.LocalCache)
            {
                var localClient = new LocalDockerClient(config, indexer, extractor, auth, loggerFactory.CreateLogger <LocalDockerClient>())
                {
                    RegistryRoot = config.RegistryRoot
                };
                var cachedClient = new CachedDockerClient(config, localClient, cacheFactory, auth)
                {
                    Host = host, CacheLocalData = config.LocalCache
                };
                return(cachedClient);
            }
            else
            {
                return(new LocalDockerClient(config, indexer, extractor, auth, loggerFactory.CreateLogger <LocalDockerClient>())
                {
                    RegistryRoot = config.RegistryRoot
                });
            }
        }