/// <summary>
 /// Creates a new instance of the ServiceClientContext class.
 /// </summary>
 /// <param name="credential">The credential for this context.</param>
 /// <param name="cancellationToken">The cancellation token for this context.</param>
 /// <param name="serviceName">The name of the storage service.</param>
 /// <param name="publicEndpoint">The Uri for the public endpoint of the storage service.</param>
 internal ServiceClientContext(IOpenStackCredential credential, CancellationToken cancellationToken, string serviceName, Uri publicEndpoint)
 {
     this.Credential = credential;
     this.CancellationToken = cancellationToken;
     this.ServiceName = serviceName;
     this.PublicEndpoint = publicEndpoint;
 }
 /// <summary>
 /// Creates a new instance of the ServiceClientContext class.
 /// </summary>
 /// <param name="credential">The credential for this context.</param>
 /// <param name="cancellationToken">The cancellation token for this context.</param>
 /// <param name="serviceName">The name of the storage service.</param>
 /// <param name="publicEndpoint">The Uri for the public endpoint of the storage service.</param>
 internal ServiceClientContext(IOpenStackCredential credential, CancellationToken cancellationToken, string serviceName, Uri publicEndpoint)
 {
     this.Credential        = credential;
     this.CancellationToken = cancellationToken;
     this.ServiceName       = serviceName;
     this.PublicEndpoint    = publicEndpoint;
 }
        /// <summary>
        ///  Creates a new instance of the OpenStackClient class.
        /// </summary>
        /// <param name="credential">The credential to be used by this client.</param>
        /// <param name="cancellationToken">The cancellation token to be used by this client.</param>
        /// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
        public OpenStackClient(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
        {
            serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an OpenStack client with a null service locator.");

            this.Credential        = credential;
            this.CancellationToken = cancellationToken;
            this.ServiceLocator    = serviceLocator;
        }
        /// <summary>
        /// Creates a new instance of the NetworkServiceClient class.
        /// </summary>
        /// <param name="credentials">The credential to be used by this client.</param>
        /// <param name="token">The cancellation token to be used by this client.</param>
        /// <param name="serviceName">The name of the service to be used by this client.</param>
        /// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
        public NetworkServiceClient(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator)
        {
            serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a network service client with a null service locator.");

            this.ServiceLocator = serviceLocator;
            var endpoint = new Uri(credentials.ServiceCatalog.GetPublicEndpoint(serviceName, credentials.Region));
            this.Context = new ServiceClientContext(credentials, token, serviceName, endpoint);
        }
        /// <inheritdoc/>
        public async Task <IOpenStackCredential> Authenticate()
        {
            var client = this.ServiceLocator.Locate <IIdentityServicePocoClientFactory>().Create(this.Credential, this.ServiceName, this.CancellationToken, this.ServiceLocator);

            this.Credential = await client.Authenticate();

            return(this.Credential);
        }
 /// <summary>
 /// Creates a new instance of the IdentityServiceClient class.
 /// </summary>
 /// <param name="credential">The credential to be used by the client.</param>
 /// <param name="serviceName">The name of the service to be used by the client.</param>
 /// <param name="cancellationToken">A cancellation token to be used when completing requests.</param>
 /// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
 internal IdentityServiceClient(IOpenStackCredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator)
 {
     serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an identity service client with a null service locator.");
     
     this.ServiceLocator = serviceLocator;
     this.Credential = credential;
     this.CancellationToken = cancellationToken;
     this.ServiceName = serviceName;
 }
Пример #7
0
        /// <summary>
        /// Creates a new instance of the ComputeServiceClient class.
        /// </summary>
        /// <param name="credentials">The credential to be used by this client.</param>
        /// <param name="token">The cancellation token to be used by this client.</param>
        /// <param name="serviceName">The name of the service to be used by this client.</param>
        /// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
        public ComputeServiceClient(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator)
        {
            serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a storage service client with a null service locator.");

            this.ServiceLocator = serviceLocator;
            var endpoint = new Uri(credentials.ServiceCatalog.GetPublicEndpoint(serviceName, credentials.Region));

            this.Context = new ServiceClientContext(credentials, token, serviceName, endpoint);
        }
        /// <summary>
        /// Creates a new instance of the IdentityServiceClient class.
        /// </summary>
        /// <param name="credential">The credential to be used by the client.</param>
        /// <param name="serviceName">The name of the service to be used by the client.</param>
        /// <param name="cancellationToken">A cancellation token to be used when completing requests.</param>
        /// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
        internal IdentityServiceClient(IOpenStackCredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator)
        {
            serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an identity service client with a null service locator.");

            this.ServiceLocator    = serviceLocator;
            this.Credential        = credential;
            this.CancellationToken = cancellationToken;
            this.ServiceName       = serviceName;
        }
        /// <summary>
        /// Creates a client of the requested type that supports the given credential and version.
        /// </summary>
        /// <typeparam name="T">The type of client to create.</typeparam>
        /// <param name="credential">A credential to be used by the client.</param>
        /// <param name="version">A version that the client must support.</param>
        /// <param name="token">A cancellation token to be used to cancel operations.</param>
        /// <returns>An OpenStack client.</returns>
        public static IOpenStackClient CreateClient <T>(IOpenStackCredential credential, CancellationToken token, string version) where T : IOpenStackClient
        {
            credential.AssertIsNotNull("credential", "Cannot create a client with a null credential.");

            var locator       = new ServiceLocator();
            var clientManager = locator.Locate <IOpenStackClientManager>();

            return(clientManager.CreateClient <T>(credential, token, version));
        }
        /// <summary>
        /// Creates a new instance of the IdentityServiceRestClient class.
        /// </summary>
        /// <param name="credential">The credential to be used by this client.</param>
        /// <param name="cancellationToken">The cancellation token to be used by this client.</param>
        /// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
        public IdentityServiceRestClient(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
        {
            credential.AssertIsNotNull("credential");
            cancellationToken.AssertIsNotNull("cancellationToken");
            serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an identity service rest client with a null service locator.");

            this.Credential = credential;
            this.CancellationToken = cancellationToken;
            this.ServiceLocator = serviceLocator;
        }
        /// <summary>
        /// Creates a new instance of the StorageServiceClient class.
        /// </summary>
        /// <param name="credentials">The credential to be used by this client.</param>
        /// <param name="token">The cancellation token to be used by this client.</param>
        /// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
        public StorageServiceClient(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator)
        {
            serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a storage service client with a null service locator.");

            this.LargeObjectThreshold = 524288000; //Set the default large file threshold to 500MB.
            this.LargeObjectSegments = 10; //set the default number of segments for large objects to 10.
            this.LargeObjectSegmentContainer = "LargeObjectSegments"; //set the default name of the container that will hold segments to 'LargeObjectSegments';

            this.ServiceLocator = serviceLocator;
            var endpoint = new Uri(credentials.ServiceCatalog.GetPublicEndpoint(serviceName, credentials.Region));
            this.Context = new ServiceClientContext(credentials, token, serviceName, endpoint);
        }
        /// <summary>
        /// Creates a new instance of the IdentityServicePocoClient class.
        /// </summary>
        /// <param name="credential">The credential to be used when interacting with OpenStack.</param>
        /// <param name="cancellationToken">The cancellation token to be used when interacting with OpenStack.</param>
        /// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
        public IdentityServicePocoClient(IOpenStackCredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator)
        {
            credential.AssertIsNotNull("credential");
            cancellationToken.AssertIsNotNull("cancellationToken");
            serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an identity service poco client with a null service locator.");
            serviceName.AssertIsNotNullOrEmpty("serviceName", "Cannot create an identity service poco client with a null or empty service name.");

            this.credential        = credential;
            this.cancellationToken = cancellationToken;
            this.ServiceLocator    = serviceLocator;
            this.ServiceName       = serviceName;
        }
 /// <summary>
 /// Creates a Json payload that will be sent to the remote instance to authenticate.
 /// </summary>
 /// <param name="creds">The credentials used to authenticate.</param>
 /// <returns>A string that represents a Json payload.</returns>
 internal static string CreateAuthenticationJsonPayload(IOpenStackCredential creds)
 {
     var authPayload = new StringBuilder();
     authPayload.Append("{\"auth\":{\"passwordCredentials\":{\"username\":\"");
     authPayload.Append(creds.UserName);
     authPayload.Append("\",\"password\":\"");
     authPayload.Append(creds.Password);
     authPayload.Append("\"},\"tenantName\":\"");
     authPayload.Append(creds.TenantId);
     authPayload.Append("\"}}");
     return authPayload.ToString();
 }
        /// <summary>
        /// Creates a new instance of the IdentityServicePocoClient class.
        /// </summary>
        /// <param name="credential">The credential to be used when interacting with OpenStack.</param>
        /// <param name="cancellationToken">The cancellation token to be used when interacting with OpenStack.</param>
        /// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
        public IdentityServicePocoClient(IOpenStackCredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator)
        {
            credential.AssertIsNotNull("credential");
            cancellationToken.AssertIsNotNull("cancellationToken");
            serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an identity service poco client with a null service locator.");
            serviceName.AssertIsNotNullOrEmpty("serviceName", "Cannot create an identity service poco client with a null or empty service name.");

            this.credential = credential;
            this.cancellationToken = cancellationToken;
            this.ServiceLocator = serviceLocator;
            this.ServiceName = serviceName;
        }
        /// <summary>
        /// Creates a new instance of the StorageServiceClient class.
        /// </summary>
        /// <param name="credentials">The credential to be used by this client.</param>
        /// <param name="token">The cancellation token to be used by this client.</param>
        /// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
        public StorageServiceClient(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator)
        {
            serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a storage service client with a null service locator.");

            this.LargeObjectThreshold        = 524288000;             //Set the default large file threshold to 500MB.
            this.LargeObjectSegments         = 10;                    //set the default number of segments for large objects to 10.
            this.LargeObjectSegmentContainer = "LargeObjectSegments"; //set the default name of the container that will hold segments to 'LargeObjectSegments';

            this.ServiceLocator = serviceLocator;
            var endpoint = new Uri(credentials.ServiceCatalog.GetPublicEndpoint(serviceName, credentials.Region));

            this.Context = new ServiceClientContext(credentials, token, serviceName, endpoint);
        }
Пример #16
0
 /// <inheritdoc/>
 public IIdentityServicePocoClient Create(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator)
 {
     return(new IdentityServicePocoClient(credentials, serviceName, token, serviceLocator));
 }
 public IIdentityServiceRestClient Create(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
 {
     return(Client);
 }
 /// <inheritdoc/>
 public IIdentityServiceRestClient Create(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
 {
     return new IdentityServiceRestClient(credential, cancellationToken, serviceLocator);
 }
 /// <inheritdoc/>
 public IIdentityServicePocoClient Create(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator)
 {
     return new IdentityServicePocoClient(credentials, serviceName, token, serviceLocator);
 }
 /// <summary>
 /// Creates a client of the requested type that supports the given credential.
 /// </summary>
 /// <typeparam name="T">The type of client to create.</typeparam>
 /// <param name="credential">A credential to be used by the client.</param>
 /// <param name="version">A version that the client must support.</param>
 /// <returns>An OpenStack client.</returns>
 public static IOpenStackClient CreateClient <T>(IOpenStackCredential credential, string version) where T : IOpenStackClient
 {
     return(CreateClient <T>(credential, CancellationToken.None, version));
 }
 /// <summary>
 /// Creates an OpenStack client that supports the given credential.
 /// </summary>
 /// <param name="credential">A credential to be used by the client.</param>
 /// <returns>A OpenStack client.</returns>
 public static IOpenStackClient CreateClient(IOpenStackCredential credential)
 {
     return(CreateClient(credential, CancellationToken.None, string.Empty));
 }
 /// <inheritdoc/>
 public async Task<IOpenStackCredential> Authenticate()
 {
     var client = this.ServiceLocator.Locate<IIdentityServicePocoClientFactory>().Create(this.Credential, this.ServiceName, this.CancellationToken, this.ServiceLocator);
     this.Credential = await client.Authenticate();
     return this.Credential;
 }
        /// <inheritdoc/>
        public async Task Connect()
        {
            var identityClient = this.CreateServiceClient <IIdentityServiceClient>();

            this.Credential = await identityClient.Authenticate();
        }
 public TestIdentityServiceClient(IOpenStackCredential cred, CancellationToken token)
 {
     this.cred  = cred;
     this.token = token;
 }