笔记—华为OBS存储API调用
1 获取AK和SK
购买后从官网获取
略
2 计算鉴权签名
采用在请求头headers中携带签名的方式
Java和Python的计算方式:https://support.huaweicloud.com/api-obs/obs_04_0010.html#section1
Ruby的计算方式:
# @@UserName 桶名
# @@AccessKeyId AK
# @@SecretAccessKey SK
require 'base64'
require "uri"
require "net/http"
# 构建请求头鉴权签名
def self.get_signature(method, content_type='')
date = DateTime.now.httpdate
canonical_string = method + "\n" + "\n" + content_type + "\n" + date + "\n" + "/"
digest = OpenSSL::Digest.new('sha1')
signature = Base64.encode64(OpenSSL::HMAC.digest(digest, @@SecretAccessKey, canonical_string))
authorization = "OBS " + @@AccessKeyId + ":" + signature.to_s.strip
{
authorization: authorization, date: date}
end
3 发送请求
3.1 获取桶列表
get请求
require "uri"
require 'rexml/document'
require 'active_support/core_ext/hash'
# 获取桶列表
url = URI("http://obs.*******.huaweihaiercloud.com/")
http = Net