public void testConfig()
        {
            String config =
                "access_key: 'testkey'\n"
                + "access_secret: 'test_asss'\n"
                + "host: qingcloud.com\n"
                + "port: 443\n"
                + "protocol: https\n";
            FileStream f     = new FileStream(System.Environment.CurrentDirectory + "/tmp/key.csv", FileMode.Open);
            Boolean    bConf = false;

            try
            {
                StreamReader output = new StreamReader(f);
                output.ReadToEnd();
                output.Close();
                f.Close();
                bConf = true;
            }
            catch (Exception e)
            {
                System.Console.Write(e.Message);
            }

            if (bConf)
            {
                EvnContext evnContext = EvnContext.loadFromFile(System.Environment.CurrentDirectory + "/tmp/key.csv");
                Assert.AreEqual(evnContext.getAccessKey(), "testkey");
                Assert.AreEqual(evnContext.getAccessSecret(), "testaccess");
                Assert.AreEqual(evnContext.getRequestUrl(), "https://qingcloud.com:443");
            }
        }
Пример #2
0
        public static String getExpireAuth(Dictionary <object, object> context, int expiresSecond, RequestInputModel Params)
        {
            EvnContext evnContext = (EvnContext)context[QSConstant.EVN_CONTEXT_KEY];

            Dictionary <object, object> paramsQuery   = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_QUERY);
            Dictionary <object, object> paramsHeaders = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_HEADER);

            paramsHeaders.Remove(QSConstant.HEADER_PARAM_KEY_DATE);
            paramsHeaders.Clear();
            paramsHeaders.Add(QSConstant.HEADER_PARAM_KEY_EXPIRES, expiresSecond + "");

            string method      = (string)context[QSConstant.PARAM_KEY_REQUEST_METHOD];
            string bucketName  = (string)context[QSConstant.PARAM_KEY_BUCKET_NAME];
            string requestPath = (string)context[QSConstant.PARAM_KEY_REQUEST_PATH];

            requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName);
            if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME))
            {
                requestPath = requestPath.Replace(QSConstant.OBJECT_NAME_REPLACE, (string)context[QSConstant.PARAM_KEY_OBJECT_NAME]);
            }
            string authSign = getSignature(
                evnContext.getAccessKey(),
                evnContext.getAccessSecret(),
                method,
                requestPath,
                paramsQuery,
                paramsHeaders);

            return(HttpUtility.UrlEncode(authSign, Encoding.GetEncoding(QSConstant.ENCODING_UTF8)));
        }
        public void testDefault()
        {
            EvnContext evnContext = new EvnContext("testkey", "test_asss");

            Assert.AreEqual(evnContext.getAccessKey(), "testkey");
            Assert.AreEqual(evnContext.getAccessSecret(), "test_asss");
            Assert.AreEqual(evnContext.getRequestUrl(), "https://qingstor.com");
            Assert.AreEqual(evnContext.getLog_level(), QSConstant.LOGGER_ERROR);
        }
Пример #4
0
        private HttpWebRequest buildRequest(Dictionary <object, object> context, RequestInputModel Params)
        {
            EvnContext evnContext = (EvnContext)context[QSConstant.EVN_CONTEXT_KEY];
            string     zone       = (string)context[QSConstant.PARAM_KEY_REQUEST_ZONE];

            Dictionary <object, object> paramsQuery   = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_QUERY);
            Dictionary <object, object> paramsBody    = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_BODY);
            Dictionary <object, object> paramsHeaders = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_HEADER);

            if (context.ContainsKey(QSConstant.PARAM_KEY_USER_AGENT))
            {
                paramsHeaders.Add(QSConstant.PARAM_KEY_USER_AGENT, context[QSConstant.PARAM_KEY_USER_AGENT]);
            }

            String requestApi = (String)context[QSConstant.PARAM_KEY_REQUEST_APINAME];

            //string FileBody = GetBodyFile(context[QSConstant.PARAM_KEY_OBJECT_NAME].ToString()).ToString();
            paramsHeaders = initHeadContentMd5(requestApi, paramsBody, paramsHeaders);

            string method      = (string)context[QSConstant.PARAM_KEY_REQUEST_METHOD];
            string bucketName  = (string)context[QSConstant.PARAM_KEY_BUCKET_NAME];
            string requestPath = (string)context[QSConstant.PARAM_KEY_REQUEST_PATH];

            string objectName = "";

            if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME))
            {
                objectName = context[QSConstant.PARAM_KEY_OBJECT_NAME].ToString();
            }
            if (!paramsHeaders.ContainsKey(QSConstant.HEADER_PARAM_KEY_CONTENTTYPE))
            {
                paramsHeaders.Add(QSConstant.HEADER_PARAM_KEY_CONTENTTYPE, MimeMapping.GetMimeMapping(objectName));
            }

            if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME))
            {
                requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName);
                requestPath = requestPath.Replace(QSConstant.OBJECT_NAME_REPLACE, QSStringUtil.urlCharactersEncoding(objectName));
            }
            else
            {
                requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName + "/");
            }

            string authSign =
                QSSignatureUtil.getAuth(
                    evnContext.getAccessKey(),
                    evnContext.getAccessSecret(),
                    method,
                    requestPath,
                    paramsQuery,
                    paramsHeaders);
            string requestSuffixPath = getRequestSuffixPath((string)context[QSConstant.PARAM_KEY_REQUEST_PATH], bucketName, objectName);

            paramsHeaders.Add("Authorization", authSign);
            logger.Info(authSign);
            string singedUrl =
                getSignedUrl(
                    evnContext.getRequestUrl(),
                    zone,
                    bucketName,
                    paramsQuery,
                    requestSuffixPath);

            if (singedUrl.IndexOf("&upload_id") != -1)//?part_number=0&upload_id=1asfdsf
            {
                if (singedUrl.IndexOf("upload_id") > singedUrl.IndexOf("part_number"))
                {
                    String temp1 = singedUrl.Substring(singedUrl.IndexOf("part_number"), singedUrl.IndexOf("&upload_id") - singedUrl.IndexOf("part_number"));
                    String temp2 = singedUrl.Substring(singedUrl.IndexOf("upload_id"), singedUrl.Length - singedUrl.IndexOf("upload_id"));
                    singedUrl = singedUrl.Substring(0, singedUrl.IndexOf("?") + 1) + temp2 + "&" + temp1; //singedUrl.Replace(temp1, temp2).Replace(temp2,temp1);
                }
            }
            logger.Info(singedUrl);
            if (QSConstant.PARAM_KEY_REQUEST_API_MULTIPART.Equals(requestApi))
            {
                HttpWebRequest request =
                    QSHttpRequestClient.getInstance()
                    .buildStorMultiUpload(
                        method, paramsBody, singedUrl, paramsHeaders, paramsQuery);
                return(request);
            }
            else
            {
                //System.Console.WriteLine(singedUrl);
                HttpWebRequest request =
                    QSHttpRequestClient.getInstance()
                    .buildStorRequest(method, paramsBody, singedUrl, paramsHeaders);
                return(request);
            }
        }