3 Star 0 Fork 0

HuaweiCloudDeveloper / obs-helper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Huawei Cloud OBS Helper

对象存储服务(Object Storage Service,OBS)是一个基于对象的海量存储服务,为客户提供海量、安全、高可靠、低成本的数据存储能力。 您可以使用OBS Helper action实现如下对OBS的操作:
1、上传文件/文件夹
2、下载文件/文件夹
3、创建桶
4、删除桶
本项目说明文件仅做基础功能示例,具体不同场景下的使用样例及其参数使用请访问OBS Helper Workflow Sample

前置工作

1、需要开通华为云的OBS服务,进行对象操作时需要建好桶。OBS主页OBS文档
2、action调用华为云接口需要华为云鉴权,建议将您华为云账户的ak/sk配置于您GitHub工程中的settting-Secret-Actions,分别添加为ACCESSKEY、SECRETACCESSKEY以加密使用,获取ak/sk方式; 3、注意替换参数region为自己OBS服务的地区,方便插件配置终端节点 obs.'<region>'.myhuaweicloud.com 来访问您的OBS服务;
4、注意替换参数bucket_name为自己OBS服务的桶名(创建桶时为要创建的桶名)

华为云统一鉴权认证

推荐使用huaweicloud/auth-action进行OBS操作的鉴权认证。

    - name: Authenticate to Huawei Cloud
      uses: huaweicloud/auth-action@v1.0.0
      with: 
          access_key_id: ${{ secrets.ACCESSKEY }} 
          secret_access_key: ${{ secrets.SECRETACCESSKEY }}
          region: '<region>'

上传下载对象参数说明

参数名称 参数说明 默认值 是否必填
access_key 访问密钥ID。与私有访问密钥关联的唯一标识符,和私有访问密钥(secret_key)一起使用,对请求进行加密签名。建议参照前置工作中的步骤2进行设置以加密使用。如果使用了华为云统一鉴权huaweicloud/auth-action可以不填写此参数
secret_key 与访问密钥ID(access_key)结合使用的私有访问密钥,对请求进行加密签名,可标识发送方,并防止请求被修改。建议参照前置工作中的步骤2进行设置以加密使用。如果使用了华为云统一鉴权huaweicloud/auth-action可以不填写此参数
region OBS服务所在区域。用于配置OBS终端节点。如果使用了华为云统一鉴权huaweicloud/auth-action可以不填写此参数 'cn-north-4'
bucket_name OBS的目标桶名
operation_type 要进行的操作,上传请使用upload,下载请使用download
local_file_path 对象的本地路径,上传对象时可填写1~10个
obs_file_path 对象在桶内的路径 下载时必填
include_self_folder 上传/下载文件夹时是否包含文件夹自身,上传/下载单个文件时无意义。默认不包含 false
exclude 下载对象时,要排除的对象,上传时无用。不填写时不排除任何对象

请注意,上传/下载时,地址类参数请不要使用操作系统独有的地址符号(如Linux系统的'~',会被识别成名为'~'的文件夹)。Github Actions提供的上下文功能中,有一些常用的地址上下文,例如:

name: Show Contexts
on:
  push:
    branches:
        master
jobs:
  Show-Workspace:
    runs-on: ubuntu-latest
    steps:
      # ${{ github.workspace }}为action运行时的工作目录
      - name: Echo Workspace of Action
        run: echo ${{ github.workspace }}

      # ${{ runner.temp }}为运行器临时目录的路径
      - name: Echo Temporary Directory on the Runner
        run: echo ${{ runner.temp }}

创建删除桶参数说明

参数名称 参数说明 默认值 是否必填
access_key 访问密钥ID。与私有访问密钥关联的唯一标识符,和私有访问密钥(secret_key)一起使用,对请求进行加密签名。建议参照前置工作中的步骤2进行设置以加密使用。如果使用了华为云统一鉴权huaweicloud/auth-action可以不填写此参数
secret_key 与访问密钥ID(access_key)结合使用的私有访问密钥,对请求进行加密签名,可标识发送方,并防止请求被修改。建议参照前置工作中的步骤2进行设置以加密使用。如果使用了华为云统一鉴权huaweicloud/auth-action可以不填写此参数
region OBS服务所在区域。用于配置OBS终端节点。如果使用了华为云统一鉴权huaweicloud/auth-action可以不填写此参数 'cn-north-4'
bucket_name OBS的目标桶名
operation_type 要进行的操作,创建桶请使用createbucket,删除桶请使用deletebucket
public_read 创建桶时,是否开放桶公共读权限,不填时默认不开放。如需设置其他权限,请在创建桶后到控制台进行修改 false
storage_class 创建桶时,桶的存储类型,不填时默认为标准存储
clear_bucket 删除桶时,是否清空桶内全部对象/碎片,不填时默认清空 true

参数支持列表

目前OBS支持的区域名称和对应region(区域)、终端节点请见对象存储服务 OBS

目前OBS支持的存储类型(storage_class)如下

  标准存储: standard
  低频访问存储: infrequent
  归档存储: archive

action代码示例片段

以下action示例片段若无特别说明,均默认使用了华为云统一鉴权huaweicloud/auth-action

- name: Authenticate to Huawei Cloud
  uses: huaweicloud/auth-action@v1.0.0
  with: 
    access_key_id: ${{ secrets.ACCESSKEY }} 
    secret_access_key: ${{ secrets.SECRETACCESSKEY }}
    region: 'cn-north-4'

上传文件示例

注意:上传单个文件时,在使用参数obs_file_path的时候,请使用是否以'/'作为结尾来区分是上传为文件,还是上传至文件夹。

假设本地文件夹的格式如下:

└── src1
    ├── src2
          ├── test1.txt
          └── test2.txt
    └── src3
          └── test3.txt

上传文件src1/src2/test1.txt至obs根目录

- name: Upload to Huawei Cloud OBS
  uses: huaweicloud/obs-helper@v1.4.0
  with:
    bucket_name: 'bucket-test'
    local_file_path: 'src1/src2/test1.txt'
    obs_file_path: 'test1.txt'
    operation_type: 'upload'

成功上传后,桶内生成对象为:

test1.txt

上传文件夹src1(包含文件夹自身)至src文件夹

- name: Upload to Huawei Cloud OBS
  uses: huaweicloud/obs-helper@v1.4.0
  with:
    bucket_name: 'bucket-test'
    local_file_path: 'src1'
    obs_file_path: 'src'
    operation_type: 'upload'
    include_self_folder: true

成功上传后,桶内生成对象为:

  src
    └── src1
          ├── src2
                ├── test1.txt
                └── test2.txt
          └── src3
                └── test3.txt

上传多个文件和文件夹(不包含文件夹自身)至src文件夹

- name: Upload to Huawei Cloud OBS
  uses: huaweicloud/obs-helper@v1.4.0
  with:
    bucket_name: 'bucket-test'
    local_file_path: |
      'src1/src2/test1.txt'
      'src1/src3'
    obs_file_path: 'src'
    operation_type: 'upload'
    include_self_folder: false

成功上传后,桶内生成对象为:

  src 
    └── test1.txt
    └── src3
          └── test3.txt

下载文件示例

注意:下载文件时,在使用参数local_file_path的时候,请使用是否以'/'作为结尾来区分是下载为文件,还是下载至文件夹。

假设bucket-test桶内包含如下对象:

test1.txt
src1
  ├── src2
        ├── test2.txt
        └── test3.txt
  └── src3
        └── test4.txt

下载文件test1.txt至文件夹src1中

- name: Download File from Huawei Cloud OBS
  uses: huaweicloud/obs-helper@v1.4.0
  with:
    bucket_name: 'bucket-test'
    local_file_path: 'src1/'
    obs_file_path: 'test1.txt'
    operation_type: 'download'

下载完成后,本地生成的文件为:

└── src1
      └── test1.txt

下载文件夹src1(包含文件夹自身)至文件夹src中

- name: Download from Huawei Cloud OBS
  uses: huaweicloud/obs-helper@v1.4.0
  with:
    bucket_name: 'bucket-test'
    local_file_path: 'src'
    obs_file_path: 'src1'
    operation_type: 'download'
    include_self_folder: true

下载完成后,本地生成的文件为:

src
  └── src1
        ├── src2
              ├── test2.txt
              └── test3.txt
        └── src3
              └── test4.txt

下载文件夹src1(不包含文件夹自身,排除下载桶内src1/sr2/test3.txt和src1/src3目录下的所有文件)到src文件夹下

- name: Download from Huawei Cloud OBS
  uses: huaweicloud/obs-helper@v1.4.0
  with:
    bucket_name: 'bucket-test'
    local_file_path: 'src'
    obs_file_path: 'src1'
    operation_type: 'download'
    include_self_folder: false
    exclude: |
      'src1/src2/test3.txt'
      'src1/src3'

下载完成后,本地生成的文件为:

src
  └── src2
        └── test2.txt

创建桶用法

创建新桶时,可指定是否开放桶公共读权限(public_read)和桶的存储类型(storage_class)。若不指定,默认不开放公共读权限,存储类型为标准存储(standard)。如需开放更多权限,请至obs控制台进行修改。

创建名为'new-bucket'的桶(开放公共读、低频访问存储、未使用统一鉴权)

假设您的OBS中不存在名为'new-bucket'的桶

- name: Create Bucket on Huawei Cloud OBS
  uses: huaweicloud/obs-helper@v1.4.0
  with:
    access_key: ${{ secrets.ACCESSKEY }}
    secret_key: ${{ secrets.SECRETACCESSKEY }}
    region: 'cn-north-4'
    bucket_name: 'new-bucket'
    operation_type: 'createBucket'
    public_read: true
    storage_class: 'infrequent'

执行成功后,OBS中会创建一个名为'new-bucket'、开放公共读权限,存储类型为低频访问存储的桶

删除桶用法

删除桶操作默认会自动清空桶内所有对象和碎片,若您不确定桶内是否有重要对象未备份,请设置参数'clear_bucker'为false

删除名为'new-bucket'的桶(自动清空桶内所有对象和碎片)

假设您的obs中存在名为'new-bucket'的桶

- name: Delete bucket on Huawei Cloud OBS
  uses: huaweicloud/obs-helper@v1.4.0
  with:
    bucket_name: 'new-bucket'
    operation_type: 'deleteBucket'

执行成功后,您在obs的桶'new-bucket'以及其中所有对象和碎片将被删除

Action中使用的公网地址说明

第三方开源包引入的公网地址

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

简介

基于华为云obs,实现文件及文件夹的上传和下载,以及桶的创建和删除功能。 展开 收起
TypeScript 等 4 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/HuaweiCloudDeveloper/obs-helper.git
git@gitee.com:HuaweiCloudDeveloper/obs-helper.git
HuaweiCloudDeveloper
obs-helper
obs-helper
master-dev

搜索帮助