Crates.io | qiniu-credential |
lib.rs | qiniu-credential |
version | 0.2.4 |
source | src |
created_at | 2022-04-07 06:22:46.316841 |
updated_at | 2023-12-26 07:19:09.843643 |
description | Qiniu Credential SDK for Rust |
homepage | https://www.qiniu.com |
repository | https://github.com/qiniu/rust-sdk.git |
max_upload_size | |
id | 563477 |
size | 78,218 |
负责存储调用七牛 API 所必要的认证信息,提供 CredentialProvider
方便扩展获取认证信息的方式。
同时提供阻塞接口和异步接口(异步接口需要启用 async
功能)。
提供 CredentialProvider
的多个实现方式,例如:
GlobalCredentialProvider
使用全局变量配置的认证信息EnvCredentialProvider
使用环境变量配置的认证信息ChainCredentialsProvider
配置多个 CredentialProvider
形成认证信息串,遍历找寻第一个可用的认证信息[dependencies]
qiniu-credential = "0.2.1"
[dependencies]
qiniu-credential = { version = "0.2.1", features = ["async"] }
use qiniu_credential::{Credential, HeaderValue, prelude::*};
use mime::APPLICATION_WWW_FORM_URLENCODED;
use std::io::Cursor;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let authorization = credential
.get(Default::default())?
.authorization_v1_for_request_with_body_reader(
&"http://upload.qiniup.com/".parse()?,
Some(&HeaderValue::from_str(APPLICATION_WWW_FORM_URLENCODED.as_ref())?),
&mut Cursor::new(b"name=test&language=go"),
);
use qiniu_credential::{Credential, Method, HeaderMap, HeaderValue, prelude::*};
use http::header::CONTENT_TYPE;
use mime::APPLICATION_JSON;
use std::io::Cursor;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, HeaderValue::from_str(APPLICATION_JSON.as_ref())?);
let authorization = credential
.get(Default::default())?
.authorization_v2_for_request_with_body_reader(
&Method::GET,
&"http://upload.qiniup.com/".parse()?,
&headers,
&mut Cursor::new(b"{\"name\":\"test\"}"),
);
use qiniu_credential::{Credential, prelude::*};
use std::time::Duration;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let url = "http://www.qiniu.com/?go=1".parse()?;
let url = credential
.get(Default::default())?
.sign_download_url(url, Duration::from_secs(3600));
println!("{}", url);
use qiniu_credential::{Credential, HeaderValue, prelude::*};
use mime::APPLICATION_WWW_FORM_URLENCODED;
use std::io::Cursor;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let authorization = credential
.async_get(Default::default()).await?
.authorization_v1_for_request_with_async_body_reader(
&"http://upload.qiniup.com/".parse()?,
Some(&HeaderValue::from_str(APPLICATION_WWW_FORM_URLENCODED.as_ref())?),
&mut Cursor::new(b"name=test&language=go"),
).await?;
use qiniu_credential::{Credential, Method, HeaderMap, HeaderValue, prelude::*};
use http::header::CONTENT_TYPE;
use mime::APPLICATION_JSON;
use std::io::Cursor;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, HeaderValue::from_str(APPLICATION_JSON.as_ref())?);
let authorization = credential
.async_get(Default::default()).await?
.authorization_v2_for_request_with_async_body_reader(
&Method::GET,
&"http://upload.qiniup.com/".parse()?,
&headers,
&mut Cursor::new(b"{\"name\":\"test\"}"),
).await?;
1.70.0
This project is licensed under the MIT license.