private OpenStackAuthResponse GetOpenstackAuthResponse()
        {
            var helper = new JSONWebHelper();

            var req = helper.CreateRequest(JoinUrls(m_authUri, "tokens"));

            req.Accept = "application/json";
            req.Method = "POST";

            var resp = helper.ReadJSONResponse <OpenStackAuthResponse>(
                req,
                new OpenStackAuthRequest(m_tenantName, m_username, m_password, m_apikey)
                );

            m_accessToken = resp.access.token;

            // Grab the endpoint now that we have received it anyway
            var fileservice = resp.access.serviceCatalog.FirstOrDefault(x => string.Equals(x.type, "object-store", StringComparison.OrdinalIgnoreCase));

            if (fileservice == null)
            {
                throw new Exception("No object-store service found, is this service supported by the provider?");
            }

            var endpoint = fileservice.endpoints.FirstOrDefault(x => string.Equals(m_region, x.region)) ?? fileservice.endpoints.First();

            m_simplestorageendpoint = endpoint.publicURL;

            return(resp);
        }
        private Keystone3AuthResponse GetKeystone3AuthResponse()
        {
            var helper = new JSONWebHelper();

            var req = helper.CreateRequest(JoinUrls(m_authUri, "auth/tokens"));

            req.Accept = "application/json";
            req.Method = "POST";

            var data = Encoding.UTF8.GetBytes(
                JsonConvert.SerializeObject(
                    new Keystone3AuthRequest(m_domainName, m_username, m_password, m_tenantName)
                    ));

            req.ContentLength = data.Length;
            req.ContentType   = "application/json; charset=UTF-8";

            using (var rs = req.GetRequestStream())
                rs.Write(data, 0, data.Length);

            WebResponse http_response = req.GetResponse();

            Keystone3AuthResponse resp;

            using (var reader = new StreamReader(http_response.GetResponseStream()))
            {
                resp = Newtonsoft.Json.JsonConvert.DeserializeObject <Keystone3AuthResponse>(
                    reader.ReadToEnd());
            }

            string token = http_response.Headers["X-Subject-Token"];

            this.m_accessToken         = new OpenStackAuthResponse.TokenClass();
            this.m_accessToken.id      = token;
            this.m_accessToken.expires = resp.token.expires_at;

            // Grab the endpoint now that we have received it anyway
            var fileservice = resp.token.catalog.FirstOrDefault(x => string.Equals(x.type, "object-store", StringComparison.OrdinalIgnoreCase));

            if (fileservice == null)
            {
                throw new Exception("No object-store service found, is this service supported by the provider?");
            }

            var endpoint = fileservice.endpoints.FirstOrDefault(x => (string.Equals(m_region, x.region) && string.Equals(x.interface_name, "public", StringComparison.OrdinalIgnoreCase))) ?? fileservice.endpoints.First();

            m_simplestorageendpoint = endpoint.url;

            return(resp);
        }
Beispiel #3
0
        private OpenStackAuthResponse GetAuthResponse()
        {
            var helper = new JSONWebHelper();

            var req = helper.CreateRequest(JoinUrls(m_authUri, "tokens"));
            req.Accept = "application/json";
            req.Method = "POST";

            var resp = helper.ReadJSONResponse<OpenStackAuthResponse>(
                req,
                new OpenStackAuthRequest(m_tenantName, m_username, m_password, m_apikey)
            );

            m_accessToken = resp.access.token;

            // Grab the endpoint now that we have received it anyway
            var fileservice = resp.access.serviceCatalog.Where(x => string.Equals(x.type, "object-store", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
            if (fileservice == null)
                throw new Exception("No object-store service found, is this service supported by the provider?");

            var endpoint = fileservice.endpoints.Where(x => string.Equals(m_region, x.region)).FirstOrDefault() ?? fileservice.endpoints.First();

            m_simplestorageendpoint = endpoint.publicURL;

            return resp;
        }