#aliyun #sts #sdk #api #oss #api-client #id

aliyun-sts-rust-sdk

A tiny lib for aliyun sts api

3 releases

0.1.2 Nov 26, 2024
0.1.1 Oct 15, 2024
0.1.0 Sep 5, 2024

#1736 in Web programming

Download history 166/week @ 2024-09-02 4/week @ 2024-09-09 6/week @ 2024-09-16 3/week @ 2024-09-23 6/week @ 2024-09-30 198/week @ 2024-10-14 1/week @ 2024-10-21 9/week @ 2024-11-04 5/week @ 2024-11-18 137/week @ 2024-11-25

151 downloads per month

MIT/Apache

24KB
438 lines

阿里云 STS SDK

实现了 AssumeRole API 的调用,生成一对临时的访问 ID 和访问密钥,可以让前端利用 ali oss 库上传比较大的文件。

使用比较简单:

async fn test_assume_role() {
    simple_logger::init_with_level(log::Level::Debug).unwrap();
    dotenv::dotenv().ok();

    let aid = dotenv::var("ACCESS_KEY_ID").unwrap();
    let asec = dotenv::var("ACCESS_KEY_SECRET").unwrap();
    let arn = dotenv::var("ARN").unwrap();
    let role_session_name = "aliyun-sts-rust-sdk";

    let policy = Policy {
        version: Versions::V1,
        statement: vec![
            StatementBlock {
                action: StringOrArray::ArrayValue(vec!["oss:*".to_owned()]),
                effect: Effects::Allow,
                resource: StringOrArray::ArrayValue(vec!["acs:oss:*:*:mi-dev-public/yuanyq-test/file-from-rust.zip".to_owned()]),
                condition: None,
            }
        ]
    };

    let req = AssumeRoleRequest::new(&arn, role_session_name, Some(policy), 3600);
    let client = StsClient::new("sts.aliyuncs.com", &aid, &asec);

    match client.assume_role(req).await {
        Ok(r) => {
            assert!(r.credentials.is_some());
        },
        Err(e) => println!("{:?}", e)
    }
}

或者,调用便捷的函数:sts_for_put_object:

client.sts_for_put_object(&arn, "mi-dev-public", "yuanyq-test/file-from-rust.zip", 3600)

Dependencies

~6–21MB
~232K SLoC