/// <summary> /// Creates the default GCloud context from the current environment. /// </summary> /// <param name="processService">The process service to use.</param> /// <param name="credentialsStore">The credentials store service to use.</param> public GCloudContext(Lazy <IProcessService> processService, ICredentialsStore credentialsStore) { CredentialsPath = credentialsStore.CurrentAccountPath; ProjectId = credentialsStore.CurrentProjectId; _processService = processService; _versionsTask = GetGcloudOutputAsync <CloudSdkVersions>("version"); }
public LoginController(IEventAggregator eventAggregator, IRegionManager regionManager, ILoginView view, ILinqApi api, ICredentialsStore store, IAsyncManager manager) { eventAggregator.GetEvent<InitialViewActivatedEvent>().Subscribe( DoLogin); this.region = regionManager.Regions[RegionNames.DialogRegion]; this.eventAggregator = eventAggregator; this.view = view; this.api = api; this.store = store; this.manager = manager; this.region.Add(this.view); this.username = store.Username; this.password = store.Password; this.view.DataContext = this; this.provideCredentialsCommand = new DelegateCommand<object>(this.ProvideCredentials, o => !(String.IsNullOrEmpty(this.Username) || String.IsNullOrEmpty(this.Password))); }
public CbsNode(IClientCredentialsFactory identityFactory, string iotHubHostName, IAuthenticator authenticator, ICredentialsStore credentialsStore) { this.clientCredentialsFactory = identityFactory; this.iotHubHostName = iotHubHostName; this.authenticator = authenticator; this.credentialsStore = credentialsStore; this.authenticationUpdateTask = Task.FromResult(AmqpAuthentication.Unauthenticated); }
public void TestDefault_DefersToPackage() { ICredentialsStore expectedCredentialsStore = Mock.Of <ICredentialsStore>(); GoogleCloudExtensionPackage.Instance = Mock.Of <IGoogleCloudExtensionPackage>(p => p.CredentialsStore == expectedCredentialsStore); Assert.AreEqual(expectedCredentialsStore, CredentialsStore.Default); }
public static AmqpSettings GetDefaultAmqpSettings( string iotHubHostName, IAuthenticator authenticator, IClientCredentialsFactory identityFactory, ILinkHandlerProvider linkHandlerProvider, IConnectionProvider connectionProvider, ICredentialsStore credentialsStore) { Preconditions.CheckNotNull(authenticator, nameof(authenticator)); Preconditions.CheckNotNull(identityFactory, nameof(identityFactory)); Preconditions.CheckNotNull(linkHandlerProvider, nameof(linkHandlerProvider)); Preconditions.CheckNonWhiteSpace(iotHubHostName, nameof(iotHubHostName)); Preconditions.CheckNotNull(connectionProvider, nameof(connectionProvider)); var settings = new AmqpSettings { AllowAnonymousConnection = true, RequireSecureTransport = true, RuntimeProvider = new AmqpRuntimeProvider(linkHandlerProvider, true, identityFactory, authenticator, iotHubHostName, connectionProvider, credentialsStore) }; // Add all transport providers we want to support. AddSaslProvider(); AddAmqpProvider(); return(settings); void AddSaslProvider() { var saslProvider = new SaslTransportProvider { MaxFrameSize = 65536, }; saslProvider.Versions.Add(Constants.AmqpVersion100); // TODO: Verify if this handler still needs to be added. It looks like at some point in the past // SASL EXTERNAL was used to do CBS. Since then we have moved away from that and are using // SASL ANONYMOUS to do CBS. So this may not be needed anymore depending on back-compat // needs (i.e. old clients that are still using EXTERNAL for CBS). // saslProvider.AddHandler(new SaslExternalHandler()); saslProvider.AddHandler(new SaslAnonymousHandler()); // CBS for other clients // This handler implements SAS key based auth. saslProvider.AddHandler(new SaslPlainHandler(new EdgeHubSaslPlainAuthenticator(authenticator, identityFactory, iotHubHostName))); settings.TransportProviders.Add(saslProvider); } void AddAmqpProvider() { var amqpProvider = new AmqpTransportProvider(); amqpProvider.Versions.Add(Constants.AmqpVersion100); settings.TransportProviders.Add(amqpProvider); } }
public WebTokenCreator( IExceptionHandler exceptionHandler, IOAuthWebRequestGenerator oAuthWebRequestGenerator, ICredentialsStore credentialsStore, ITwitterRequestHandler twitterRequestHandler) { _exceptionHandler = exceptionHandler; _oAuthWebRequestGenerator = oAuthWebRequestGenerator; _credentialsStore = credentialsStore; _twitterRequestHandler = twitterRequestHandler; }
public WebTokenCreator( IExceptionHandler exceptionHandler, IOAuthWebRequestGenerator oAuthWebRequestGenerator, ICredentialsStore credentialsStore, ITwitterRequestHandler twitterRequestHandler) { _exceptionHandler = exceptionHandler; _oAuthWebRequestGenerator = oAuthWebRequestGenerator; _credentialsStore = credentialsStore; _twitterRequestHandler = twitterRequestHandler; }
protected override void Load(ContainerBuilder builder) { // ITransportSettings builder.Register(c => new DefaultTransportSettings(this.scheme, HostName, this.port, this.tlsCertificate)) .As <ITransportSettings>() .SingleInstance(); // ITransportListenerProvider builder.Register(c => new AmqpTransportListenerProvider()) .As <ITransportListenerProvider>() .SingleInstance(); // ILinkHandlerProvider builder.Register( c => { IMessageConverter <AmqpMessage> messageConverter = new AmqpMessageConverter(); IMessageConverter <AmqpMessage> twinMessageConverter = new AmqpTwinMessageConverter(); IMessageConverter <AmqpMessage> directMethodMessageConverter = new AmqpDirectMethodMessageConverter(); ILinkHandlerProvider linkHandlerProvider = new LinkHandlerProvider(messageConverter, twinMessageConverter, directMethodMessageConverter); return(linkHandlerProvider); }) .As <ILinkHandlerProvider>() .SingleInstance(); // Task<AmqpProtocolHead> builder.Register( async c => { var identityFactory = c.Resolve <IClientCredentialsFactory>(); var transportSettings = c.Resolve <ITransportSettings>(); var transportListenerProvider = c.Resolve <ITransportListenerProvider>(); var linkHandlerProvider = c.Resolve <ILinkHandlerProvider>(); ICredentialsStore credentialsStore = await c.Resolve <Task <ICredentialsStore> >(); IAuthenticator authenticator = await c.Resolve <Task <IAuthenticator> >(); IConnectionProvider connectionProvider = await c.Resolve <Task <IConnectionProvider> >(); AmqpSettings amqpSettings = AmqpSettingsProvider.GetDefaultAmqpSettings( this.iotHubHostName, authenticator, identityFactory, linkHandlerProvider, connectionProvider, credentialsStore); return(new AmqpProtocolHead( transportSettings, amqpSettings, transportListenerProvider)); }) .As <Task <AmqpProtocolHead> >() .SingleInstance(); base.Load(builder); }
public AmqpRuntimeProvider(ILinkHandlerProvider linkHandlerProvider, bool requireSecureTransport, IClientCredentialsFactory clientCredentialsFactory, IAuthenticator authenticator, string iotHubHostName, IConnectionProvider connectionProvider, ICredentialsStore credentialsStore) { this.linkHandlerProvider = Preconditions.CheckNotNull(linkHandlerProvider, nameof(linkHandlerProvider)); this.requireSecureTransport = Preconditions.CheckNotNull(requireSecureTransport, nameof(requireSecureTransport)); this.clientCredentialsFactory = Preconditions.CheckNotNull(clientCredentialsFactory, nameof(clientCredentialsFactory)); this.iotHubHostName = Preconditions.CheckNonWhiteSpace(iotHubHostName, nameof(iotHubHostName)); this.authenticator = Preconditions.CheckNotNull(authenticator, nameof(authenticator)); this.connectionProvider = Preconditions.CheckNotNull(connectionProvider, nameof(connectionProvider)); this.credentialsStore = Preconditions.CheckNotNull(credentialsStore, nameof(credentialsStore)); }
internal KubectlContext( IFileSystem fileSystem, Lazy <IProcessService> processService, ICredentialsStore credentialsStore) : base(processService, credentialsStore) { _fileSystem = fileSystem; _configPath = _fileSystem.Path.GetTempFileName(); // Add the environment variables to use to invoke kubectl safely. This environment is necessary // to ensure that the right credentials are used should the access token need to be refreshed. Environment[KubeConfigVariable] = _configPath; Environment[UseApplicationDefaultCredentialsVariable] = TrueValue; Environment[GoogleApplicationCredentialsVariable] = CredentialsPath; }
protected override void Load(ContainerBuilder builder) { // Task<IAuthenticator> builder.Register(async c => { var connectionManager = c.Resolve <IConnectionManager>(); ICredentialsStore credentialsStore = await c.Resolve <Task <ICredentialsStore> >(); var tokenCredentialsAuthenticator = new TokenCacheAuthenticator(new CloudTokenAuthenticator(connectionManager), credentialsStore, this.iothubHostName); return(new Authenticator(tokenCredentialsAuthenticator, this.deviceId, connectionManager) as IAuthenticator); }) .As <Task <IAuthenticator> >() .SingleInstance(); // IClientCredentialsFactory builder.Register(c => new ClientCredentialsFactory(this.iothubHostName, this.productInfo)) .As <IClientCredentialsFactory>() .SingleInstance(); base.Load(builder); }
public XamarinSettingsManager(IClientSettings clientSettings, ICredentialsStore credentialsStore) { _credentialsStore = credentialsStore; _clientSettings = clientSettings; }
/// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override async Task InitializeAsync(CancellationToken token, IProgress <ServiceProgressData> progress) { try { _componentModel = await GetServiceAsync <SComponentModel, IComponentModel>(); CredentialsStore = _componentModel.GetService <ICredentialsStore>(); ExportProvider mefExportProvider = _componentModel.DefaultExportProvider; _shellUtilsLazy = mefExportProvider.GetExport <IShellUtils>(); _gcpOutputWindowLazy = mefExportProvider.GetExport <IGcpOutputWindow>(); _processService = mefExportProvider.GetExport <IProcessService>(); _statusbarService = mefExportProvider.GetExport <IStatusbarService>(); _userPromptService = mefExportProvider.GetExport <IUserPromptService>(); _dataSourceFactory = mefExportProvider.GetExport <IDataSourceFactory>(); Dte = await GetServiceAsync <SDTE, DTE2>(); // Remember the package. Instance = this; // Activity log utils, to aid in debugging. IVsActivityLog activityLog = await GetServiceAsync <SVsActivityLog, IVsActivityLog>(); await activityLog.LogInfoAsync("Starting Google Cloud Tools."); // Register the command handlers. await Task.WhenAll( CloudExplorerCommand.InitializeAsync(this, token), ManageAccountsCommand.InitializeAsync(this, token), PublishProjectMainMenuCommand.InitializeAsync(this, token), PublishProjectContextMenuCommand.InitializeAsync(this, token), LogsViewerToolWindowCommand.InitializeAsync(this, token), GenerateConfigurationContextMenuCommand.InitializeAsync(this, token), ErrorReportingToolWindowCommand.InitializeAsync(this, token)); // Update the installation status of the package. await CheckInstallationStatusAsync(); // Ensure the commands UI state is updated when the GCP project changes. CredentialsStore.CurrentProjectIdChanged += (o, e) => ShellUtils.InvalidateCommandsState(); // With this setting we allow more concurrent connections from each HttpClient instance created // in the process. This will allow all GCP API services to have more concurrent connections with // GCP servers. The first benefit of this is that we can upload more concurrent files to GCS. ServicePointManager.DefaultConnectionLimit = MaximumConcurrentConnections; IVsRegisterUIFactories registerUIFactories = await GetServiceAsync <SVsUIFactory, IVsRegisterUIFactories>(); var controlFactory = _componentModel.GetService <GcpMenuBarControlFactory>(); await registerUIFactories.RegisterUIFactoryAsync(controlFactory, token); } catch (Exception e) { IVsActivityLog activityLog = await GetServiceAsync <SVsActivityLog, IVsActivityLog>(); await activityLog.LogErrorAsync(e.Message); await activityLog.LogErrorAsync(e.StackTrace); } }
static CredentialsCreator() { _credentialsCreator = TweetinviContainer.Resolve<ICredentialsCreator>(); _webTokenCreator = TweetinviContainer.Resolve<IWebTokenCreator>(); _credentialsStore = TweetinviContainer.Resolve<ICredentialsStore>(); }
public DataSourceFactory(ICredentialsStore credentialsStore) { CredentialsStore = credentialsStore; SetupLazyDataSources(); CredentialsStore.CurrentAccountChanged += (sender, args) => SetupLazyDataSources(); }
public PasswordSafe(ICredentialsStore <ICollection <CredentialGroup> > store) { _store = store; _currentData = new List <CredentialGroup>(); }
private string GetInstancePath(Instance instance) { ICredentialsStore credentials = CredentialsStore.Default; return($@"{ToValidPathName(credentials.CurrentProjectId)}\{ToValidPathName(instance.GetZoneName())}\{ToValidPathName(instance.Name)}"); }
public TokenCredentialsAuthenticator(IConnectionManager connectionManager, ICredentialsStore credentialsStore, string iotHubHostName) { this.connectionManager = Preconditions.CheckNotNull(connectionManager, nameof(connectionManager)); this.credentialsStore = Preconditions.CheckNotNull(credentialsStore, nameof(credentialsStore)); this.iotHubHostName = Preconditions.CheckNonWhiteSpace(iotHubHostName, nameof(iotHubHostName)); }
public TwitterClient(ICredentialsStore credentialsStore) { _credentialsStore = credentialsStore; }
static AuthFlow() { _authFactory = TweetinviContainer.Resolve<IAuthFactory>(); _webTokenFactory = TweetinviContainer.Resolve<IWebTokenFactory>(); _credentialsStore = TweetinviContainer.Resolve<ICredentialsStore>(); }
public TokenCacheAuthenticator(IAuthenticator cloudAuthenticator, ICredentialsStore credentialsStore, string iotHubHostName) { this.cloudAuthenticator = Preconditions.CheckNotNull(cloudAuthenticator, nameof(cloudAuthenticator)); this.credentialsStore = Preconditions.CheckNotNull(credentialsStore, nameof(credentialsStore)); this.iotHubHostName = Preconditions.CheckNonWhiteSpace(iotHubHostName, nameof(iotHubHostName)); }
static AuthFlow() { _authFactory = TweetinviContainer.Resolve <IAuthFactory>(); _webTokenFactory = TweetinviContainer.Resolve <IWebTokenFactory>(); _credentialsStore = TweetinviContainer.Resolve <ICredentialsStore>(); }
static CredentialsCreator() { _credentialsCreator = TweetinviContainer.Resolve <ICredentialsCreator>(); _webTokenCreator = TweetinviContainer.Resolve <IWebTokenCreator>(); _credentialsStore = TweetinviContainer.Resolve <ICredentialsStore>(); }
protected override void Load(ContainerBuilder builder) { // ISignatureProvider builder.Register( c => { ISignatureProvider signatureProvider = this.edgeHubConnectionString.Map( cs => { IotHubConnectionStringBuilder csBuilder = IotHubConnectionStringBuilder.Create(cs); return(new SharedAccessKeySignatureProvider(csBuilder.SharedAccessKey) as ISignatureProvider); }) .GetOrElse( () => { string edgeHubGenerationId = this.edgeHubGenerationId.Expect(() => new InvalidOperationException("Generation ID missing")); string workloadUri = this.workloadUri.Expect(() => new InvalidOperationException("workloadUri is missing")); return(new HttpHsmSignatureProvider(this.edgeHubModuleId, edgeHubGenerationId, workloadUri, Service.Constants.WorkloadApiVersion) as ISignatureProvider); }); return(signatureProvider); }) .As <ISignatureProvider>() .SingleInstance(); // Detect system environment builder.Register(c => new SystemEnvironment()) .As <ISystemEnvironment>() .SingleInstance(); // DataBase options builder.Register(c => new Storage.RocksDb.RocksDbOptionsProvider(c.Resolve <ISystemEnvironment>(), this.optimizeForPerformance)) .As <Storage.RocksDb.IRocksDbOptionsProvider>() .SingleInstance(); // IDbStoreProvider builder.Register( c => { var loggerFactory = c.Resolve <ILoggerFactory>(); ILogger logger = loggerFactory.CreateLogger(typeof(RoutingModule)); if (this.usePersistentStorage) { // Create partitions for messages and twins var partitionsList = new List <string> { Core.Constants.MessageStorePartitionKey, Core.Constants.TwinStorePartitionKey, Core.Constants.CheckpointStorePartitionKey }; try { IDbStoreProvider dbStoreprovider = Storage.RocksDb.DbStoreProvider.Create(c.Resolve <Storage.RocksDb.IRocksDbOptionsProvider>(), this.storagePath, partitionsList); logger.LogInformation($"Created persistent store at {this.storagePath}"); return(dbStoreprovider); } catch (Exception ex) when(!ExceptionEx.IsFatal(ex)) { logger.LogError(ex, "Error creating RocksDB store. Falling back to in-memory store."); return(new InMemoryDbStoreProvider()); } } else { logger.LogInformation($"Using in-memory store"); return(new InMemoryDbStoreProvider()); } }) .As <IDbStoreProvider>() .SingleInstance(); // Task<IEncryptionProvider> builder.Register( async c => { IEncryptionProvider encryptionProvider = await this.workloadUri.Map( async uri => await EncryptionProvider.CreateAsync( this.storagePath, new Uri(uri), Service.Constants.WorkloadApiVersion, this.edgeHubModuleId, this.edgeHubGenerationId.Expect(() => new InvalidOperationException("Missing generation ID")), Service.Constants.InitializationVectorFileName) as IEncryptionProvider) .GetOrElse(() => Task.FromResult <IEncryptionProvider>(NullEncryptionProvider.Instance)); return(encryptionProvider); }) .As <Task <IEncryptionProvider> >() .SingleInstance(); // IStoreProvider builder.Register(c => new StoreProvider(c.Resolve <IDbStoreProvider>())) .As <IStoreProvider>() .SingleInstance(); // ITokenProvider builder.Register(c => new ModuleTokenProvider(c.Resolve <ISignatureProvider>(), this.iothubHostName, this.edgeDeviceId, this.edgeHubModuleId, TimeSpan.FromHours(1))) .Named <ITokenProvider>("EdgeHubClientAuthTokenProvider") .SingleInstance(); // ITokenProvider builder.Register(c => { string deviceId = WebUtility.UrlEncode(this.edgeDeviceId); string moduleId = WebUtility.UrlEncode(this.edgeHubModuleId); return(new ModuleTokenProvider(c.Resolve <ISignatureProvider>(), this.iothubHostName, deviceId, moduleId, TimeSpan.FromHours(1))); }) .Named <ITokenProvider>("EdgeHubServiceAuthTokenProvider") .SingleInstance(); // Task<IKeyValueStore<string, string>> - EncryptedStore builder.Register( async c => { var storeProvider = c.Resolve <IStoreProvider>(); IEncryptionProvider encryptionProvider = await c.Resolve <Task <IEncryptionProvider> >(); IEntityStore <string, string> entityStore = storeProvider.GetEntityStore <string, string>("SecurityScopeCache"); IKeyValueStore <string, string> encryptedStore = new EncryptedStore <string, string>(entityStore, encryptionProvider); return(encryptedStore); }) .Named <Task <IKeyValueStore <string, string> > >("EncryptedStore") .SingleInstance(); // Task<IDeviceScopeIdentitiesCache> builder.Register( async c => { IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache; if (this.authenticationMode == AuthenticationMode.CloudAndScope || this.authenticationMode == AuthenticationMode.Scope) { var edgeHubTokenProvider = c.ResolveNamed <ITokenProvider>("EdgeHubServiceAuthTokenProvider"); IDeviceScopeApiClient securityScopesApiClient = new DeviceScopeApiClient(this.iothubHostName, this.edgeDeviceId, this.edgeHubModuleId, 10, edgeHubTokenProvider); IServiceProxy serviceProxy = new ServiceProxy(securityScopesApiClient); IKeyValueStore <string, string> encryptedStore = await c.ResolveNamed <Task <IKeyValueStore <string, string> > >("EncryptedStore"); deviceScopeIdentitiesCache = await DeviceScopeIdentitiesCache.Create(serviceProxy, encryptedStore, this.scopeCacheRefreshRate); } else { deviceScopeIdentitiesCache = new NullDeviceScopeIdentitiesCache(); } return(deviceScopeIdentitiesCache); }) .As <Task <IDeviceScopeIdentitiesCache> >() .SingleInstance(); // Task<IAuthenticator> builder.Register(async c => { IConnectionManager connectionManager = await c.Resolve <Task <IConnectionManager> >(); IAuthenticator tokenAuthenticator; IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache; switch (this.authenticationMode) { case AuthenticationMode.Cloud: if (this.cacheTokens) { ICredentialsStore credentialsStore = await c.Resolve <Task <ICredentialsStore> >(); IAuthenticator authenticator = new CloudTokenAuthenticator(connectionManager); tokenAuthenticator = new TokenCacheAuthenticator(authenticator, credentialsStore, this.iothubHostName); } else { tokenAuthenticator = new CloudTokenAuthenticator(connectionManager); } break; case AuthenticationMode.Scope: deviceScopeIdentitiesCache = await c.Resolve <Task <IDeviceScopeIdentitiesCache> >(); tokenAuthenticator = new DeviceScopeTokenAuthenticator(deviceScopeIdentitiesCache, this.iothubHostName, this.edgeDeviceHostName, new NullAuthenticator(), connectionManager); break; default: deviceScopeIdentitiesCache = await c.Resolve <Task <IDeviceScopeIdentitiesCache> >(); IAuthenticator cloudAuthenticator = new CloudTokenAuthenticator(connectionManager); tokenAuthenticator = new DeviceScopeTokenAuthenticator(deviceScopeIdentitiesCache, this.iothubHostName, this.edgeDeviceHostName, cloudAuthenticator, connectionManager); break; } return(new Authenticator(tokenAuthenticator, this.edgeDeviceId, connectionManager) as IAuthenticator); }) .As <Task <IAuthenticator> >() .SingleInstance(); // IClientCredentialsFactory builder.Register(c => new ClientCredentialsFactory(this.iothubHostName, this.productInfo)) .As <IClientCredentialsFactory>() .SingleInstance(); base.Load(builder); }