public static ICollector Create(ICredential credential) { if (credential.GetType() == typeof(MyCredential)) { return(new MyCollector((MyCredential)credential)); } if (credential.GetType() == typeof(OtherCredential)) { return(new OtherCollector((OtherCredential )credential)); } }
/// <inheritdoc/> public IOpenStackClient CreateClient(ICredential credential, CancellationToken token, string version) { credential.AssertIsNotNull("credential", "Cannot create an OpenStack client with a null credential."); version.AssertIsNotNull("version", "Cannot create an OpenStack client with a null version."); //Ensure that the assembly that contains the credential has a chance to register itself. this.ServiceLocator.EnsureAssemblyRegistration(credential.GetType().GetAssembly()); return(this.GetSupportedClient(this.clients, credential, token, version)); }
/// <inheritdoc/> public IOpenStackClient CreateClient <T>(ICredential credential, CancellationToken token, string version) where T : IOpenStackClient { credential.AssertIsNotNull("credential", "Cannot create an OpenStack client with a null credential."); version.AssertIsNotNull("version", "Cannot create an OpenStack client with a null version."); //Ensure that the assemblies that contain the credential and client type has had a chance to register itself. this.ServiceLocator.EnsureAssemblyRegistration(credential.GetType().GetAssembly()); this.ServiceLocator.EnsureAssemblyRegistration(typeof(T).GetAssembly()); return(this.GetSupportedClient(this.clients.Where(c => c == typeof(T)), credential, token, version)); }
/// <inheritdoc/> public T CreateServiceClient <T>(ICredential credential, string serviceName, CancellationToken cancellationToken) where T : IOpenStackServiceClient { credential.AssertIsNotNull("credential", "Cannot create an OpenStack service with a null credential."); cancellationToken.AssertIsNotNull("cancellationToken", "Cannot create an OpenStack service with a null cancellationToken."); credential.ServiceCatalog.AssertIsNotNull("credential.ServiceCatalog", "Cannot create an OpenStack service with a null service catalog."); //Ensure that the assembly that contains this credential has had a chance to be service located. //This is, at least for now, the entry point for third-parties can extend the API/SDK. this.ServiceLocator.EnsureAssemblyRegistration(credential.GetType().GetAssembly()); this.ServiceLocator.EnsureAssemblyRegistration(typeof(T).GetAssembly()); foreach (var serviceClientDef in this.serviceClientDefinitions.Where(s => typeof(T).IsAssignableFrom(s.Key))) { if (serviceClientDef.Value != null && serviceClientDef.Value.IsSupported(credential, serviceName)) { var client = this.CreateServiceClientInstance(serviceClientDef.Value, credential, serviceName, cancellationToken); return((T)client); } } throw new InvalidOperationException("A client that supports the requested service for the given instance of OpenStack could not be found."); }
public async Task <GetAccessTokenResult> GetAccessTokenAsync(ICredential credential) { if (credential == null) { throw new ArgumentNullException(nameof(credential)); } if (configuration == null) { await EnsureDirectoryIsSetAsync(); } switch (credential) { case JwtCredential jwk: return(await GetFromJwtAsync(jwk)); case AccessKey accessKey: return(await GetFromAccessKeyAsync(accessKey)); case RefreshToken refreshToken: return(await GetFromRefreshTokenAsync(refreshToken)); } throw new Exception("Invalid credential. Was " + credential.GetType().ToString()); }