-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoss1.py
More file actions
45 lines (40 loc) · 1.27 KB
/
oss1.py
File metadata and controls
45 lines (40 loc) · 1.27 KB
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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2020 ubuntu <ubuntu@VM-0-13-ubuntu>
#
# Distributed under terms of the MIT license.
"""
获取ossutil的权限
auth 登录信息
endpoint
bucket
bucket_status 当前bucket是否cunz
"""
import oss2
class Bucket():
__default_path = '/home/ubuntu/.ossutilconfig'
def __init__(self, bucket_name='wmsj100-python-test',config_path=''):
self.__config_path = config_path or self.__default_path
self.__auth = self.__read_conf()
self.auth = oss2.Auth(self.__auth['accessKeyID'], self.__auth['accessKeySecret'])
self.endpoint = self.__auth['endpoint']
self.bucket = oss2.Bucket(self.auth, self.endpoint, bucket_name)
self.bucket_status = self.__bucket_exist()
def __read_conf(self):
auth = dict()
with open(self.__config_path) as file:
for line in file.readlines():
if line.find('=') > -1:
[key, val] = line.split('=')
auth[key.strip()] = val.strip()
return auth
def __bucket_exist(self):
try:
self.bucket.get_bucket_info()
except oss2.exceptions.NoSuchBucket:
return False
except:
raise
return True