Skip to content

Commit

Permalink
fix: claims
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato committed Apr 18, 2024
1 parent 786c880 commit df42680
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
18 changes: 9 additions & 9 deletions lib/claims/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,13 @@ pub mod ent {
}

#[derive(Clone, Debug)]
pub struct Server {}
pub struct ProvisionedServer {}

impl TryFrom<&schema::entitlement::Server> for Server {
impl TryFrom<&schema::entitlement::ProvisionedServer> for ProvisionedServer {
type Error = GlobalError;

fn try_from(_value: &schema::entitlement::Server) -> GlobalResult<Self> {
Ok(Server {})
fn try_from(_value: &schema::entitlement::ProvisionedServer) -> GlobalResult<Self> {
Ok(ProvisionedServer {})
}
}
}
Expand All @@ -367,7 +367,7 @@ pub trait ClaimsDecode {
fn as_cloud_device_link(&self) -> GlobalResult<ent::CloudDeviceLink>;
fn as_bypass(&self) -> GlobalResult<ent::Bypass>;
fn as_access_token(&self) -> GlobalResult<ent::AccessToken>;
fn as_server(&self) -> GlobalResult<ent::Server>;
fn as_provisioned_server(&self) -> GlobalResult<ent::ProvisionedServer>;
}

impl ClaimsDecode for schema::Claims {
Expand Down Expand Up @@ -618,16 +618,16 @@ impl ClaimsDecode for schema::Claims {
.and_then(std::convert::identity)
}

fn as_server(&self) -> GlobalResult<ent::Server> {
fn as_provisioned_server(&self) -> GlobalResult<ent::ProvisionedServer> {
self.entitlements
.iter()
.find_map(|ent| match &ent.kind {
Some(schema::entitlement::Kind::Server(ent)) => Some(ent::Server::try_from(ent)),
Some(schema::entitlement::Kind::ProvisionedServer(ent)) => Some(ent::ProvisionedServer::try_from(ent)),
_ => None,
})
.ok_or(err_code!(
CLAIMS_MISSING_ENTITLEMENT,
entitlement = "Server"
entitlement = "ProvisionedServer"
))
.and_then(std::convert::identity)
}
Expand Down Expand Up @@ -673,7 +673,7 @@ impl EntitlementTag for schema::Entitlement {
schema::entitlement::Kind::CloudDeviceLink(_) => 14,
schema::entitlement::Kind::Bypass(_) => 15,
schema::entitlement::Kind::AccessToken(_) => 16,
schema::entitlement::Kind::Server(_) => 17,
schema::entitlement::Kind::ProvisionedServer(_) => 17,
})
}
}
Expand Down
7 changes: 4 additions & 3 deletions proto/claims.proto
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ message Entitlement {
string name = 1;
}

// Issued to provisioned servers for communication with our API.
message Server {
// Issued to provisioned servers for communication with our API. This will be written to prebake servers
// (see /docs/packages/cluster/SERVER_PROVISIONING.md).
message ProvisionedServer {

}

Expand All @@ -128,7 +129,7 @@ message Entitlement {
CloudDeviceLink cloud_device_link = 14;
Bypass bypass = 15;
AccessToken access_token = 16;
Server server = 17;
ProvisionedServer provisioned_server = 17;
}

reserved 13;
Expand Down
4 changes: 2 additions & 2 deletions svc/api/provision/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Auth {
.ok_or_else(|| err_code!(API_UNAUTHORIZED, reason = "No bearer token provided."))
}

pub fn server(&self) -> GlobalResult<rivet_claims::ent::Server> {
self.claims()?.as_server()
pub fn server(&self) -> GlobalResult<rivet_claims::ent::ProvisionedServer> {
self.claims()?.as_provisioned_server()
}
}
4 changes: 3 additions & 1 deletion svc/pkg/cluster/worker/src/workers/server_install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ async fn worker(ctx: &OperationContext<cluster::msg::server_install::Message>) -
entitlements: vec![
proto::claims::Entitlement {
kind: Some(
proto::claims::entitlement::Kind::Server(proto::claims::entitlement::Server { })
proto::claims::entitlement::Kind::ProvisionedServer(
proto::claims::entitlement::ProvisionedServer {}
)
)
}
],
Expand Down

0 comments on commit df42680

Please sign in to comment.