示例#1
0
        internal static BuildXL.Cache.MemoizationStore.Interfaces.Caches.ICache CreateBuildCacheCache <T>(T cacheConfig, ILogger logger, string pat = null) where T : BuildCacheCacheConfig
        {
            // TODO: Remove check when all clients are updated with unified Dedup flag
            if ((ContentHashingUtilities.HashInfo.HashType.IsValidDedup()) ^ cacheConfig.UseDedupStore)
            {
                var store = cacheConfig.UseDedupStore ? "DedupStore" : "BlobStore";
                throw new ArgumentException($"HashType {ContentHashingUtilities.HashInfo.HashType} cannot be used with {store}");
            }

            var credentialProviderHelper = new CredentialProviderHelper(m => logger.Debug(m));

            if (credentialProviderHelper.IsCredentialProviderSpecified())
            {
                logger.Debug($"Credential providers path specified: '{credentialProviderHelper.CredentialHelperPath}'");
            }
            else
            {
                logger.Debug("Using current user's credentials for obtaining AAD token");
            }

            var credentialsFactory = new VssCredentialsFactory(pat, credentialProviderHelper, m => logger.Debug(m));

            logger.Diagnostic("Creating BuildCacheCache factory");
            var fileSystem = new PassThroughFileSystem(logger);

            // TODO: Once write-behind is implemented send a contentstorefunc down to the create.
            Func <IContentStore> writeThroughStore = null;

            if (!string.IsNullOrWhiteSpace(cacheConfig.CacheName))
            {
                ServiceClientRpcConfiguration rpcConfiguration;
                if (cacheConfig.GrpcPort != 0)
                {
                    rpcConfiguration = new ServiceClientRpcConfiguration((int)cacheConfig.GrpcPort);
                }
                else
                {
                    var factory    = new MemoryMappedFileGrpcPortSharingFactory(logger, cacheConfig.GrpcPortFileName);
                    var portReader = factory.GetPortReader();
                    var port       = portReader.ReadPort();

                    rpcConfiguration = new ServiceClientRpcConfiguration(port);
                }

                writeThroughStore = () =>
                                    new ServiceClientContentStore(
                    logger,
                    fileSystem,
                    cacheConfig.CacheName,
                    rpcConfiguration,
                    cacheConfig.ConnectionRetryIntervalSeconds,
                    cacheConfig.ConnectionRetryCount,
                    scenario: cacheConfig.ScenarioName);
            }

            BuildCacheServiceConfiguration buildCacheServiceConfiguration = cacheConfig.AsBuildCacheServiceConfigurationFile();

            return(BuildCacheCacheFactory.Create(fileSystem, logger, credentialsFactory, buildCacheServiceConfiguration, writeThroughStore));
        }
示例#2
0
        public void TestBadCredentialHelperPath(bool emptyPath)
        {
            var outStream  = new StringBuilder();
            var credHelper = CredentialProviderHelper.CreateInstanceForTesting(m => outStream.AppendLine(m), emptyPath ? "" : "badPath", "");

            var result = credHelper.AcquirePatAsync(new Uri("https://foo"), PatType.CacheReadWrite).Result;

            XAssert.IsTrue(result.Result == CredentialHelperResultType.NoCredentialProviderSpecified);
            XAssert.IsNull(result.Pat);
        }
示例#3
0
        public void TestBadExitCode()
        {
            var outStream  = new StringBuilder();
            var credHelper = CredentialProviderHelper.CreateInstanceForTesting(m => outStream.AppendLine(m), CmdHelper.OsShellExe, "/d /c exit 1");

            var result = credHelper.AcquirePatAsync(new Uri("https://foo"), PatType.CacheReadWrite).Result;

            XAssert.IsTrue(result.Result == CredentialHelperResultType.BadStatusCodeReturned);
            XAssert.IsTrue(outStream.ToString().Contains("Credential provider execution failed with exit code 1"));
            XAssert.IsNull(result.Pat);
        }
示例#4
0
        public void TestSuccessfulPatAcquisition()
        {
            var outStream      = new StringBuilder();
            var testAuthOutput = new AuthOutput()
            {
                Username = "",
                Password = "******",
                Message  = ""
            };
            var serialized = JsonConvert.SerializeObject(testAuthOutput);
            var credHelper = CredentialProviderHelper.CreateInstanceForTesting(m => outStream.AppendLine(m), CmdHelper.OsShellExe, $"/d /c echo {serialized}");

            var result = credHelper.AcquirePatAsync(new Uri("https://foo"), PatType.CacheReadWrite).Result;

            XAssert.IsTrue(result.Result == CredentialHelperResultType.Success);
            XAssert.IsTrue(outStream.ToString().Contains("Credentials were successfully retrieved from provider"));
            XAssert.IsTrue(outStream.ToString().Contains("testPassword"));
            XAssert.IsNotNull(result.Pat);
        }