-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added API for adding credentials (#35)
Implemented POST and DELETE methods to allow credentials to be modified via HTTP. The GET method intentionally does not respond with the credential as there's never a reason inserted credentials should be readable after the initial insert. So as a additional security measure, the GET only determines if the credential exists or not.
- Loading branch information
Showing
16 changed files
with
401 additions
and
30 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,2 +1,4 @@ | ||
ignore: | ||
- integration | ||
- integration | ||
- src/credhelper/memory.rs | ||
- src/credhelper/faulty.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
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,31 @@ | ||
/// Implementation of the memory credential helper that always throws an error | ||
/// | ||
/// This is useful for testing the error handling of the credential helper | ||
use async_trait::async_trait; | ||
|
||
use super::{Credential, CredentialHelper}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub(crate) struct FaultyCredentials; | ||
|
||
impl FaultyCredentials { | ||
#[allow(dead_code)] | ||
pub(crate) fn new() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl CredentialHelper for FaultyCredentials { | ||
async fn get(&self, _hostname: impl AsRef<str> + Send) -> Result<Credential, anyhow::Error> { | ||
Err(anyhow::anyhow!("Error occurred")) | ||
} | ||
|
||
async fn store(&mut self, _hostname: String, _cred: String) -> Result<(), anyhow::Error> { | ||
Err(anyhow::anyhow!("Error occurred")) | ||
} | ||
|
||
async fn forget(&mut self, _hostname: impl AsRef<str> + Send) -> Result<(), anyhow::Error> { | ||
Err(anyhow::anyhow!("Error occurred")) | ||
} | ||
} |
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,4 +1,5 @@ | ||
pub mod database; | ||
pub mod faulty; | ||
pub mod memory; | ||
mod types; | ||
|
||
|
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,23 @@ | ||
use axum::{routing::post, Router}; | ||
|
||
use crate::credhelper::CredentialHelper; | ||
|
||
use self::v1::credential::{delete, exists, update}; | ||
|
||
pub(crate) mod v1; | ||
|
||
#[derive(Clone)] | ||
pub(crate) struct APIState<C> { | ||
pub(crate) credentials: C, | ||
} | ||
|
||
pub(crate) fn routes<S, C: Clone + Send + Sync + 'static + CredentialHelper>( | ||
state: APIState<C>, | ||
) -> Router<S> { | ||
Router::new() | ||
.route( | ||
"/api/v1/credentials/:hostname", | ||
post(update).delete(delete).get(exists), | ||
) | ||
.with_state(state) | ||
} |
Oops, something went wrong.