Exemple #1
0
        public async Task <List <ScanFinding> > GetScans(Application application)
        {
            Login();
            NameValuePairs nv = new NameValuePairs();

            nv.Add("query", WebUtility.UrlEncode(String.Format("Application Name={0}", application.name)));

            HttpResponseMessage response = await Get("issues", nv);

            string json = await response.Content.ReadAsStringAsync();

            Log.Debug(String.Format("Received JSON: {0}", json));

            Logout();
            return(JsonConvert.DeserializeObject <List <ScanFinding> >(json));
        }
Exemple #2
0
        public async Task <List <Application> > GetApplications()
        {
            Login();
            NameValuePairs nv = new NameValuePairs();

            nv.Add("columns", WebUtility.UrlEncode("name,url"));

            HttpResponseMessage response = await Get("applications", nv);

            string json = await response.Content.ReadAsStringAsync();

            Log.Debug(String.Format("Received JSON: {0}", json));

            Logout();
            return(JsonConvert.DeserializeObject <List <Application> >(json));
        }
Exemple #3
0
        /// <summary>
        /// Sends a GET request to the REST API at the requestUri given. If NameValuePairs is given, then this will
        /// appended to the query string for the call.
        /// </summary>
        /// <param name="requestUri">Request URI</param>
        /// <param name="nameValuePairs">Name Value Pairs (parameter names and values)</param>
        /// <returns></returns>
        async Task <HttpResponseMessage> Get(string requestUri, NameValuePairs nameValuePairs = null)
        {
            requestUri = aseRootPath + requestUri;
            if (nameValuePairs != null)
            {
                requestUri += nameValuePairs.ToQueryString(true);
            }

            Uri uri = new Uri(Client.BaseAddress, requestUri);

            Log.Debug(String.Format("Sending HTTP GET request to {0}.", uri));
            HttpResponseMessage response = await Client.GetAsync(uri);

            response.EnsureSuccessStatusCode();

            return(response);
        }
Exemple #4
0
        /// <summary>
        /// Logs in using ASE credentials provided in the constructor.
        /// </summary>
        /// <returns>Token for use in further calls to the API.</returns>
        void Login()
        {
            NameValuePairs nv = new NameValuePairs();

            nv.Add("userId", Username);
            nv.Add("password", StringUtils.GetUnsecureString(Password));
            nv.Add("featureKey", DEFAULT_FEATUREKEY);

            try
            {
                HttpResponseMessage          response = Post("login", nv.ToJson()).GetAwaiter().GetResult();
                Dictionary <string, dynamic> ret      = GenericJsonParse(response);
                Client.DefaultRequestHeaders.TryAddWithoutValidation(TOKEN_NAME, ret["sessionId"]);

                Log.Debug(String.Format("Successfully logged into ASE as {1}: {0}", ret["sessionId"], Username));
            }catch (Exception e)
            {
                Log.Error(String.Format("Failed to login to ASE as {0}: {1}", Username, e.Message), e);
                throw e;
            }finally
            {
                nv = null; //clean up values from memory.
            }
        }
Exemple #5
0
        /// <summary>
        /// Sends a HTTP PUT request to the server at the requestUri given. This will append the given
        /// name value pairs into the body of the request as JSON.
        /// </summary>
        /// <param name="requestUri">Request URI</param>
        /// <param name="nameValuePairs">Name value pairs which will be sent in the body of the request as JSON.</param>
        /// <returns>Response from the server if the status code is 200</returns>
        async Task <HttpResponseMessage> Put(string requestUri, NameValuePairs nameValuePairs)
        {
            StringContent content = new StringContent(nameValuePairs.ToJson(), Encoding.UTF8, "application/json");

            return(await Put(requestUri, content));
        }