Skip to content

Commit 4c35f09

Browse files
authored
Feature/fix user creds (#60)
* fix auth
1 parent 7101d48 commit 4c35f09

6 files changed

Lines changed: 28 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.2.1] - 2024-07-30
9+
10+
* fix password based auth
11+
812
## [1.2.0] - 2024-07-27
913

1014
* move authentication to rust layer

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyfusion"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
edition = "2021"
55

66

py_src/fusion/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
__author__ = """Fusion Devs"""
44
__email__ = "fusion_developers@jpmorgan.com"
5-
__version__ = "1.2.0"
5+
__version__ = "1.2.1"
66

77
from fusion._fusion import FusionCredentials
88
from fusion.fs_sync import fsync

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pyfusion"
3-
version = "1.2.0"
3+
version = "1.2.1"
44

55
homepage = "https://github.com/jpmorganchase/fusion"
66
description = "JPMC Fusion Developer Tools"
@@ -222,7 +222,7 @@ omit = [
222222

223223

224224
[tool.bumpversion]
225-
current_version = "1.2.0"
225+
current_version = "1.2.1"
226226
parse = '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(?:-(?P<release>[a-z]+)(?P<candidate>\d+))?'
227227
serialize = [
228228
'{major}.{minor}.{patch}-{release}{candidate}',

src/auth.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,35 +102,35 @@ fn find_cfg_file(file_path: &Path) -> PyResult<PathBuf> {
102102
);
103103
return Ok(current_path);
104104
}
105-
106105
let cwd = env::current_dir()?;
107-
108106
let cfg_file_name = "client_credentials.json";
109-
let mut start_dir = match file_path.parent() {
107+
let cfg_folder_name = "config";
108+
let start_dir = match current_path.parent() {
110109
Some(parent) => match parent.exists() {
111110
true => parent.to_path_buf(),
112111
false => cwd,
113112
},
114113
None => cwd,
115114
};
116-
let start_dir_init = start_dir.clone();
117-
115+
let mut start_dir_abs = start_dir.canonicalize()?;
116+
let start_dir_init = start_dir_abs.clone();
118117
loop {
119-
let full_path = start_dir.join(cfg_file_name);
118+
let full_path = start_dir_abs.join(cfg_folder_name).join(cfg_file_name);
120119
if full_path.is_file() {
121120
debug!("Found file at: {}", full_path.display());
122121
return Ok(full_path);
123122
}
124123

125124
// Move to the parent directory
126-
if let Some(parent) = start_dir.parent() {
127-
start_dir = parent.to_path_buf();
125+
if let Some(parent) = start_dir_abs.parent() {
126+
start_dir_abs = parent.to_path_buf().canonicalize()?;
128127
} else {
129128
// Reached the root directory
130129
let error_message = format!(
131-
"File {} not found in {} or any of its parents",
130+
"File {} not found in {} or any of its parents. Current parent: {}",
132131
cfg_file_name,
133-
start_dir_init.display()
132+
start_dir_init.display(),
133+
start_dir.display()
134134
);
135135
return Err(PyFileNotFoundError::new_err(error_message));
136136
}
@@ -781,16 +781,17 @@ impl FusionCredentials {
781781
.client_id
782782
.or_else(|| std::env::var("FUSION_CLIENT_ID").ok())
783783
.ok_or_else(|| CredentialError::new_err("Missing client ID"))?;
784-
let client_secret = credentials
785-
.client_secret
786-
.or_else(|| std::env::var("FUSION_CLIENT_SECRET").ok())
787-
.ok_or_else(|| CredentialError::new_err("Missing client secret"))?;
788784

789785
let full_creds = match credentials.grant_type.as_str() {
790786
"client_credentials" => FusionCredentials::from_client_id(
791787
cls,
792788
Some(client_id),
793-
Some(client_secret),
789+
Some(
790+
credentials
791+
.client_secret
792+
.or_else(|| std::env::var("FUSION_CLIENT_SECRET").ok())
793+
.ok_or_else(|| CredentialError::new_err("Missing client secret"))?,
794+
),
794795
credentials.resource,
795796
credentials.auth_url,
796797
Some(untyped_proxies(credentials.proxies)),
@@ -886,11 +887,13 @@ mod tests {
886887
let temp_dir = TempDir::new("test_find_cfg_file").unwrap();
887888
let parent_dir = temp_dir.path().join("parent");
888889
let child_dir = parent_dir.join("child");
890+
let dir_path = Path::new("config");
889891

890892
fs::create_dir_all(&child_dir).unwrap();
891-
let cfg_file_path = parent_dir.join("client_credentials.json");
893+
let cfg_file_path = parent_dir.join("config").join("client_credentials.json");
892894

893895
// Create the config file in the parent directory
896+
fs::create_dir_all(parent_dir.join(dir_path)).expect("Failed to create directory");
894897
let mut file = File::create(&cfg_file_path).unwrap();
895898
writeln!(file, "{{\"key\": \"value\"}}").unwrap();
896899

0 commit comments

Comments
 (0)