Example #1
0
 /// <summary>
 /// Adds the cryptography interceptor.
 /// </summary>
 /// <param name="cryptographyInterceptor">Cryptography interceptor.</param>
 public static void AddCryptographyInterceptor(CryptographyInterceptor cryptographyInterceptor)
 {
     if (!cryptographyMap.Contains(cryptographyInterceptor))
     {
         cryptographyMap.Add(cryptographyInterceptor);
     }
 }
Example #2
0
 /// <summary>
 /// Adds the cryptography interceptor.
 /// </summary>
 /// <param name="cryptographyInterceptor">Cryptography interceptor.</param>
 public static void AddCryptographyInterceptor(CryptographyInterceptor cryptographyInterceptor)
 {
     if (!cryptographyMap.ContainsKey(cryptographyInterceptor.GetTriggeringPath()))
     {
         cryptographyMap.Add(cryptographyInterceptor.GetTriggeringPath(), cryptographyInterceptor);
     }
 }
Example #3
0
        private RestyRequest GetRequest(OperationConfig config, OperationMetadata metadata, RequestMap requestMap)
        {
            RestyRequest restyRequest = null;
            IDictionary <string, object> dictionary  = requestMap.Clone();
            IDictionary <string, object> dictionary2 = Util.SubMap(dictionary, config.HeaderParams);
            Uri uRL     = this.GetURL(config, metadata, dictionary);
            Uri baseUrl = new Uri(string.Concat(new object[]
            {
                uRL.Scheme,
                "://",
                uRL.Host,
                ":",
                uRL.Port
            }));
            CryptographyInterceptor cryptographyInterceptor = _apiConfig?.GetCryptographyInterceptor(uRL.AbsolutePath) ?? ApiConfig.GetCryptographyInterceptor(uRL.AbsolutePath);
            string action = config.Action;

            if (!(action == "create"))
            {
                if (!(action == "delete"))
                {
                    if (!(action == "update"))
                    {
                        if (action == "read" || action == "list" || action == "query")
                        {
                            restyRequest = new RestyRequest(uRL, Method.GET);
                        }
                    }
                    else
                    {
                        restyRequest = new RestyRequest(uRL, Method.PUT);
                        if (cryptographyInterceptor != null)
                        {
                            dictionary = cryptographyInterceptor.Encrypt(dictionary);
                        }
                        if (config.RequestType == DataType.Json)
                        {
                            restyRequest.AddJsonBody(dictionary);
                        }
                        else if (config.RequestType == DataType.Xml)
                        {
                            restyRequest.AddXmlBody(dictionary);
                        }
                    }
                }
                else
                {
                    restyRequest = new RestyRequest(uRL, Method.DELETE);
                }
            }
            else
            {
                restyRequest = new RestyRequest(uRL, Method.POST);
                if (cryptographyInterceptor != null)
                {
                    dictionary = cryptographyInterceptor.Encrypt(dictionary);
                }
                if (config.RequestType == DataType.Json)
                {
                    restyRequest.AddJsonBody(dictionary);
                }
                else if (config.RequestType == DataType.Xml)
                {
                    restyRequest.AddXmlBody(dictionary);
                }
            }
            if (config.RepsonseType == DataType.Json)
            {
                restyRequest.AddHeader("Accept", "application/json");
            }
            else if (config.RepsonseType == DataType.Xml)
            {
                restyRequest.AddHeader("Accept", "application/xml");
            }
            if (config.RequestType == DataType.Json)
            {
                restyRequest.AddHeader("Content-Type", "application/json");
            }
            else if (config.RequestType == DataType.Xml)
            {
                restyRequest.AddHeader("Content-Type", "application/xml");
            }

            restyRequest.AddHeader("User-Agent", "CSharp-SDK-Unofficial/" + this.apiVersion);
            foreach (KeyValuePair <string, object> current in dictionary2)
            {
                restyRequest.AddHeader(current.Key, current.Value.ToString());
            }
            (_apiConfig?.GetAuthentication() ?? ApiConfig.GetAuthentication()).SignRequest(uRL, restyRequest);
            restyRequest.AbsoluteUrl = uRL;
            restyRequest.BaseUrl     = baseUrl;
            restyRequest.interceptor = cryptographyInterceptor;
            return(restyRequest);
        }
Example #4
0
        /// <summary>
        /// Gets the request.
        /// </summary>
        /// <returns>The request.</returns>
        /// <param name="uri">URI.</param>
        /// <param name="action">Action.</param>
        /// <param name="objectMap">Object map.</param>
        RestRequest getRequest(Uri uri, String action, IDictionary <String, Object> inputMap, IDictionary <String, Object> headerMap, CryptographyInterceptor interceptor = null)
        {
            RestRequest request = null;



            switch (action)
            {
            case "create":
                request = new RestRequest(uri, Method.POST);

                //arizzini: adding cryptography interceptor for POST
                if (interceptor != null)
                {
                    inputMap = interceptor.Encrypt(inputMap);
                }

                request.AddJsonBody(inputMap);
                break;

            case "delete":
                request = new RestRequest(uri, Method.DELETE);
                break;

            case "update":
                request = new RestRequest(uri, Method.PUT);

                //arizzini: adding cryptography interceptor for PUT
                if (interceptor != null)
                {
                    inputMap = interceptor.Encrypt(inputMap);
                }

                request.AddJsonBody(inputMap);
                break;

            case "read":
            case "list":
            case "query":
                request = new RestRequest(uri, Method.GET);
                break;
            }

            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("User-Agent", "CSharp-SDK/" + this.apiVersion);

            //arizzini: adding the header paramter support.
            foreach (KeyValuePair <string, object> entry in headerMap)
            {
                request.AddHeader(entry.Key, entry.Value.ToString());
            }

            ApiConfig.getAuthentication().SignRequest(uri, request);

            return(request);
        }
Example #5
0
 public bool Equals(CryptographyInterceptor other)
 {
     return(this.GetConfig().Equals(other.GetConfig()));
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="action"></param>
        /// <param name="config"></param>
        /// <param name="inputMap"></param>
        /// <returns></returns>
        protected RestyRequest GetRequest(OperationConfig config, OperationMetadata metadata, RequestMap requestMap)
        {
            RestyRequest request = null;


            // separate the parameterMap and headerMap from requestMap
            IDictionary <String, Object> paramterMap = requestMap.Clone();
            IDictionary <String, Object> headerMap   = Util.SubMap(paramterMap, config.HeaderParams);

            Uri    url           = GetURL(config, metadata, paramterMap);
            String baseUriString = url.Scheme + "://" + url.Host + ":" + url.Port;
            Uri    baseUrl       = new Uri(baseUriString);

            string contentType = "application/json; charset=utf-8";

            if (metadata.ContentTypeOverride != null)
            {
                contentType = metadata.ContentTypeOverride + "; charset=utf-8";
            }

            CryptographyInterceptor interceptor = ApiConfig.GetCryptographyInterceptor(url.AbsolutePath);



            switch (config.Action)
            {
            case "create":
                request = new RestyRequest(url, Method.POST);

                //arizzini: adding cryptography interceptor for POST
                if (interceptor != null)
                {
                    paramterMap = interceptor.Encrypt(paramterMap);
                }
                request.AddJsonBody(paramterMap);
                break;

            case "delete":
                request = new RestyRequest(url, Method.DELETE);
                break;

            case "update":
                request = new RestyRequest(url, Method.PUT);

                //arizzini: adding cryptography interceptor for PUT
                if (interceptor != null)
                {
                    paramterMap = interceptor.Encrypt(paramterMap);
                }
                request.AddJsonBody(paramterMap);
                break;

            case "read":
            case "list":
            case "query":
                request = new RestyRequest(url, Method.GET);
                break;
            }

            request.AddHeader("Accept", contentType);
            if (request.HasBody)
            {
                request.AddHeader("Content-Type", contentType);
            }
            request.AddHeader("User-Agent", Constants.getCoreVersion() + "/" + metadata.Version);

            //arizzini: adding the header paramter support.
            foreach (KeyValuePair <string, object> entry in headerMap)
            {
                request.AddHeader(entry.Key, entry.Value.ToString());
            }

            ApiConfig.GetAuthentication().SignRequest(url, request);


            request.AbsoluteUrl = url;
            request.BaseUrl     = baseUrl;
            request.interceptor = interceptor;


            return(request);
        }