Skip to content

Commit

Permalink
Merge pull request #21 from Infisical/daniel/fixes
Browse files Browse the repository at this point in the history
(Fix): Python process hanging & schema issue, .NET attach to process env
  • Loading branch information
DanielHougaard authored Jan 24, 2024
2 parents f123e75 + 4c46f9b commit c84056c
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ InfisicalClient.egg-info

__pycache__
crates/infisical-py/infisical_client/schemas.py
crates/infisical-py/infisical_client/infisical_py.*.so
crates/infisical-py/infisical_client/infisical_py.*.dll


infisical_py.so
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"napi",
"openapi",
"openapitools",
"pyclass",
"pymethods",
"quicktype",
"reqwest",
"rngs"
Expand Down
3 changes: 2 additions & 1 deletion crates/infisical-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.20.0", features = ["extension-module"] }
pyo3-log = "0.9.0"
infisical-json = { path = "../infisical-json" }
env_logger = "0.10.1"
log = "0.4.20"

[build-dependencies]
pyo3-build-config = { version = "0.20.0" }
Expand Down
8 changes: 4 additions & 4 deletions crates/infisical-py/infisical_client/infisical_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
from .schemas import CreateSecretOptions, ResponseForCreateSecretResponse

from .schemas import EncryptSymmetricOptions, EncryptSymmetricResponse, ResponseForEncryptSymmetricResponse
from .schemas import DecryptSymmetricOptions, DecryptSymmetricResponse, ResponseForDecryptSymmetricResponse
from .schemas import DecryptSymmetricOptions, ResponseForDecryptSymmetricResponse

from .schemas import ArbitraryOptions, ResponseForCreateSymmetricKeyResponse

from .infisical_py import InfisicalClient as RustInfisicalClient
import os

class InfisicalClient:
def __init__(self, settings: ClientSettings = None):
def __init__(self, settings: ClientSettings = None, debug: bool = False):

if settings is None:
self.inner = RustInfisicalClient(None)
self.inner = RustInfisicalClient(settings, debug)
else:

settings.user_agent = "infisical-python-sdk"

settings_json = json.dumps(settings.to_dict())

self.inner = RustInfisicalClient(settings_json)
self.inner = RustInfisicalClient(settings_json, debug)

def _run_command(self, command: Command) -> Any:
response_json = self.inner.run_command(json.dumps(command.to_dict()))
Expand Down
Binary file not shown.
11 changes: 9 additions & 2 deletions crates/infisical-py/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
extern crate log;
use infisical_json::client::Client as JsonClient;
use pyo3::prelude::*;

Expand All @@ -7,8 +8,14 @@ pub struct InfisicalClient(JsonClient);
#[pymethods]
impl InfisicalClient {
#[new]
pub fn new(settings_string: Option<String>) -> Self {
pyo3_log::init();
pub fn new(settings_string: Option<String>, debug: Option<bool>) -> Self {
if debug.unwrap_or(false) == true {
// This will only fail if another logger was already initialized, so we can ignore the result
let _ = env_logger::Builder::from_default_env()
.filter_level(log::LevelFilter::Debug)
.try_init();
}

Self(JsonClient::new(settings_string))
}

Expand Down
3 changes: 2 additions & 1 deletion crates/infisical/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub struct Client {

impl Client {
pub fn new(settings_input: Option<ClientSettings>) -> Self {
let settings = settings_input.expect("Settings not found or were set improperly.");
// We should allow the user to not provide settings, so they can still use encryption methods that don't require authentication.
let settings = settings_input.unwrap_or(ClientSettings::default());

let c = Self {
auth: ClientAuth {
Expand Down
9 changes: 9 additions & 0 deletions languages/csharp/Infisical.Sdk/InfisicalClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public SecretElement[] ListSecrets(ListSecretsOptions options)

if (result is { Success: true })
{

if (options.AttachToProcessEnv == true)
{
foreach (var secret in result.Data.Secrets)
{
Environment.SetEnvironmentVariable(secret.SecretKey, secret.SecretValue);
}
}

return result.Data.Secrets;
}

Expand Down

0 comments on commit c84056c

Please sign in to comment.