use azure_core::prelude::*;
use azure_storage::blob::prelude::*;
use azure_storage::core::prelude::*;
use chrono::{Duration, Utc};
use std::error::Error;

fn main() {
    env_logger::init();
    code().unwrap();
}

fn code() -> Result<(), Box<dyn Error>> {
    // First we retrieve the account name and master key from environment variables.
    let account =
        std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!");
    let master_key =
        std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!");

    let container_name = std::env::args()
        .nth(1)
        .expect("please specify container name as command line parameter");
    let blob_name = std::env::args()
        .nth(2)
        .expect("please specify blob name as command line parameter");

    let client = client::with_access_key(&account, &master_key);

    let now = Utc::now();
    let later = now + Duration::hours(1);
    let sas = client
        .shared_access_signature()
        .with_resource(SasResource::Blob)
        .with_resource_type(SasResourceType::Object)
        .with_start(now)
        .with_expiry(later)
        .with_permissions(SasPermissions::Read)
        .with_protocol(SasProtocol::HttpHttps)
        .finalize();
    println!("token: '{}'", sas.token());

    let url = client
        .generate_signed_blob_url()
        .with_container_name(&container_name)
        .with_blob_name(&blob_name)
        .with_shared_access_signature(&sas)
        .finalize();
    println!("url: '{}'", url);

    Ok(())
}

{'avg_line_length': 30.941176470588236, 'max_line_length': 97, 'alphanum_fraction': 0.6343472750316856, 'licenses': ['MIT'], 'repository_name': 'Alexei-B/azure-sdk-for-rust', 'path': 'sdk/storage/examples/shared_access_signature.rs', 'size': 1578, 'lang': 'Rust'}