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

feat: add service tokens #636

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 19 additions & 0 deletions docs/infrastructure/fern/GENERATING.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote my own docs for this in the script file parallel to this being written:

# To install fern, first clone the repo and check out the branch
# $ git clone https://github.com/rivet-gg/fern
# $ cd fern
# $ git checkout max/remove-headers
#
# Then, follow the instructions in SETUP.md and CONTRIBUTING.md to compile fern
# $ yarn
# $ yarn compile
# $ yarn dist:cli:dev
#
# Finally, run this with the path to the fern repo, say:
# $ FERN_REPO_PATH=~/fern ./oss/scripts/fern/gen.sh

I think we can remove mine, it makes more sense to go here. I'm going to make some other requests for things that could be a bit better in the writeup based on mine.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generating

## Step 1: Cloud & build Fern

```sh
gh repo clone rivet-gg/fern
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we instead use git here? I think people will be less familiar with gh, and potentially not know what the command would do.

Suggested change
gh repo clone rivet-gg/fern
git clone https://github.com/rivet-gg/fern

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my version, I said to check out max/remove-headers. Is that now included in trunk?

cd fern
yarn install
yarn husky install
yarn dist:cli:dev
Comment on lines +8 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have yarn compile right before yarn dist:cli:dev, is it needed?

```

## Step 2: Generate

In the Rivet repo:

```
FERN_REPO_PATH=/path/to/fern ./scripts/fern/gen.sh
```
26 changes: 26 additions & 0 deletions fern/definition/cloud/games/namespaces/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ service:
type: uuid
response: CreateGameNamespaceTokenPublicResponse

createGameNamespaceTokenService:
path: /games/{game_id}/namespaces/{namespace_id}/tokens/service
method: POST
docs: Creates a service token for the given namespace.
path-parameters:
game_id:
type: uuid
namespace_id:
type: uuid
request:
body: CreateGameNamespaceTokenServiceRequest
response: CreateGameNamespaceTokenServiceResponse

updateGameNamespaceVersion:
path: /games/{game_id}/namespaces/{namespace_id}/version
method: PUT
Expand Down Expand Up @@ -373,6 +386,19 @@ types:
JSON.
type: string

CreateGameNamespaceTokenServiceRequest:
properties:
ttl: integer

CreateGameNamespaceTokenServiceResponse:
properties:
token:
docs: |-
A JSON Web Token.
Slightly modified to include a description prefix and use Protobufs of
JSON.
type: string

UpdateGameNamespaceVersionRequest:
properties:
version_id:
Expand Down
33 changes: 33 additions & 0 deletions lib/claims/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,21 @@ pub mod ent {
Ok(ProvisionedServer {})
}
}

#[derive(Clone, Debug)]
pub struct GameNamespaceService {
pub namespace_id: Uuid,
}

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

fn try_from(value: &schema::entitlement::GameNamespaceService) -> GlobalResult<Self> {
Ok(GameNamespaceService {
namespace_id: unwrap!(value.namespace_id).as_uuid(),
})
}
}
}

pub trait ClaimsDecode {
Expand All @@ -368,6 +383,7 @@ pub trait ClaimsDecode {
fn as_bypass(&self) -> GlobalResult<ent::Bypass>;
fn as_access_token(&self) -> GlobalResult<ent::AccessToken>;
fn as_provisioned_server(&self) -> GlobalResult<ent::ProvisionedServer>;
fn as_game_namespace_service(&self) -> GlobalResult<ent::GameNamespaceService>;
}

impl ClaimsDecode for schema::Claims {
Expand Down Expand Up @@ -647,6 +663,22 @@ impl ClaimsDecode for schema::Claims {
))
.and_then(std::convert::identity)
}

fn as_game_namespace_service(&self) -> GlobalResult<ent::GameNamespaceService> {
self.entitlements
.iter()
.find_map(|ent| match &ent.kind {
Some(schema::entitlement::Kind::GameNamespaceService(ent)) => {
Some(ent::GameNamespaceService::try_from(ent))
}
_ => None,
})
.ok_or(err_code!(
CLAIMS_MISSING_ENTITLEMENT,
entitlements = "GameNamespaceService"
))
.and_then(std::convert::identity)
}
}

pub trait EntitlementTag {
Expand Down Expand Up @@ -674,6 +706,7 @@ impl EntitlementTag for schema::Entitlement {
schema::entitlement::Kind::Bypass(_) => 15,
schema::entitlement::Kind::AccessToken(_) => 16,
schema::entitlement::Kind::ProvisionedServer(_) => 17,
schema::entitlement::Kind::GameNamespaceService(_) => 18,
})
}
}
Expand Down
8 changes: 7 additions & 1 deletion proto/claims.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ message Entitlement {
rivet.common.Uuid run_id = 1;
}

// Manage a game's cloud status.
// Manage a game's cloud resources.
message GameCloud {
rivet.common.Uuid game_id = 1;
}
Expand Down Expand Up @@ -110,7 +110,12 @@ message Entitlement {
// 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 {

}

// Token used to access Rivet via an API backend.
message GameNamespaceService {
rivet.common.Uuid namespace_id = 1;
}

oneof kind {
Expand All @@ -130,6 +135,7 @@ message Entitlement {
Bypass bypass = 15;
AccessToken access_token = 16;
ProvisionedServer provisioned_server = 17;
GameNamespaceService game_namespace_service = 18;
}

reserved 13;
Expand Down
79 changes: 79 additions & 0 deletions sdks/full/go/cloud/games/namespaces/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions sdks/full/go/cloud/games/namespaces/namespaces.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdks/full/go/provision/servers/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading