Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: claims #672

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading