Skip to content

Commit

Permalink
feat(svc): add servers database
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelOnFira committed Jul 6, 2024
1 parent 60de313 commit a2c51b9
Show file tree
Hide file tree
Showing 158 changed files with 13,553 additions and 1,673 deletions.
9 changes: 9 additions & 0 deletions errors/servers/servers/servers_multiple_port_routers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name = "SERVERS_MULTIPLE_PORT_ROUTERS"
description = "Multiple server port routers were provided."
http_status = 400
---

# Multiple Server Port Routers

Multiple server port routers were provided.
9 changes: 9 additions & 0 deletions errors/servers/servers/servers_multiple_runtimes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name = "SERVERS_MULTIPLE_RUNTIMES"
description = "Multiple server runtimes were provided."
http_status = 400
---

# Multiple Server Runtimes

Multiple server runtimes were provided.
9 changes: 9 additions & 0 deletions errors/servers/servers/servers_no_port_routers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name = "SERVERS_NO_PORT_ROUTERS"
description = "No port routers were provided."
http_status = 400
---

# No Port Routers

No port routers were provided.
9 changes: 9 additions & 0 deletions errors/servers/servers/servers_no_runtime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name = "SERVERS_NO_RUNTIME"
description = "No server runtime were provided."
http_status = 400
---

# No Server Runtime

No server runtime were provided.
14 changes: 14 additions & 0 deletions fern/definition/cloud/games/tokens.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ service:
game_id:
type: uuid
response: CreateCloudTokenResponse
createServiceToken:
path: /games/{game_id}/tokens/service
method: POST
docs: Creates a new game service token.
path-parameters:
game_id:
type: uuid
response: CreateCloudTokenResponse

types:
CreateCloudTokenResponse:
Expand All @@ -22,3 +30,9 @@ types:
Slightly modified to include a description prefix and use Protobufs of
JSON.
type: string
CreateServiceTokenResponse:
properties:
token:
docs: |-
A JSON Web Token.
type: string
5 changes: 0 additions & 5 deletions fern/definition/servers/__package__.yml

This file was deleted.

69 changes: 49 additions & 20 deletions fern/definition/servers/common.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,78 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json

types:
Server:
properties:
server_id: uuid
game_id: uuid
datacenter_id: uuid
cluster_id: uuid
metadata: unknown
resources: Resources
kill_timeout:
docs: >-
The duration to wait for in milliseconds before killing the server.
This should be set to a safe default, and can be overridden during a
DELETE request if needed.
type: optional<long>
runtime: Runtime
create_ts: long
destroy_ts: optional<long>

Resources:
properties:
cpu:
docs: |
The number of CPU cores in millicores, or 1/1000 of a core. For example,
1/8 of a core would be 125 millicores, and 1 core would be 1000
millicores.
type: integer
memory:
docs: The amount of memory in megabytes
type: integer

Runtime:
properties:
docker: optional<DockerRuntime>

DockerRuntime:
properties:
image_id: string
args: list<string>
environment: map<string, string>
image_id: uuid
args: optional<list<string>>
environment: optional<map<string, string>>
network: DockerNetwork

DockerNetwork:
properties:
mode: DockerNetworkMode
mode: optional<DockerNetworkMode>
ports: map<string, DockerPort>

DockerNetworkMode:
enum:
- host
- bridge

GameGuardProtocol:
enum:
- http
- https
- tcp
- tcp_tls
- udp
- host

DockerPort:
properties:
port: optional<integer>
routing: DockerPortRouting

DockerPortRouting:
DockerPortRouting:
properties:
game_guard: optional<GameGuardProtocol>
game_guard: optional<DockerGameGuardRouting>
host: optional<DockerHostRouting>

DockerHostRouting:
DockerGameGuardRouting:
properties:
null: unknown
protocol: optional<GameGuardProtocol>

Server:
properties:
null: unknown
GameGuardProtocol:
enum:
- http
- https
- tcp
- tcp_tls
- udp

DockerHostRouting:
properties: {}
11 changes: 0 additions & 11 deletions fern/definition/servers/datacenters/__package__.yml

This file was deleted.

20 changes: 0 additions & 20 deletions fern/definition/servers/images/__package__.yml

This file was deleted.

59 changes: 59 additions & 0 deletions fern/definition/servers/servers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json

imports:
commons: common.yml

service:
auth: true
base-path: /servers/servers
endpoints:
create:
path: ""
method: POST
docs: Create a new dynamic server.
request:
body: CreateServerRequest
response: CreateServerResponse
destroy:
path: "/{server_id}"
method: DELETE
docs: Destroy a dynamic server.
path-parameters:
server_id:
docs: The id of the server to destroy
type: uuid
request:
name: DestroyServerRequest
query-parameters:
override_kill_timeout:
docs: >-
The duration to wait for in milliseconds before killing the server.
This should be used to override the default kill timeout if a faster
time is needed, say for ignoring a graceful shutdown.
type: optional<long>
response: DestroyServerResponse

types:
CreateServerRequest:
properties:
datacenter:
docs: The name ID of the datacenter
type: string
metadata: unknown
resources: commons.Resources
kill_timeout:
docs: >-
The duration to wait for in milliseconds before killing the server.
This should be set to a safe default, and can be overridden during a
DELETE request if needed.
type: optional<long>
runtime: commons.Runtime
CreateServerResponse:
properties:
server:
docs: The server that was created
type: commons.Server
DestroyServerResponse:
properties:
server_id:
type: uuid
52 changes: 0 additions & 52 deletions fern/definition/servers/servers/__package__.yml

This file was deleted.

33 changes: 33 additions & 0 deletions lib/claims/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,21 @@ pub mod ent {
})
}
}

#[derive(Clone, Debug)]
pub struct GameService {
pub game_id: Uuid,
}

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

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

pub trait ClaimsDecode {
Expand All @@ -388,6 +403,7 @@ pub trait ClaimsDecode {
fn as_access_token(&self) -> GlobalResult<ent::AccessToken>;
fn as_provisioned_server(&self) -> GlobalResult<ent::ProvisionedServer>;
fn as_opengb_db(&self) -> GlobalResult<ent::OpenGbDb>;
fn as_game_service(&self) -> GlobalResult<ent::GameService>;
}

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

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

pub trait EntitlementTag {
Expand Down Expand Up @@ -713,6 +745,7 @@ impl EntitlementTag for schema::Entitlement {
schema::entitlement::Kind::AccessToken(_) => 16,
schema::entitlement::Kind::ProvisionedServer(_) => 17,
schema::entitlement::Kind::OpengbDb(_) => 18,
schema::entitlement::Kind::GameService(_) => 19,
})
}
}
Expand Down
Loading

0 comments on commit a2c51b9

Please sign in to comment.