项目作者: CarlosLanderas

项目描述 :
Azure App Configuration Rust client
高级语言: Rust
项目地址: git://github.com/CarlosLanderas/azure-app-configuration.git
创建时间: 2019-09-09T14:19:01Z
项目社区:https://github.com/CarlosLanderas/azure-app-configuration

开源协议:

下载


Azure App Configuration client for Rust

Build Status
License
Cargo
Documentation

With azure-app-configuration you can easily work with your Azure App Configuration service centralized configurations.

Latest version supports:

  • List keys
  • List labels
  • List key values
  • Get key value
  • Set key value (with label, tags and content type)
  • Remove key value

Running samples

You can find some sample code snippets here: examples.

Just replace the configuration with your Azure configuration endpoint, your access_key and secret and execute them by using:

cargo run --example list-key-values

cargo run --example get_key_value

cargo run --example set_key_value

You can see all available targets in Cargo.toml file

Code samples

Create an AzureAppConfiguration client

To create an Azure App Configuration client just use ::new method and provide the endpoint url, the access key and the secret:

  1. use azure_app_configuration::client::AzureAppConfigClient;
  2. let app_config_client = AzureAppConfigClient::new(
  3. "https://endpoint.azconfig.io",
  4. "0-l9-s0:Z6DMwn2DoiK2gVsTIm7h",
  5. "wgf9BDWeh/+Dtq8Dmps3SUpwrdgYLrXG8svE+VyM06w=",
  6. );

List keys

  1. //List all key values without a label (all key values);
  2. let keys = app_config_client.list_keys().await.unwrap();
  3. for k in keys.items {
  4. println!("{:?}", k);
  5. }

List labels

  1. let labels = app_config_client.list_labels().await.unwrap();
  2. for l in labels.items {
  3. println!("{:?}", l);
  4. }

List Key Values

  1. let key_values = app_config_client.list_key_values(SearchLabel::All).await;
  2. for k in key_values {
  3. println!("{:?}", k);
  4. }

Get Key value with label

Retrieve value for key ConnectionString using label ContosoApp

  1. let kv = app_config_client
  2. .get_key_value("ConnectionString", SearchLabel::For("ContosoApp"))
  3. .await;
  4. println!("{:?}", kv);

Get Key value without label

Retrieve a label called ConnectionString with no label specified

  1. let kv = app_config_client
  2. .get_key_value("ConnectionString", SearchLabel::All)
  3. .await;
  4. println!("{:?}", kv);

Set key value

Delete ConnectionString key for Application1 label

  1. let kv = app_config_client
  2. .set_key(
  3. "ConnectionString",
  4. "Server=dummy;user id=user;password=fakepass",
  5. SearchLabel::For("Application1"),
  6. None,
  7. None,
  8. )
  9. .await;
  10. println!("{:?}", kv);

Set key value with tags and content type

  1. let mut tags = HashMap::new();
  2. tags.insert("tag1", "tagvalue1");
  3. tags.insert("tag2", "tagvalue2");
  4. let kv = app_config_client
  5. .set_key(
  6. "UseCache",
  7. "true",
  8. SearchLabel::For("PublicWebsite"),
  9. Some(tags),
  10. Some("application/lande"),
  11. )
  12. .await;
  13. println!("{:?}", kv);