1 /* 2 * Copyright 2009-2017 Alibaba Cloud All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ALIBABACLOUD_OSS_OSSCLIENTIMPL_H_ 18 #define ALIBABACLOUD_OSS_OSSCLIENTIMPL_H_ 19 20 #include <alibabacloud/oss/client/ClientConfiguration.h> 21 #include <alibabacloud/oss/auth/CredentialsProvider.h> 22 #include <alibabacloud/oss/OssRequest.h> 23 #include <alibabacloud/oss/OssResponse.h> 24 #include <alibabacloud/oss/utils/Executor.h> 25 #include <alibabacloud/oss/OssFwd.h> 26 #include "auth/Signer.h" 27 #include "client/Client.h" 28 #ifdef GetObject 29 #undef GetObject 30 #endif 31 32 namespace AlibabaCloud 33 { 34 namespace OSS 35 { 36 class OssClientImpl : public Client 37 { 38 public: 39 typedef Client BASE; 40 41 OssClientImpl(const std::string &endpoint, const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration); 42 virtual ~OssClientImpl(); 43 int asyncExecute(Runnable * r) const; 44 45 #if !defined(OSS_DISABLE_BUCKET) 46 ListBucketsOutcome ListBuckets(const ListBucketsRequest &request) const; 47 CreateBucketOutcome CreateBucket(const CreateBucketRequest &request) const; 48 VoidOutcome SetBucketAcl(const SetBucketAclRequest& request) const; 49 VoidOutcome SetBucketLogging(const SetBucketLoggingRequest& request) const; 50 VoidOutcome SetBucketWebsite(const SetBucketWebsiteRequest& request) const; 51 VoidOutcome SetBucketReferer(const SetBucketRefererRequest& request) const; 52 VoidOutcome SetBucketLifecycle(const SetBucketLifecycleRequest& request) const; 53 VoidOutcome SetBucketCors(const SetBucketCorsRequest& request) const; 54 VoidOutcome SetBucketStorageCapacity(const SetBucketStorageCapacityRequest& request) const; 55 VoidOutcome SetBucketPolicy(const SetBucketPolicyRequest& request) const; 56 VoidOutcome SetBucketRequestPayment(const SetBucketRequestPaymentRequest& request) const; 57 VoidOutcome SetBucketEncryption(const SetBucketEncryptionRequest& request) const; 58 VoidOutcome SetBucketTagging(const SetBucketTaggingRequest& request) const; 59 VoidOutcome SetBucketQosInfo(const SetBucketQosInfoRequest& request) const; 60 VoidOutcome SetBucketVersioning(const SetBucketVersioningRequest& request) const; 61 VoidOutcome SetBucketInventoryConfiguration(const SetBucketInventoryConfigurationRequest& request) const; 62 63 VoidOutcome DeleteBucket(const DeleteBucketRequest &request) const; 64 VoidOutcome DeleteBucketLogging(const DeleteBucketLoggingRequest& request) const; 65 VoidOutcome DeleteBucketWebsite(const DeleteBucketWebsiteRequest& request) const; 66 VoidOutcome DeleteBucketLifecycle(const DeleteBucketLifecycleRequest& request) const; 67 VoidOutcome DeleteBucketCors(const DeleteBucketCorsRequest& request) const; 68 VoidOutcome DeleteBucketPolicy(const DeleteBucketPolicyRequest& request) const; 69 VoidOutcome DeleteBucketEncryption(const DeleteBucketEncryptionRequest& request) const; 70 VoidOutcome DeleteBucketTagging(const DeleteBucketTaggingRequest& request) const; 71 VoidOutcome DeleteBucketQosInfo(const DeleteBucketQosInfoRequest& request) const; 72 VoidOutcome DeleteBucketInventoryConfiguration(const DeleteBucketInventoryConfigurationRequest& request) const; 73 74 ListBucketInventoryConfigurationsOutcome ListBucketInventoryConfigurations(const ListBucketInventoryConfigurationsRequest& request) const; 75 76 GetBucketAclOutcome GetBucketAcl(const GetBucketAclRequest &request) const; 77 GetBucketLocationOutcome GetBucketLocation(const GetBucketLocationRequest &request) const; 78 GetBucketInfoOutcome GetBucketInfo(const GetBucketInfoRequest &request) const; 79 GetBucketLoggingOutcome GetBucketLogging(const GetBucketLoggingRequest &request) const; 80 GetBucketWebsiteOutcome GetBucketWebsite(const GetBucketWebsiteRequest &request) const; 81 GetBucketRefererOutcome GetBucketReferer(const GetBucketRefererRequest &request) const; 82 GetBucketLifecycleOutcome GetBucketLifecycle(const GetBucketLifecycleRequest &request) const; 83 GetBucketStatOutcome GetBucketStat(const GetBucketStatRequest &request) const; 84 GetBucketCorsOutcome GetBucketCors(const GetBucketCorsRequest &request) const; 85 GetBucketStorageCapacityOutcome GetBucketStorageCapacity(const GetBucketStorageCapacityRequest& request) const; 86 GetBucketPolicyOutcome GetBucketPolicy(const GetBucketPolicyRequest& request) const; 87 GetBucketPaymentOutcome GetBucketRequestPayment(const GetBucketRequestPaymentRequest& request) const; 88 GetBucketEncryptionOutcome GetBucketEncryption(const GetBucketEncryptionRequest& request) const; 89 GetBucketTaggingOutcome GetBucketTagging(const GetBucketTaggingRequest& request) const; 90 GetBucketQosInfoOutcome GetBucketQosInfo(const GetBucketQosInfoRequest& request) const; 91 GetUserQosInfoOutcome GetUserQosInfo(const GetUserQosInfoRequest& request) const; 92 GetBucketVersioningOutcome GetBucketVersioning(const GetBucketVersioningRequest& request) const; 93 GetBucketInventoryConfigurationOutcome GetBucketInventoryConfiguration(const GetBucketInventoryConfigurationRequest& request) const; 94 #endif 95 96 /*Object*/ 97 ListObjectOutcome ListObjects(const ListObjectsRequest &request) const; 98 ListObjectVersionsOutcome ListObjectVersions(const ListObjectVersionsRequest &request) const; 99 100 GetObjectOutcome GetObject(const GetObjectRequest &request) const; 101 PutObjectOutcome PutObject(const PutObjectRequest &request) const; 102 DeleteObjectOutcome DeleteObject(const DeleteObjectRequest &request) const; 103 DeleteObjecstOutcome DeleteObjects(const DeleteObjectsRequest &request) const; 104 DeleteObjecVersionstOutcome DeleteObjectVersions(const DeleteObjectVersionsRequest& request) const; 105 ObjectMetaDataOutcome HeadObject(const HeadObjectRequest &request) const; 106 ObjectMetaDataOutcome GetObjectMeta(const GetObjectMetaRequest &request) const; 107 108 GetObjectAclOutcome GetObjectAcl(const GetObjectAclRequest &request) const; 109 AppendObjectOutcome AppendObject(const AppendObjectRequest &request) const; 110 CopyObjectOutcome CopyObject(const CopyObjectRequest &request) const; 111 GetSymlinkOutcome GetSymlink(const GetSymlinkRequest &request) const; 112 RestoreObjectOutcome RestoreObject(const RestoreObjectRequest &request) const; 113 CreateSymlinkOutcome CreateSymlink(const CreateSymlinkRequest &request) const; 114 SetObjectAclOutcome SetObjectAcl(const SetObjectAclRequest &request) const; 115 GetObjectOutcome ProcessObject(const ProcessObjectRequest &request) const; 116 117 GetObjectOutcome SelectObject(const SelectObjectRequest &request) const; 118 CreateSelectObjectMetaOutcome CreateSelectObjectMeta(const CreateSelectObjectMetaRequest &request) const; 119 120 SetObjectTaggingOutcome SetObjectTagging(const SetObjectTaggingRequest& request) const; 121 DeleteObjectTaggingOutcome DeleteObjectTagging(const DeleteObjectTaggingRequest& request) const; 122 GetObjectTaggingOutcome GetObjectTagging(const GetObjectTaggingRequest& request) const; 123 124 /*MultipartUpload*/ 125 InitiateMultipartUploadOutcome InitiateMultipartUpload(const InitiateMultipartUploadRequest &request) const; 126 PutObjectOutcome UploadPart(const UploadPartRequest& request) const; 127 UploadPartCopyOutcome UploadPartCopy(const UploadPartCopyRequest &request) const; 128 CompleteMultipartUploadOutcome CompleteMultipartUpload(const CompleteMultipartUploadRequest &request) const; 129 VoidOutcome AbortMultipartUpload(const AbortMultipartUploadRequest &request) const; 130 ListMultipartUploadsOutcome ListMultipartUploads(const ListMultipartUploadsRequest &request) const; 131 ListPartsOutcome ListParts(const ListPartsRequest &request) const; 132 133 /*Generate URL*/ 134 StringOutcome GeneratePresignedUrl(const GeneratePresignedUrlRequest &request) const; 135 GetObjectOutcome GetObjectByUrl(const GetObjectByUrlRequest &request) const; 136 PutObjectOutcome PutObjectByUrl(const PutObjectByUrlRequest &request) const; 137 138 139 /*Generate Post Policy*/ 140 141 #if !defined(OSS_DISABLE_RESUAMABLE) 142 /*Resumable Operation*/ 143 PutObjectOutcome ResumableUploadObject(const UploadObjectRequest& request) const; 144 CopyObjectOutcome ResumableCopyObject(const MultiCopyObjectRequest& request) const; 145 GetObjectOutcome ResumableDownloadObject(const DownloadObjectRequest& request) const; 146 #endif 147 148 #if !defined(OSS_DISABLE_LIVECHANNEL) 149 /*Live Channel*/ 150 VoidOutcome PutLiveChannelStatus(const PutLiveChannelStatusRequest &request) const; 151 PutLiveChannelOutcome PutLiveChannel(const PutLiveChannelRequest &request) const; 152 VoidOutcome PostVodPlaylist(const PostVodPlaylistRequest &request) const; 153 GetVodPlaylistOutcome GetVodPlaylist(const GetVodPlaylistRequest& request) const; 154 GetLiveChannelStatOutcome GetLiveChannelStat(const GetLiveChannelStatRequest &request) const; 155 GetLiveChannelInfoOutcome GetLiveChannelInfo(const GetLiveChannelInfoRequest &request) const; 156 GetLiveChannelHistoryOutcome GetLiveChannelHistory(const GetLiveChannelHistoryRequest &request) const; 157 ListLiveChannelOutcome ListLiveChannel(const ListLiveChannelRequest &request) const; 158 VoidOutcome DeleteLiveChannel(const DeleteLiveChannelRequest &request) const; 159 StringOutcome GenerateRTMPSignedUrl(const GenerateRTMPSignedUrlRequest &request) const; 160 #endif 161 162 /*Requests control*/ 163 void DisableRequest(); 164 void EnableRequest(); 165 166 protected: 167 virtual std::shared_ptr<HttpRequest> buildHttpRequest(const std::string & endpoint, const ServiceRequest &msg, Http::Method method) const; 168 virtual bool hasResponseError(const std::shared_ptr<HttpResponse>&response) const; 169 OssOutcome MakeRequest(const OssRequest &request, Http::Method method) const; 170 171 private: 172 void addHeaders(const std::shared_ptr<HttpRequest> &httpRequest, const HeaderCollection &headers) const; 173 void addBody(const std::shared_ptr<HttpRequest> &httpRequest, const std::shared_ptr<std::iostream>& body, bool contentMd5 = false) const; 174 void addSignInfo(const std::shared_ptr<HttpRequest> &httpRequest, const ServiceRequest &request) const; 175 void addUrl(const std::shared_ptr<HttpRequest> &httpRequest, const std::string &endpoint, const ServiceRequest &request) const; 176 void addOther(const std::shared_ptr<HttpRequest> &httpRequest, const ServiceRequest &request) const; 177 178 OssError buildError(const Error &error) const; 179 ServiceResult buildResult(const OssRequest &request, const std::shared_ptr<HttpResponse> &httpResponse) const; 180 181 private: 182 std::string endpoint_; 183 std::shared_ptr<CredentialsProvider> credentialsProvider_; 184 std::shared_ptr<Signer> signer_; 185 std::shared_ptr<Executor> executor_; 186 }; 187 } 188 } 189 #endif // !ALIBABACLOUD_OSS_OSSCLIENTIMPL_H_ 190