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)); }
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); }
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); }
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); }