-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ts
90 lines (75 loc) · 2.36 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as core from '@actions/core';
import * as context from './context';
import * as utils from './utils';
import * as upload from './obs/upload';
import * as download from './obs/download';
import * as bucket from './obs/bucket';
async function run() {
const commonInputs = context.getCommonInputs();
if (!utils.checkCommonInputs(commonInputs)) {
return;
}
// 初始化OBS客户端
const obs = context.getObsClient(
commonInputs.accessKey,
commonInputs.secretKey,
`https://obs.${commonInputs.region}.myhuaweicloud.com`
);
const operationCategory = utils.getOperationCategory(context.getOperationType());
if (operationCategory === 'object') {
handleObject(obs);
} else if (operationCategory === 'bucket') {
handleBucket(obs);
} else {
core.setFailed(
`please check your operation_type. you can use 'download', 'upload', 'createbucket' or 'deletebucket'.`
);
}
}
/**
* 处理对象,目前支持上传对象,下载对象
* @param obs OBS客户端
* @returns
*/
async function handleObject(obs: any): Promise<void> {
const inputs = context.getObjectInputs();
if (!utils.checkObjectInputs(inputs)) {
return;
}
// 若桶不存在,退出
if (!(await bucket.hasBucket(obs, inputs.bucketName))) {
core.setFailed(`The bucket: ${inputs.bucketName} does not exists.`);
return;
}
// 执行上传/下载操作
if (inputs.operationType === 'upload') {
await upload.uploadFileOrFolder(obs, inputs);
}
if (inputs.operationType === 'download') {
await download.downloadFileOrFolder(obs, inputs);
}
}
/**
* 处理桶,目前支持新增桶,删除桶
* @param obs OBS客户端
* @returns
*/
async function handleBucket(obs: any): Promise<void> {
const inputs = context.getBucketInputs();
if (!utils.checkBucketInputs(inputs)) {
return;
}
if (inputs.operationType.toLowerCase() === 'createbucket') {
bucket.createBucket(
obs,
inputs.bucketName,
inputs.region,
inputs.publicRead,
utils.getStorageClass(inputs.storageClass ?? '')
);
}
if (inputs.operationType.toLowerCase() === 'deletebucket') {
await bucket.deleteBucket(obs, inputs.bucketName, inputs.clearBucket);
}
}
run();