Пример #1
0
        public async Task <string> Login(string userName, string password)
        {
            BasicAuthToken = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(userName + ":" + password));
            AuthToken      = await HttpClientHandler.Send <string>(HttpMethod.Post, SmaxHcmOptions.CircuitBreakerName, string.Format(SmaxHcmEndpointConst.Logon, SmaxHcmOptions.TenantId), new LoginRequestDto { Login = userName, Password = password }, MediaType.ApplicationJson);

            return(AuthToken);
        }
Пример #2
0
        /// <summary>
        /// Performs the generic API Get call to Ansible Tower
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="authenticationToken"></param>
        /// <param name="endpoint"></param>
        /// <param name="searchCriteria"></param>
        /// <returns></returns>
        private async Task <T> GetAnsible <T>(string authenticationToken, string endpoint, string searchCriteria = null)
        {
            await SetAutehnticationTokenAsync(authenticationToken);

            var searchCriteriaUri = (searchCriteria != null ? "?search=" + searchCriteria : string.Empty);

            return(await HttpClientHandler.Send <T>(HttpMethod.Get, AnsibleTowerInstance.CircuitBreakerName, endpoint + searchCriteriaUri, null, MediaType.ApplicationJson, GetAuthorizationHeaders()));
        }
Пример #3
0
        private static void WebSocketData(HttpClientHandler client, WebSocketFrame data)
        {
            Console.WriteLine(System.Text.Encoding.UTF8.GetString(data.Payload));

            WebSocketFrame response = new WebSocketFrame("This is a WebSocket server response!");

            client.Send(response);
        }
Пример #4
0
        public async Task <LoginRequestDto> Login(string userName, string password)
        {
            var result = await HttpClientHandler.Send <LoginRequestDto>(HttpMethod.Post, AnsibleTowerInstance.CircuitBreakerName, AnsibleTowerInstance.ApiDefinition.tokens, null, MediaType.ApplicationJson, GetLoginHeaders(userName, password)).ConfigureAwait(false);

            //var result = await CircuitBreakerHttpClient.Post<LoginRequestDto>(AnsibleTowerInstance.CircuitBreakerName, AnsibleTowerInstance.ApiDefinition.tokens, null, MediaType.ApplicationJson, GetLoginHeaders(userName, password), true).ConfigureAwait(false);
            AuthToken = result.token;

            return(result);
        }
        private static IAnsibleTowerInstance GetAnsibleTowerInstances()
        {
            if (AnsibleTowerOptions == null || !AnsibleTowerOptions.EnableAnsible || string.IsNullOrEmpty(AnsibleTowerOptions.ApiUrlBase))
            {
                return(null);
            }
            var apiRequestDto = HttpClientHandler.Send <ApiRequestDto>(HttpMethod.Get, AnsibleTowerOptions.CircuitBreakerName, AnsibleTowerOptions.ApiUrlBase, null, MediaType.ApplicationJson).Result;

            return(new AnsibleTowerInstance(AnsibleTowerOptions.Name, AnsibleTowerOptions.CircuitBreakerName, AnsibleTowerOptions.ApiUrlBase, AnsibleTowerOptions.Version, apiRequestDto, AnsibleTowerOptions.Username, AnsibleTowerOptions.Password));
        }
Пример #6
0
        private async Task <HttpResponseMessage> SendSmaxHcm(HttpMethod httpMethod, string endpoint, object content = null, bool getUrlWithTenant = false, bool addBasicAuth = false, bool addAcceptJsonHeader = false, bool useCamelCase = false)
        {
            await PerformLogin();

            return(await HttpClientHandler.Send(httpMethod, SmaxHcmOptions.CircuitBreakerName, getUrlWithTenant?GetUrlWithTenant(endpoint) : endpoint, content, MediaType.ApplicationJson, false, false, GetAuthorizationHeaders(addBasicAuth, addAcceptJsonHeader)));
        }
Пример #7
0
        /// <summary>
        /// Performs the generic API Delete call to Ansible Tower
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="authenticationToken"></param>
        /// <param name="endpoint"></param>
        /// <param name="dataToSend"></param>
        /// <returns></returns>
        private async Task <T> DeleteAnsible <T>(string authenticationToken, string endpoint, bool useCamelCase = true)
        {
            await SetAutehnticationTokenAsync(authenticationToken);

            return(await HttpClientHandler.Send <T>(HttpMethod.Delete, AnsibleTowerInstance.CircuitBreakerName, endpoint, null, MediaType.ApplicationJson, GetAuthorizationHeaders(), true, useCamelCase));
        }
Пример #8
0
        /// <summary>
        /// Performs the generic API Post call to Ansible Tower
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="authenticationToken"></param>
        /// <param name="endpoint"></param>
        /// <param name="dataToSend"></param>
        /// <returns></returns>
        private async Task <T> PostAnsible <T>(string authenticationToken, string endpoint, object dataToSend)
        {
            await SetAutehnticationTokenAsync(authenticationToken);

            return(await HttpClientHandler.Send <T>(HttpMethod.Post, AnsibleTowerInstance.CircuitBreakerName, endpoint, dataToSend, MediaType.ApplicationJson, GetAuthorizationHeaders()));
        }
Пример #9
0
 /// <summary>
 /// Performs the ping command in Ansible Tower
 /// </summary>
 /// <returns></returns>
 public Task <PingResponseDto> Ping()
 {
     return(HttpClientHandler.Send <PingResponseDto>(HttpMethod.Get, AnsibleTowerInstance.CircuitBreakerName, AnsibleTowerInstance.ApiDefinition.ping, null, MediaType.ApplicationJson));
 }
Пример #10
0
        private static void ClientRequest(HttpClientHandler client, HttpRequest req)
        {
            HttpResponse resp = null;

            //Console.WriteLine("--- REQUEST ---");
            //Console.WriteLine(req.ToString());
            if (req["Request"] == "GET")
            {
                string uri = req["URI"];
                if (uri == "/")
                {
                    resp = new HttpResponse("HTTP/1.1", "200", "OK");
                    resp.AddProperty("Date", DateTime.Now.ToShortDateString());
                    resp.AddProperty("Server", "WunderVision");
                    resp.AddProperty("Content-Type", "text/html;charset=UTF-8");
                    resp.SetData(Site);
                }
                else
                {
                    if (req.ContainsKey("Sec-WebSocket-Key"))
                    {
                        resp = new HttpResponse("HTTP/1.1", "101", "Switching Protocols");
                        resp.AddProperty("Upgrade", "websocket");
                        resp.AddProperty("Connection", "Upgrade");
                        //Console.WriteLine(req["Sec-WebSocket-Key"]);
                        resp.AddProperty("Sec-WebSocket-Accept", HttpTools.ComputeWebSocketKeyHash(req["Sec-WebSocket-Key"]));
                        client.UpgradeToWebsocket();
                    }
                    else
                    {
                        Uri requestedfile = new Uri(Root + uri);
                        //Console.WriteLine(requestedfile.LocalPath);
                        if (File.Exists(requestedfile.LocalPath))
                        {
                            string mime = HttpTools.GetFileMimeType(uri);
                            //Console.WriteLine(mime);
                            byte[] data;
                            if (HttpTools.IsFileBinary(uri))
                            {
                                data = File.ReadAllBytes(requestedfile.LocalPath);
                            }
                            else
                            {
                                data = System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(requestedfile.LocalPath));
                            }
                            resp = new HttpResponse("HTTP/1.1", "200", "OK");
                            resp.AddProperty("Date", DateTime.Now.ToShortDateString());
                            resp.AddProperty("Server", "WunderVision");
                            resp.AddProperty("Content-Type", mime);
                            resp.SetData(data);
                        }
                    }
                }
            }
            if (resp == null)
            {
                resp = new HttpResponse("HTTP/1.1", "404", "NOT FOUND");
                resp.AddProperty("Date", DateTime.Now.ToShortDateString());
                resp.AddProperty("Server", "WunderVision");
                resp.AddProperty("Content-Type", "text/html;charset=UTF-8");
                resp.SetData("SORRY CAN'T DO WHAT YOU WANT ME TO");
            }
            //Console.WriteLine("--- RESPONSE ---");
            //Console.WriteLine(resp.ToString());
            client.Send(resp);
        }