-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from Oxen-AI/feat/config_user
Feat/config user
- Loading branch information
Showing
11 changed files
with
163 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
from .oxen import auth | ||
from .oxen import auth, util | ||
from typing import Optional | ||
|
||
|
||
def create_user_config(name: str, email: str, path: Optional[str] = None): | ||
if path is None: | ||
path = f"{auth.get_oxen_home_dir()}/user_config.toml" | ||
if not path.endswith(".toml"): | ||
raise ValueError("Path must end with .toml") | ||
auth.create_user_config(name, email, path) | ||
|
||
|
||
def add_host_auth(host: str, token: str, path: Optional[str] = None): | ||
def config_auth(host: str, token: str, path: Optional[str] = None): | ||
if path is None: | ||
path = f"{auth.get_oxen_home_dir()}/user_config.toml" | ||
path = f"{util.get_oxen_config_dir()}/user_config.toml" | ||
if not path.endswith(".toml"): | ||
raise ValueError("Path must end with .toml") | ||
auth.add_host_auth(host, token, path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from .oxen import user, util | ||
from typing import Optional | ||
|
||
def config_user(name: str, email: str, path: Optional[str] = None): | ||
if path is None: | ||
path = f"{util.get_oxen_config_dir()}/user_config.toml" | ||
if not path.endswith(".toml"): | ||
raise ValueError(f"Path {path} must end with .toml") | ||
return user.config_user(name, email, path) | ||
|
||
def current_user(path: Optional[str] = None): | ||
if path is None: | ||
path = f"{util.get_oxen_config_dir()}/user_config.toml" | ||
if not path.endswith(".toml"): | ||
raise ValueError(f"Path {path} must end with .toml") | ||
return user.current_user(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use pyo3::prelude::*; | ||
|
||
use liboxen::model::diff::generic_diff::GenericDiff; | ||
|
||
#[pyclass] | ||
pub struct PyDiff { | ||
pub diff: GenericDiff, | ||
} | ||
|
||
#[pymethods] | ||
impl PyDiff { | ||
fn __repr__(&self) -> String { | ||
format!("PyDiff(type={})", self.get_type()) | ||
} | ||
|
||
#[getter] | ||
pub fn get_type(&self) -> String { | ||
match &self.diff { | ||
GenericDiff::DirDiff(_diff) => { | ||
"dir".to_string() | ||
}, | ||
GenericDiff::TabularDiff(_diff) => { | ||
"tabular".to_string() | ||
}, | ||
// GenericDiff::TextDiff(_diff) => { | ||
// "text".to_string() | ||
// }, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use liboxen::model::User; | ||
use pyo3::prelude::*; | ||
|
||
#[pyclass] | ||
pub struct PyUser { | ||
_user: User, | ||
} | ||
|
||
#[pymethods] | ||
impl PyUser { | ||
#[new] | ||
#[pyo3(signature = (name, email))] | ||
pub fn new(name: String, email: String) -> Self { | ||
Self { | ||
_user: User { | ||
name, | ||
}, | ||
} | ||
} | ||
|
||
#[getter] | ||
pub fn name(&self) -> &str { | ||
&self._user.name | ||
} | ||
|
||
#[getter] | ||
pub fn email(&self) -> &str { | ||
&self._user.email | ||
} | ||
|
||
fn __repr__(&self) -> String { | ||
format!("PyUser(name='{}', email={})", self._user.name, self._user.email) | ||
} | ||
|
||
fn __str__(&self) -> String { | ||
format!("{}", self._user.name) | ||
} | ||
} | ||
|
||
impl From<User> for PyUser { | ||
fn from(user: User) -> PyUser { | ||
PyUser { _user: user } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//! Oxen User Functions | ||
//! | ||
use crate::error::PyOxenError; | ||
use crate::py_user::PyUser; | ||
use liboxen::config::user_config::UserConfig; | ||
use liboxen::model::User; | ||
use pyo3::prelude::*; | ||
use std::path::Path; | ||
|
||
#[pyfunction] | ||
pub fn config_user(name: String, email: String, path: String) -> Result<PyUser, PyOxenError> { | ||
let final_path = Path::new(&path); | ||
let user = User { name, email }; | ||
let config = UserConfig::from_user(&user); | ||
config.save(final_path)?; | ||
Ok(user.into()) | ||
} | ||
|
||
#[pyfunction] | ||
pub fn current_user(path: String) -> Result<PyUser, PyOxenError> { | ||
let path = Path::new(&path); | ||
let config = UserConfig::new(&path); | ||
Ok(config.to_user().into()) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters