Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
chore: return backend project on bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Jul 22, 2024
1 parent de1cf11 commit 1f58474
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 10 deletions.
42 changes: 36 additions & 6 deletions rivet-toolchain/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,47 @@ pub async fn spawn_opengb_command(opts: OpenGbCommandOpts) -> GlobalResult<u32>

/// Gets or auto-creates a backend project for the game.
pub async fn get_or_create_project(ctx: &Ctx) -> GlobalResult<Box<models::EeBackendProject>> {
// Get the project
let project_res = apis::ee_cloud_games_projects_api::ee_cloud_games_projects_get(
&ctx.openapi_config_cloud,
&ctx.game_id,
)
.await?;

// TODO: Add get or create project
let project = unwrap!(
project_res.project,
"No OpenGB project linked to the current game. Create one on the hub: https://hub.rivet.gg/"
);
if let Some(project) = project_res.project {
Ok(project)
} else {
// Get game in order to determine team & project name
let models::CloudGamesGetGameByIdResponse { game, .. } =
apis::cloud_games_api::cloud_games_get_game_by_id(
&ctx.openapi_config_cloud,
&ctx.game_id,
None,
)
.await?;

Ok(project)
// Create project
let display_name = format!("{:.15}-backend", game.display_name);
let models::EeCloudBackendProjectsCreateResponse { project, .. } =
apis::ee_cloud_backend_projects_api::ee_cloud_backend_projects_create(
&ctx.openapi_config_cloud,
models::EeCloudBackendProjectsCreateRequest {
developer_group_id: game.developer_group_id,
display_name,
},
)
.await?;

// Link to game
apis::ee_cloud_games_projects_api::ee_cloud_games_projects_link(
&ctx.openapi_config_cloud,
&ctx.game_id,
models::EeCloudGamesProjectsLinkRequest {
project_id: project.project_id,
},
)
.await?;

Ok(project)
}
}
19 changes: 18 additions & 1 deletion rivet-toolchain/src/tasks/get_bootstrap_data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use global_error::prelude::*;
use rivet_api::{apis, models};
use serde::{Deserialize, Serialize};

use crate::util::task::TaskCtx;
use crate::{backend, util::task::TaskCtx};

#[derive(Deserialize)]
pub struct Input {}
Expand All @@ -11,6 +12,8 @@ pub struct Output {
pub token: String,
pub api_endpoint: String,
pub game_id: String,
pub backend_project: models::EeBackendProject,
pub backend_environments: Vec<models::EeBackendEnvironment>,
}

pub struct Task;
Expand All @@ -25,10 +28,24 @@ impl super::Task for Task {

async fn run(_task: TaskCtx, _input: Self::Input) -> GlobalResult<Self::Output> {
let ctx = crate::ctx::load().await?;

// Get or create backend project
let backend_project = backend::get_or_create_project(&ctx).await?;
let backend_environments =
apis::ee_cloud_backend_projects_envs_api::ee_cloud_backend_projects_envs_list(
&ctx.openapi_config_cloud,
&backend_project.project_id.to_string(),
None,
)
.await?
.environments;

Ok(Output {
token: ctx.access_token.clone(),
api_endpoint: ctx.api_endpoint.clone(),
game_id: ctx.game_id.clone(),
backend_project: *backend_project,
backend_environments,
})
}
}
3 changes: 2 additions & 1 deletion scripts/copy_sdks.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
set -euf

mkdir -p ./sdks/rust
rm -rf ./sdks/rust
cp -r ../rivet-ee/sdks/full/rust ./sdks
cp -r $EE_REPO_PATH/sdks/full/rust ./sdks
1 change: 1 addition & 0 deletions sdks/rust/docs/EeBackendEnvironment.md

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

1 change: 1 addition & 0 deletions sdks/rust/docs/EeCloudBackendProjectsCreateResponse.md

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

5 changes: 4 additions & 1 deletion sdks/rust/src/models/ee_backend_environment.rs

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

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

0 comments on commit 1f58474

Please sign in to comment.