#cf #cloudfoundry #cf-for-k8s #cloud-foundry

cf-env

Crate to parse Cloud Foundry environment variables with types and checks. Get you off that boilerplate code and care about what you actually need to code

7 releases

Uses new Rust 2021

0.1.8 Aug 3, 2022
0.1.7 Jul 21, 2022
0.1.6 Feb 18, 2022
0.1.4 Jan 11, 2022
0.1.3 Dec 9, 2021

#48 in Configuration

Download history 30/week @ 2022-04-24 18/week @ 2022-05-01 32/week @ 2022-05-08 101/week @ 2022-05-15 27/week @ 2022-05-22 45/week @ 2022-05-29 28/week @ 2022-06-05 3/week @ 2022-06-12 4/week @ 2022-06-19 1/week @ 2022-06-26 14/week @ 2022-07-03 14/week @ 2022-07-10 27/week @ 2022-07-17 21/week @ 2022-07-24 40/week @ 2022-07-31 6/week @ 2022-08-07

94 downloads per month

MIT/Apache

43KB
1K SLoC

Cloud Foundry Environment

codecov Crates.io

Open in Gitpod

A small library to get you going in no time with typed environment variables for you Cloud Foundry envirnoment.

Goals:

  • Remove boilerplate code for projects using cf
  • Use the power of rust to get the environment variables in a typed way
  • Give you the flexiblity to define custom values such as credential structures to meet your needs

Usage

Getting this crate is easy as adding it to your dependencies

[dependencies]
cf-env = "0.1.7"

After that, just check what you need and get it, you may wanna check out the docs.rs page. For example CF_INSTANCE_INDEX

let instance_index = cf_env::get_instance_index().unwrap();

Or for example if you need to get some credentials:

use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct CustomCredentials {
    pub password: String,
    pub username: String,
    pub host: String,
    pub port: u16,
}

// After that you can use it
let service = cf_env::get_service_by_name::<CustomCredentials>("my_db").unwrap();

There is no need for typed credentials if you would like to parse it anyway and then deal with the Value enum from serde_json

use serde_json::Value;
use cf_env::Service;

let service: Service<Value> = cf_env::get_service_by_name("my_db").unwrap();

let uri = service.credentials["uri"].as_str().unwrap();

Dependencies

~3.5–4.5MB
~103K SLoC