Exemplo n.º 1
0
 public ServiceResponse Send(ServiceRequest request, ExecutionContext context)
 {
     SignRequest(request, context);
     var response = SendCore(request, context);
     HandleResponse(response, context.ResponseHandlers);
     return response;
 }
Exemplo n.º 2
0
        public void Sign(ServiceRequest request, ICredentials credentials)
        {
            var accessKeyId = credentials.AccessId;
            var secretAccessKey = credentials.AccessKey;
            var httpMethod = request.Method.ToString().ToUpperInvariant();
            // Because the resource path to is different from the one in the request uri,
            // can't use ServiceRequest.ResourcePath here.
            var resourcePath = _resourcePath;

            if (!string.IsNullOrEmpty(secretAccessKey))
            {
                var canonicalString = SignUtils.BuildCanonicalString(httpMethod, resourcePath, request);
                var signature = ServiceSignature.Create().ComputeSignature(secretAccessKey, canonicalString);
                request.Headers.Add(HttpHeaders.Authorization, "OSS " + accessKeyId + ":" + signature);
            }
        }
 public ServiceResponse Send(ServiceRequest request, ExecutionContext context)
 {
     return(SendImpl(request, context, 0));
 }
Exemplo n.º 4
0
        private ServiceRequest BuildRequest()
        {
            var conf = OssUtils.GetClientConfiguration(Client);
            var request = new ServiceRequest
            {
                Method = Method,
                Endpoint = OssUtils.MakeBucketEndpoint(Endpoint, Bucket, conf),
                ResourcePath = OssUtils.MakeResourcePath(Key)
            };

            foreach(var p in Parameters)
                request.Parameters.Add(p.Key, p.Value);

            var adjustedTime = DateTime.UtcNow.AddSeconds(conf.TickOffset);
            request.Headers[HttpHeaders.Date] = DateUtils.FormatRfc822Date(adjustedTime);
            if (!Headers.ContainsKey(HttpHeaders.ContentType))
                request.Headers[HttpHeaders.ContentType] = string.Empty;
            foreach(var h in Headers)
                request.Headers.Add(h.Key, h.Value);
            if (Context.Credentials.UseToken)
                request.Headers[HttpHeaders.SecurityToken] = Context.Credentials.SecurityToken;

            request.Content = Content;

            return request;
        }
Exemplo n.º 5
0
 protected abstract IAsyncResult BeginSendCore(ServiceRequest request, ExecutionContext context, 
     AsyncCallback callback, Object state);
Exemplo n.º 6
0
 public IAsyncResult BeginSend(ServiceRequest request, ExecutionContext context, 
     AsyncCallback callback, object state)
 {
     SignRequest(request, context);
     return BeginSendCore(request, context, callback, state);
 }
Exemplo n.º 7
0
 private static void SignRequest(ServiceRequest request, ExecutionContext context)
 {
     if (context.Signer != null)
         context.Signer.Sign(request, context.Credentials);
 }
Exemplo n.º 8
0
 protected abstract ServiceResponse SendCore(ServiceRequest request, ExecutionContext context);
Exemplo n.º 9
0
 protected abstract IAsyncResult BeginSendCore(ServiceRequest request, ExecutionContext context,
                                               AsyncCallback callback, Object state);
Exemplo n.º 10
0
 protected abstract ServiceResponse SendCore(ServiceRequest request, ExecutionContext context);
Exemplo n.º 11
0
 public IAsyncResult BeginSend(ServiceRequest request, ExecutionContext context,
                               AsyncCallback callback, object state)
 {
     SignRequest(request, context);
     return(BeginSendCore(request, context, callback, state));
 }