Skip to content

Commit

Permalink
Environment Variable Configuration (#2)
Browse files Browse the repository at this point in the history
## Problem

Some parameters should be definable via environment variables, but this
is not yet handled.

## Solution

Added support for providing API key, controller host, and additional
request headers through environment variables.

## Type of Change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] Infrastructure change (CI configs, etc)
- [ ] Non-code change (docs, etc)
- [ ] None of the above: (explain here)

## Test Plan

Test cases are written in `src/pinecone.rs`.
  • Loading branch information
emily-emily authored Jun 6, 2024
1 parent 9656202 commit 5aa32ed
Show file tree
Hide file tree
Showing 7 changed files with 452 additions and 15 deletions.
108 changes: 108 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pinecone_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ edition = "2021"
[dependencies]
openapi = { path = "../openapi" }
tokio = { version = "1", features = ["full"] }
mockito = "0.30"
regex = "1.10.4"
serde_json = "1.0.117"
snafu = "0.8.3"

[dev-dependencies]
mockito = "0.30"
serial_test = "3.1.1"
4 changes: 4 additions & 0 deletions pinecone_sdk/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::collections::HashMap;

#[derive(Debug, Clone)]
pub struct Config {
pub api_key: String,
pub controller_url: String,
pub additional_headers: HashMap<String, String>,
pub source_tag: Option<String>,
}

Expand All @@ -10,6 +13,7 @@ impl Config {
Config {
api_key,
controller_url: "https://api.pinecone.io".to_string(),
additional_headers: HashMap::new(),
source_tag,
}
}
Expand Down
15 changes: 7 additions & 8 deletions pinecone_sdk/src/control/list_indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ impl Pinecone {
#[cfg(test)]
mod tests {
use super::*;
use mockito::mock;
use tokio;
use crate::control::list_indexes::models::index_model::Metric;
use crate::config::Config;

Check warning on line 18 in pinecone_sdk/src/control/list_indexes.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused import: `crate::config::Config`
use openapi::models::IndexList;
use openapi::apis::configuration::Configuration;
use crate::control::list_indexes::models::index_model::Metric;
use mockito::mock;
use openapi::apis::configuration::ApiKey;

Check warning on line 21 in pinecone_sdk/src/control/list_indexes.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused import: `openapi::apis::configuration::ApiKey`
use openapi::apis::configuration::Configuration;

Check warning on line 22 in pinecone_sdk/src/control/list_indexes.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, stable)

unused import: `openapi::apis::configuration::Configuration`
use openapi::models::IndexList;
use openapi::models::IndexModel;


use tokio;

#[tokio::test]
async fn test_list_indexes() {
Expand Down Expand Up @@ -66,7 +64,8 @@ mod tests {

// Construct Pinecone instance with the mock server URL
let api_key = "test_api_key".to_string();
let pinecone = Pinecone::new(api_key, Some(mockito::server_url()), None);
let pinecone = Pinecone::new(Some(api_key), Some(mockito::server_url()), None, None)
.expect("Failed to create Pinecone instance");

// Call list_indexes and verify the result
let result = pinecone.list_indexes().await;
Expand Down
Loading

0 comments on commit 5aa32ed

Please sign in to comment.