Skip to content

Latest commit

 

History

History
95 lines (69 loc) · 2.76 KB

README.md

File metadata and controls

95 lines (69 loc) · 2.76 KB

oci-rust-sdk

Crates.io MIT licensed Rust codecov

Oracle Cloud Infrastructure SDK for Rust Lang

About

OCI-Rust-SDK is written to access the OCI API using async methods.

use oci_sdk::{
    config::AuthConfig,
    identity::Identity
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    // Set up auth config
    let auth_config = AuthConfig::from_file(
        Some("~/.oci/config".to_string()),
        Some("DEFAULT".to_string())
    );
    // Create a service client
    let identity = Identity::new(auth_config, None);
    //# Get the current user
    let response = identity.get_current_user().await?;
    // parse information
    let body = response.text().await?;

    println!("{}", body);
    // {
    //     "compartment_id": "ocid1.tenancy.oc1...",
    //     "description": "Test user",
    //     "id": "ocid1.user.oc1...",
    //     "inactive_status": null,
    //     "lifecycle_state": "ACTIVE",
    //     "name": "[email protected]",
    //     "time_created": "2016-08-30T23:46:44.680000+00:00"
    // }

    Ok(())}
}

Examples

You can look for the test folder for more examples.

Development

OCI-Emulator

We recommend you to use oci-emulator to develop new features and testing.

To do so, just run:

docker run -d --name oci-emulator -p 12000:12000 cameritelabs/oci-emulator:latest

You can then use the service_endpoint parameter available on every client to use it. For example:

let auth_config = AuthConfig::from_file(None, None);

Nosql::new(auth_config, Some("http://localhost:12000".to_string()));

Running Tests

We're using tarpaulin to generate code coverage. To use it, you'll need to install it using cargo:

cargo install tarpaulin

After installing it, you can build/test and generate the coverage simply using:

cargo tarpaulin --out Lcov

We're using Lcov format to upload the coverage to codecov. You can view the coverage on VSCode using Coverage Gutters.

If you don't want to generate coverage you can simply use:

cargo test