aboutsummaryrefslogtreecommitdiff
path: root/crates/secd/src/client/spice
diff options
context:
space:
mode:
authorbenj <benj@rse8.com>2023-05-22 15:47:06 -0700
committerbenj <benj@rse8.com>2023-05-22 15:47:06 -0700
commited34a5251f13bbded0aa15719887db4924b351eb (patch)
tree9719d805e915f4483d5db3e5e612e8b4cf5c702c /crates/secd/src/client/spice
parenteb92f823c31a5e702af7005231f0d6915aad3342 (diff)
downloadsecdiam-ed34a5251f13bbded0aa15719887db4924b351eb.tar
secdiam-ed34a5251f13bbded0aa15719887db4924b351eb.tar.gz
secdiam-ed34a5251f13bbded0aa15719887db4924b351eb.tar.bz2
secdiam-ed34a5251f13bbded0aa15719887db4924b351eb.tar.lz
secdiam-ed34a5251f13bbded0aa15719887db4924b351eb.tar.xz
secdiam-ed34a5251f13bbded0aa15719887db4924b351eb.tar.zst
secdiam-ed34a5251f13bbded0aa15719887db4924b351eb.zip
update credential API to include sessions
This change updates the credential API to include sessions as just another credential type. It adds the ApiToken type and enables revocation of credentials. Updates were also made to the Identity API which now includes a list of new credentials added to an Identity. This change also migrates off the hacky ENV configuration paradigm and includes a new config.toml file specified by the SECD_CONFIG_PATH env var. No default is currently provided. Clippy updates and code cleanup.
Diffstat (limited to '')
-rw-r--r--crates/secd/src/client/spice/mod.rs21
1 files changed, 8 insertions, 13 deletions
diff --git a/crates/secd/src/client/spice/mod.rs b/crates/secd/src/client/spice/mod.rs
index d3ca30d..67965d7 100644
--- a/crates/secd/src/client/spice/mod.rs
+++ b/crates/secd/src/client/spice/mod.rs
@@ -3,6 +3,7 @@
// favor of a light weight solution that leverages the Zanzibar API but disregards the
// scaling part.
+#[allow(clippy::module_inception)]
pub mod spice {
tonic::include_proto!("authzed.api.v1");
}
@@ -10,7 +11,7 @@ pub mod spice {
use spice::permissions_service_client::PermissionsServiceClient;
use spice::schema_service_client::SchemaServiceClient;
use spice::WriteSchemaRequest;
-use std::env::var;
+use std::matches;
use tonic::metadata::MetadataValue;
use tonic::transport::Channel;
use tonic::{Request, Status};
@@ -19,7 +20,6 @@ use crate::auth::z::{self, Subject};
use crate::client::spice::spice::{
relationship_update, ObjectReference, Relationship, RelationshipUpdate, SubjectReference,
};
-use crate::{ENV_SPICE_SECRET, ENV_SPICE_SERVER};
use self::spice::check_permission_response::Permissionship;
use self::spice::{consistency, CheckPermissionRequest, Consistency, WriteRelationshipsRequest};
@@ -36,12 +36,7 @@ pub(crate) struct Spice {
}
impl Spice {
- pub async fn new() -> Self {
- let secret =
- var(ENV_SPICE_SECRET).expect("initialization error: Failed to find SPICE_SECRET");
- let server =
- var(ENV_SPICE_SERVER).expect("initialization error: Failed to find SPICE_SERVER");
-
+ pub async fn new(secret: String, server: String) -> Self {
let channel = Channel::from_shared(server)
.expect("invalid SPICE_SERVER uri")
.connect()
@@ -69,10 +64,10 @@ impl Spice {
let response = client.check_permission(request).await?.into_inner();
- Ok(match Permissionship::from_i32(response.permissionship) {
- Some(Permissionship::HasPermission) => true,
- _ => false,
- })
+ Ok(matches!(
+ Permissionship::from_i32(response.permissionship),
+ Some(Permissionship::HasPermission)
+ ))
}
pub async fn write_relationship(&self, rs: &[z::Relationship]) -> Result<(), SpiceError> {
@@ -83,7 +78,7 @@ impl Spice {
let request = tonic::Request::new(WriteRelationshipsRequest {
updates: rs
- .into_iter()
+ .iter()
.map(|t| RelationshipUpdate {
operation: (relationship_update::Operation::Touch as i32),
relationship: Some(Relationship {