-
Notifications
You must be signed in to change notification settings - Fork 55
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 #3196 from rina23q/feature/3036/support-basic-auth…
…-for-c8y feat: support SmartREST1.0 for Cumulocity
- Loading branch information
Showing
27 changed files
with
815 additions
and
174 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
59 changes: 59 additions & 0 deletions
59
crates/common/tedge_config/src/tedge_config_cli/models/auth_method.rs
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,59 @@ | ||
use camino::Utf8Path; | ||
use std::str::FromStr; | ||
use strum_macros::Display; | ||
|
||
#[derive( | ||
Debug, Display, Clone, Copy, Eq, PartialEq, doku::Document, serde::Serialize, serde::Deserialize, | ||
)] | ||
#[serde(rename_all = "kebab-case")] | ||
#[strum(serialize_all = "kebab-case")] | ||
pub enum AuthMethod { | ||
Certificate, | ||
Basic, | ||
Auto, | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
#[error("Failed to parse flag: {input}. Supported values are: 'certificate', 'basic' or 'auto'")] | ||
pub struct InvalidRegistrationMode { | ||
input: String, | ||
} | ||
|
||
impl FromStr for AuthMethod { | ||
type Err = InvalidRegistrationMode; | ||
|
||
fn from_str(input: &str) -> Result<Self, Self::Err> { | ||
match input { | ||
"certificate" => Ok(AuthMethod::Certificate), | ||
"basic" => Ok(AuthMethod::Basic), | ||
"auto" => Ok(AuthMethod::Auto), | ||
_ => Err(InvalidRegistrationMode { | ||
input: input.to_string(), | ||
}), | ||
} | ||
} | ||
} | ||
|
||
pub enum AuthType { | ||
Certificate, | ||
Basic, | ||
} | ||
|
||
impl AuthMethod { | ||
pub fn is_basic(self, credentials_path: &Utf8Path) -> bool { | ||
matches!(self.to_type(credentials_path), AuthType::Basic) | ||
} | ||
|
||
pub fn is_certificate(self, credentials_path: &Utf8Path) -> bool { | ||
matches!(self.to_type(credentials_path), AuthType::Certificate) | ||
} | ||
|
||
pub fn to_type(self, credentials_path: &Utf8Path) -> AuthType { | ||
match self { | ||
AuthMethod::Certificate => AuthType::Certificate, | ||
AuthMethod::Basic => AuthType::Basic, | ||
AuthMethod::Auto if credentials_path.exists() => AuthType::Basic, | ||
AuthMethod::Auto => AuthType::Certificate, | ||
} | ||
} | ||
} |
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,4 +1,5 @@ | ||
pub mod apt_config; | ||
pub mod auth_method; | ||
pub mod auto; | ||
pub mod c8y_software_management; | ||
pub mod connect_url; | ||
|
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
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
Oops, something went wrong.