#!/usr/bin/env python3  
# -*- coding: utf-8 -*-  
"""
@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
@AUTHOR: ASJRD018
@NAME: AnsjerFormal
@software: PyCharm
@DATE: 2018/11/8 9:23
@Version: python3.6
@MODIFY DECORD:ansjer dev
@file: oss_sts.py
@Contact: chanjunkai@163.com
"""
# -*- coding: utf-8 -*-
'''
生成sts上传授权
'''
from aliyunsdkcore import client
from aliyunsdksts.request.v20150401 import AssumeRoleRequest
import json
import oss2
import base64

'''
http://test.dvema.com/cloudVod/getSts?uidToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjaGFubmVsIjoiNCIsInVpZCI6IkZUU0xMOEhNNDM3WjM4V1UxMTFBIn0.wkrwYvIYf5qEukOSTxALSAgSqop-gNBdEvSwScOgYB8
'''
endpoint = 'oss-cn-shenzhen.aliyuncs.com'
bucket_name = 'cnvod1'

tokenss ={
    'AccessKeySecret': '7kWzxVezTBs5Qd3AArRAcuXiYaQoLYVUnLb14iuv5LWW',
    'AccessKeyId': 'STS.NU3npZw8fkd7sSeFFrehxRmud',
    'Expiration': '2019-12-16T04:40:40Z',
    'SecurityToken': 'CAIS3AJ1q6Ft5B2yfSjIr5aGJcrumudH3KbccXXUokYnaedUvajehjz2IHFIf3NhAe0bv/kzm2lX7/YYlqduSpMcHhaYNJErss0NqltYtGpBI4nng4YfgbiJREJJYnyShb0WCoeUZdfZfejXOjKgvyRvwLz8WCy/Vli+S/OggoJmadJlF2vdaiFdVu9LOixoqsIRKRmpMu22YDLnhmfMAW1iuAd3lRkti8KFz9ab9wDVgXDj1+YRvP6RGJW/aNR2N5oNJbXB1edtJK3ay3wSuVoY/6NxkaBa/jue+c2QGEUWoW/CUYv16vRjIBV0fbNAf6dPt6rHkuBiseHyj/aOqXEUZ7kTCX+AAtn9n42dSL+LTo9oLe+gZy6Sg4rTasep6l8eDChFZF8QSb0IMWRtDBEgcDbeJ5K89UrCCgXZEPnZi/tniccongi0ooPVfgjVWduCzT0fIYQsyci1stvWBQcagAFYkAuSbf8lQF1U2ifn3hKAD3S5+CVRyluQoYJBnel5o1MsL6gzccGXwBC0Jpuux/tzOZBETh0DqA+BrfYsPEUdHyZ9O5wVAHym8gx9TYiZNYNkd9FXev1k5i9pOMoy+DzaF90gZBiiZv9AYhlw8k8WGo+0InLNdI8F4CcjA1oYBQ=='
  }
# 使用RAM账号的AccessKeyId和AccessKeySecret向STS申请临时token。

# 使用临时token中的认证信息初始化StsAuth实例。
auth = oss2.StsAuth(tokenss['AccessKeyId'],
                    tokenss['AccessKeySecret'],
                    tokenss['SecurityToken'])
bucket = oss2.Bucket(auth, endpoint, bucket_name)
result = bucket.append_object('mio', 0, 'content of first append')
print(result)