Example #1
0
        protected override void ProcessRecord()
        {
            string endPoint = "/authenticate_user";

            var baseUri = new Uri(Connection.ChefUrl);

            var requestUri = new Uri(baseUri, endPoint);

            Dictionary<string, string> user = new Dictionary<string, string>();

            user.Add("username", _userName);
            user.Add("password", _password);

            string body = JsonConvert.SerializeObject(user, Formatting.Indented);

            var authenticatedRequest = new AuthenticatedRequest(Connection.UserName, requestUri, HttpMethod.Post, body, String.Empty);

            authenticatedRequest.Sign(Connection.PrivateKey);

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(Connection.ChefUrl);

                var chefRequest = authenticatedRequest.Create();

                var result = client.SendAsync(chefRequest).Result;

                WriteObject(result.StatusCode);
            }
        }
        public string SendRequest(AuthenticatedRequest request)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = server;

                var message = request.Create();
                var result  = client.SendAsync(message).Result;

                result.EnsureSuccessStatusCode();

                return(result.Content.ReadAsStringAsync().Result);
            }
        }
Example #3
0
        public async Task <HttpResponseMessage> SendRequestAsync(AuthenticatedRequest request)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = server;

                var message = request.Create();
                var result  = await client.SendAsync(message);

                result.EnsureSuccessStatusCode();

                return(result);
            }
        }
Example #4
0
        public string SendRequest(AuthenticatedRequest request)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = server;
                
                var message = request.Create();
                var result = client.SendAsync(message).Result;
                
                result.EnsureSuccessStatusCode();

                return result.Content.ReadAsStringAsync().Result;
            }
        }
Example #5
0
        public static string MakeRequest(string chefServer,string endPoint,string privateKey,string userId,HttpMethod method,string body, string parameter)
        {
            var baseUri = new Uri(chefServer);

            var requestUri = new Uri(baseUri, endPoint);

            var authenticatedRequest = new AuthenticatedRequest(userId, requestUri,method,body, parameter);

            authenticatedRequest.Sign(privateKey);

            var server = new ChefServer(baseUri);
            string resultContent = server.SendRequest(authenticatedRequest);

            return resultContent;
        }
Example #6
0
        public string SendRequest(AuthenticatedRequest request)
        {
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            using (var client = new HttpClient())
            {
                client.BaseAddress = server;

                var message = request.Create();
                var result = client.SendAsync(message).Result;

                result.EnsureSuccessStatusCode();

                return result.Content.ReadAsStringAsync().Result;
            }
        }
Example #7
0
 public HttpResponseMessage SendRequest(AuthenticatedRequest request)
 {
     return(SendRequestAsync(request).Result);
 }