Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bucket operation #191

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ Products/
# big Resource for test
Example/AliyunOSSSDK-iOS-Example/Resources/

# Python script generated files
script generated files
Scripts/*.pyc
12 changes: 12 additions & 0 deletions AliyunOSSSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
D829F3AA1FD8CFBE00A8C2DC /* OSSInputStreamHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = D829F3A71FD8CFBE00A8C2DC /* OSSInputStreamHelper.h */; };
D829F3AB1FD8CFBE00A8C2DC /* OSSInputStreamHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = D829F3A81FD8CFBE00A8C2DC /* OSSInputStreamHelper.m */; };
D829F3AC1FD8CFBE00A8C2DC /* OSSInputStreamHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = D829F3A81FD8CFBE00A8C2DC /* OSSInputStreamHelper.m */; };
D833051F21A25E40001F42D9 /* OSSRequest+Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = D833051D21A25E40001F42D9 /* OSSRequest+Utils.h */; };
D833052021A25E40001F42D9 /* OSSRequest+Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = D833051D21A25E40001F42D9 /* OSSRequest+Utils.h */; };
D833052121A25E40001F42D9 /* OSSRequest+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = D833051E21A25E40001F42D9 /* OSSRequest+Utils.m */; };
D833052221A25E40001F42D9 /* OSSRequest+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = D833051E21A25E40001F42D9 /* OSSRequest+Utils.m */; };
D842D59B1FFCAAD600220913 /* AliyunOSSiOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21028BBC1BA9ABF500C2A6BA /* AliyunOSSiOS.framework */; };
D842D59C1FFCAAF300220913 /* OSSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = D842D5891FFC8C0500220913 /* OSSLog.swift */; };
D842D5A81FFCBA2800220913 /* AliyunOSSiOS.h in Headers */ = {isa = PBXBuildFile; fileRef = D842D5A71FFCBA2800220913 /* AliyunOSSiOS.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -259,6 +263,8 @@
D827B4342111ADF7003A24F6 /* OSSGetSymlinkResult.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSSGetSymlinkResult.m; sourceTree = "<group>"; };
D829F3A71FD8CFBE00A8C2DC /* OSSInputStreamHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSSInputStreamHelper.h; sourceTree = "<group>"; };
D829F3A81FD8CFBE00A8C2DC /* OSSInputStreamHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSSInputStreamHelper.m; sourceTree = "<group>"; };
D833051D21A25E40001F42D9 /* OSSRequest+Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OSSRequest+Utils.h"; sourceTree = "<group>"; };
D833051E21A25E40001F42D9 /* OSSRequest+Utils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "OSSRequest+Utils.m"; sourceTree = "<group>"; };
D842D5891FFC8C0500220913 /* OSSLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSSLog.swift; sourceTree = "<group>"; };
D842D5911FFCA8F300220913 /* AliyunOSSSwiftSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AliyunOSSSwiftSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D842D59E1FFCB97900220913 /* AliyunOSSSwift.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AliyunOSSSwift.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -486,6 +492,8 @@
D827B42E2111ADE9003A24F6 /* OSSPutSymlinkResult.m */,
D827B4332111ADF7003A24F6 /* OSSGetSymlinkResult.h */,
D827B4342111ADF7003A24F6 /* OSSGetSymlinkResult.m */,
D833051D21A25E40001F42D9 /* OSSRequest+Utils.h */,
D833051E21A25E40001F42D9 /* OSSRequest+Utils.m */,
);
path = AliyunOSSSDK;
sourceTree = "<group>";
Expand Down Expand Up @@ -550,6 +558,7 @@
files = (
D8C41B1A1FCC2FD20091699B /* OSSModel.h in Headers */,
D8C41B1D1FCC2FD20091699B /* OSSCompat.h in Headers */,
D833051F21A25E40001F42D9 /* OSSRequest+Utils.h in Headers */,
D8C41B1F1FCC2FD20091699B /* OSSUtil.h in Headers */,
D8C41B201FCC2FD20091699B /* OSSXMLDictionary.h in Headers */,
D8C41B211FCC2FD20091699B /* OSSClient.h in Headers */,
Expand Down Expand Up @@ -608,6 +617,7 @@
files = (
D80C81FB1FC82541008E3900 /* OSSModel.h in Headers */,
D80C81FE1FC8254D008E3900 /* OSSXMLDictionary.h in Headers */,
D833052021A25E40001F42D9 /* OSSRequest+Utils.h in Headers */,
D80C81FF1FC82554008E3900 /* OSSClient.h in Headers */,
D80C82021FC8255B008E3900 /* OSSNetworking.h in Headers */,
D80C82131FC82596008E3900 /* OSSIPv6Adapter.h in Headers */,
Expand Down Expand Up @@ -838,6 +848,7 @@
D827B41321114E4B003A24F6 /* NSMutableDictionary+OSS.m in Sources */,
D85278122015DF4900D7B1DE /* OSSConstants.m in Sources */,
D80C88CB201AC1B400F379D8 /* OSSGetObjectACLRequest.m in Sources */,
D833052121A25E40001F42D9 /* OSSRequest+Utils.m in Sources */,
D8C41B0E1FCC2F920091699B /* OSSDDLog.m in Sources */,
D8C2951A20F46A95008A08AA /* OSSGetBucketInfoResult.m in Sources */,
D8C41B101FCC2F920091699B /* OSSReachability.m in Sources */,
Expand Down Expand Up @@ -891,6 +902,7 @@
D827B41421114E4B003A24F6 /* NSMutableDictionary+OSS.m in Sources */,
D85278132015DF4900D7B1DE /* OSSConstants.m in Sources */,
D80C88CC201AC1B400F379D8 /* OSSGetObjectACLRequest.m in Sources */,
D833052221A25E40001F42D9 /* OSSRequest+Utils.m in Sources */,
D8C41ACF1FCC28500091699B /* OSSDDLog.m in Sources */,
D8C2951B20F46A95008A08AA /* OSSGetBucketInfoResult.m in Sources */,
D8C41AD11FCC28500091699B /* OSSReachability.m in Sources */,
Expand Down
63 changes: 43 additions & 20 deletions AliyunOSSSDK/OSSAllRequestNeededMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#import "OSSDefine.h"
#import "OSSUtil.h"

static NSString * const kOSSInvalidBucketNameMessage = @"The bucket name is invalid. \nA bucket name must: \n1) be comprised of lower-case characters, numbers or dash(-); \n2) start with lower case or numbers; \n3) be between 3-63 characters long.";

static NSString * const kOSSInvalidObjectNameMessage = @"The object key is invalid. \nAn object name should be: \n1) between 1 - 1023 bytes long when encoded as UTF-8 \n2) cannot contain LF or CR or unsupported chars in XML1.0, \n3) cannot begin with \'/\' or \'\\\'.";

@implementation OSSAllRequestNeededMessage

- (instancetype)init
Expand All @@ -33,31 +37,23 @@ - (void)setHeaderParams:(NSMutableDictionary *)headerParams {
- (OSSTask *)validateRequestParamsInOperationType:(OSSOperationType)operType {
NSString * errorMessage = nil;

// 1.check for endpoint
if (!self.endpoint) {
errorMessage = @"Endpoint should not be nil";
}

if (!self.bucketName && operType != OSSOperationTypeGetService) {
errorMessage = @"Bucket name should not be nil";
}

if (self.bucketName && ![OSSUtil validateBucketName:self.bucketName]) {
errorMessage = @"Bucket name invalid";
}

if (!self.objectKey &&
(operType != OSSOperationTypeGetBucket && operType != OSSOperationTypeCreateBucket
&& operType != OSSOperationTypeDeleteBucket && operType != OSSOperationTypeGetService
&& operType != OSSOperationTypeGetBucketACL&& operType != OSSOperationTypeDeleteMultipleObjects
&& operType != OSSOperationTypeListMultipartUploads
&& operType != OSSOperationTypeGetBucketInfo)) {
errorMessage = @"Object key should not be nil";
// 2.check for bucket and object
if (operType != OSSOperationTypeGetService) {
if (![_bucketName oss_isNotEmpty]
|| ![OSSUtil validateBucketName:_bucketName]) {
errorMessage = kOSSInvalidBucketNameMessage;
}
if (![self operationBelongsToBucket:operType]) {
if (![_objectKey oss_isNotEmpty]
|| ![OSSUtil validateObjectKey:_objectKey]) {
errorMessage = kOSSInvalidObjectNameMessage;
}
}



if (self.objectKey && ![OSSUtil validateObjectKey:self.objectKey]) {
errorMessage = @"Object key invalid";
}

if (errorMessage) {
Expand All @@ -69,4 +65,31 @@ - (OSSTask *)validateRequestParamsInOperationType:(OSSOperationType)operType {
}
}

- (BOOL)operationBelongsToBucket:(OSSOperationType)type {
BOOL belongsToBucket = NO;
switch (type) {
case OSSOperationTypeGetService:
case OSSOperationTypeCreateBucket:
case OSSOperationTypeDeleteBucket:
case OSSOperationTypeGetBucket:
case OSSOperationTypeGetBucketInfo:
case OSSOperationTypeGetBucketACL:
case OSSOperationTypePutBucketACL:
case OSSOperationTypePutBucketLogging:
case OSSOperationTypeGetBucketLogging:
case OSSOperationTypeDeleteBucketLogging:
case OSSOperationTypePutBucketReferer:
case OSSOperationTypeGetBucketReferer:
case OSSOperationTypePutBucketLifecycle:
case OSSOperationTypeGetBucketLifecycle:
case OSSOperationTypeDeleteBucketLifecycle:
belongsToBucket = YES;
break;
default:
break;
}

return belongsToBucket;
}

@end
82 changes: 79 additions & 3 deletions AliyunOSSSDK/OSSClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@
@class OSSGetServiceRequest;
@class OSSCreateBucketRequest;
@class OSSDeleteBucketRequest;
@class OSSHeadObjectRequest;
@class OSSGetBucketRequest;
@class OSSPutBucketACLRequest;
@class OSSGetBucketACLRequest;
@class OSSGetBucketInfoRequest;
@class OSSPutBucketLoggingRequest;
@class OSSGetBucketLoggingRequest;
@class OSSDeleteBucketLoggingRequest;
@class OSSPutBucketRefererRequest;
@class OSSGetBucketRefererRequest;
@class OSSPutBucketLifecycleRequest;
@class OSSGetBucketLifecycleRequest;
@class OSSDeleteBucketLifecycleRequest;

@class OSSGetBucketRequest;
@class OSSHeadObjectRequest;
@class OSSGetObjectRequest;
@class OSSGetObjectACLRequest;
@class OSSPutObjectRequest;
Expand All @@ -31,7 +42,6 @@
@class OSSMultipartUploadRequest;
@class OSSCallBackRequest;
@class OSSImagePersistRequest;
@class OSSGetBucketInfoRequest;
@class OSSPutSymlinkRequest;
@class OSSGetSymlinkRequest;
@class OSSRestoreObjectRequest;
Expand Down Expand Up @@ -139,12 +149,78 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (OSSTask *)getBucketInfo:(OSSGetBucketInfoRequest *)request;

- (OSSTask *)putBucketACL:(OSSPutBucketACLRequest *)request;

/**
The corresponding RESTFul API: GetBucketACL
Gets the bucket ACL.
*/
- (OSSTask *)getBucketACL:(OSSGetBucketACLRequest *)request;

/**
Update the bucket logging settings. Log file will create every one hour and name format: <prefix><bucket>-YYYY-mm-DD-HH-MM-SS-UniqueString

@param request an instance of OSSPutBucketLoggingRequest
@return an instance of OSSTask
*/
- (OSSTask *)putBucketLogging:(OSSPutBucketLoggingRequest *)request;

/**
Get the bucket logging settings.

@param request an instance of OSSGetBucketLoggingRequest
@return an instance of OSSTask
*/
- (OSSTask *)getBucketLogging:(OSSGetBucketLoggingRequest *)request;

/**
Delete the bucket logging settings.

@param request an instance of OSSDeleteBucketLoggingRequest
@return an instance of OSSTask
*/
- (OSSTask *)deleteBucketLogging:(OSSDeleteBucketLoggingRequest *)request;

/**
Set the bucket request Referer white list.

@param request an OSSPutBucketRefererRequest instance.
@return an OSSTask instance.
*/
- (OSSTask *)putBucketReferer:(OSSPutBucketRefererRequest *)request;

/**
Get the bucket request Referer white list.

@param request an OSSGetBucketRefererRequest instance.
@return an OSSTask instance.
*/
- (OSSTask *)getBucketReferer:(OSSGetBucketRefererRequest *)request;

/**
The bucket owner can set the lifecycle of a bucket with the PutBucketLifecycle request. After Lifecycle is enabled, OSS automatically deletes the objects or transitions the objects (to another storage class) corresponding the lifecycle rules on a regular basis.for more information,please refer to https://www.alibabacloud.com/help/doc-detail/31964.htm

@param request an OSSPutBucketLifecycleRequest instance.
@return an OSSTask instance.
*/
- (OSSTask *)putBucketLifecycle:(OSSPutBucketLifecycleRequest *)request;

/**
GetBucketLifecycle is used to view the lifecycle configuration of a bucket.for more information,please refer to https://www.alibabacloud.com/help/doc-detail/31972.htm

@param request an OSSGetBucketLifecycleRequest instance.
@return an OSSTask instance.
*/
- (OSSTask *)getBucketLifecycle:(OSSGetBucketLifecycleRequest *)request;

/**
The DeleteBucketLifecycle interface is used to delete the lifecycle configuration of a specified bucket.for more information,please refer to https://www.alibabacloud.com/help/doc-detail/31976.htm

@param request an OSSDeleteBucketLifecycleRequest instance
@return an OSSTask instance
*/
- (OSSTask *)deleteBucketLifecycle:(OSSDeleteBucketLifecycleRequest *)request;

@end


Expand Down
Loading