cf-services

Crates.iocf-services
lib.rscf-services
version0.1.1
sourcesrc
created_at2021-11-16 00:29:12.961834
updated_at2021-11-16 00:34:10.38081
descriptionClient library for Cloud Foundry.
homepagehttps://github.com/Piszmog/cf-services
repositoryhttps://github.com/Piszmog/cf-services.git
max_upload_size
id482418
size16,392
Piszmog (Piszmog)

documentation

https://github.com/Piszmog/cf-services

README

CF Services

crates.io Rust License: MIT

This library is aimed at removing the boilerplate code and let developers just worry about using actually connecting to the services they have bounded to their app.

Retrieving VCAP_SERVICES

Simply use cf_services::get_services_from_env().

use cf_services::get_services_from_env;

fn main() {
    let services = get_services_from_env().unwrap();
    let service = services.get("serviceA").unwrap();
    // Use information about service A to perform actions (such as creating an OAuth2 Client)
}

Retrieving Credentials of a Service

Call cf_services::get_service_credentials(..) by passing the VCAP_SERVICES marshalled JSON and the name of the service to retrieve the credentials for. If VCAP_SERVICES is guaranteed to be an environment variable use cf_services::get_service_cred_from_env(..) instead.

use cf_services::{get_services_from_env, get_service_credentials, get_service_cred_from_env};

fn main() {
    let services = get_services_from_env().unwrap();
    let creds = get_service_credentials(services, "serviceB").unwrap();
    // Use credentials...

    // Retrieve the JSON from the environment
    let creds = get_service_cred_from_env("serviceB").unwrap();
    // Use credentials...
}
Commit count: 23

cargo fmt