Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato committed Feb 23, 2024
1 parent a806eb2 commit d96a0b3
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 69 deletions.
54 changes: 29 additions & 25 deletions lib/bolt/core/src/context/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,18 +814,6 @@ impl ServiceContextData {
env.push(("RIVET_ORIGIN_API".into(), project_ctx.origin_api()));
env.push(("RIVET_ORIGIN_HUB".into(), project_ctx.origin_hub()));

// DNS
if let Some(dns) = &project_ctx.ns().dns {
if let Some(provider) = &dns.provider {
env.push((
"RIVET_DNS_PROVIDER".into(),
match provider {
config::ns::DnsProvider::Cloudflare { .. } => "cloudflare".into(),
},
));
}
}

// Pools
if !project_ctx.ns().pools.is_empty() {
env.push(("RIVET_HAS_POOLS".into(), "1".into()));
Expand All @@ -852,19 +840,28 @@ impl ServiceContextData {
));
}

if project_ctx.ns().dns.is_some() {
let dns = terraform::output::read_dns(&project_ctx).await;
// DNS
if let Some(dns) = &project_ctx.ns().dns {
match &dns.provider {
Some(config::ns::DnsProvider::Cloudflare { account_id, .. }) => {
env.push(("RIVET_DNS_PROVIDER".into(), "cloudflare".into()));
env.push(("CLOUDFLARE_ACCOUNT_ID".into(), account_id.clone()));
}
None => {}
}

let dns_output = terraform::output::read_dns(&project_ctx).await;
env.push((
"CLOUDFLARE_ZONE_ID_BASE".into(),
(*dns.cloudflare_zone_ids).main.clone(),
"CLOUDFLARE_ZONE_ID_MAIN".into(),
(*dns_output.cloudflare_zone_ids).main.clone(),
));
env.push((
"CLOUDFLARE_ZONE_ID_GAME".into(),
(*dns.cloudflare_zone_ids).cdn.clone(),
(*dns_output.cloudflare_zone_ids).cdn.clone(),
));
env.push((
"CLOUDFLARE_ZONE_ID_JOB".into(),
(*dns.cloudflare_zone_ids).job.clone(),
(*dns_output.cloudflare_zone_ids).job.clone(),
));
}

Expand Down Expand Up @@ -1204,13 +1201,20 @@ impl ServiceContextData {
}
}

if project_ctx.ns().dns.is_some() && self.depends_on_cloudflare() {
env.push((
"CLOUDFLARE_AUTH_TOKEN".into(),
project_ctx
.read_secret(&["cloudflare", "terraform", "auth_token"])
.await?,
));
if let Some(dns) = &project_ctx.ns().dns {
match &dns.provider {
Some(config::ns::DnsProvider::Cloudflare { .. }) => {
if self.depends_on_cloudflare() {
env.push((
"CLOUDFLARE_AUTH_TOKEN".into(),
project_ctx
.read_secret(&["cloudflare", "terraform", "auth_token"])
.await?,
));
}
}
None => {}
}
}

Ok(env)
Expand Down
5 changes: 1 addition & 4 deletions lib/bolt/core/src/dep/terraform/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ pub async fn init_if_needed_quiet(ctx: &ProjectContext, plan_id: &str, quiet: bo
.read_secret(&["terraform", "pg_backend", "conn_str"])
.await
.unwrap();
vec![
format!("-backend-config=conn_str={tf_conn_str}"),
"-reconfigure".to_string(),
]
vec![format!("-backend-config=conn_str={tf_conn_str}")]
}
};

Expand Down
21 changes: 10 additions & 11 deletions lib/bolt/core/src/dep/terraform/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,13 @@ pub async fn project(ctx: &ProjectContext) {
pub async fn gen_bolt_tf(ctx: &ProjectContext, plan_id: &str) -> Result<()> {
// Configure the backend
let backend = match ctx.ns().terraform.backend {
ns::TerraformBackend::Local {} => indoc!(
r#"
terraform {
backend "local" {}
}
"#
)
.to_string(),
ns::TerraformBackend::Local {} => String::new(),
ns::TerraformBackend::Postgres {} => indoc!(
r#"
"
terraform {
backend "pg" {}
backend \"pg\" {}
}
"#
"
)
.to_string(),
};
Expand Down Expand Up @@ -325,6 +318,12 @@ async fn vars(ctx: &ProjectContext) {
"name": domain_main_api,
}));

// OGS
extra_dns.push(json!({
"zone_name": "main",
"name": format!("*.ogs.{domain_main}"),
}));

// Add services
for svc_ctx in all_svc {
if let Some(router) = svc_ctx.config().kind.router() {
Expand Down
15 changes: 13 additions & 2 deletions lib/util/env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ pub mod cloudflare {

lazy_static::lazy_static! {
static ref CLOUDFLARE_AUTH_TOKEN: Option<String> = std::env::var("CLOUDFLARE_AUTH_TOKEN").ok();
static ref CLOUDFLARE_ACCOUNT_ID: Option<String> = std::env::var("CLOUDFLARE_ACCOUNT_ID").ok();
}

pub fn auth_token() -> &'static str {
Expand All @@ -194,10 +195,20 @@ pub mod cloudflare {
}
}

pub fn account_id() -> &'static str {
match &*CLOUDFLARE_ACCOUNT_ID {
Some(x) => x.as_str(),
None => panic!(
"{}",
EnvVarError::Missing("CLOUDFLARE_ACCOUNT_ID".to_string())
),
}
}

pub mod zone {
pub mod base {
pub mod main {
lazy_static::lazy_static! {
static ref ID: Option<String> = std::env::var("CLOUDFLARE_ZONE_ID_BASE").ok();
static ref ID: Option<String> = std::env::var("CLOUDFLARE_ZONE_ID_MAIN").ok();
}

pub fn id() -> Option<&'static str> {
Expand Down
11 changes: 11 additions & 0 deletions svc/pkg/cf-custom-hostname/worker/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
pub mod workers;

#[derive(Debug, Deserialize)]
struct CloudflareError {
errors: Vec<CloudflareErrorEntry>,
}

#[derive(Debug, Deserialize)]
struct CloudflareErrorEntry {
code: usize,
message: String,
}
13 changes: 2 additions & 11 deletions svc/pkg/cf-custom-hostname/worker/src/workers/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use proto::backend::{self, pkg::*};
use serde::Deserialize;
use serde_json::json;

use crate::CloudflareError;

#[derive(Debug, Deserialize)]
struct CloudflareResponse {
result: CloudflareResult,
Expand All @@ -20,17 +22,6 @@ struct CloudflareOwnershipVerificationHttp {
http_body: Uuid,
}

#[derive(Debug, Deserialize)]
struct CloudflareError {
errors: Vec<CloudflareErrorEntry>,
}

#[derive(Debug, Deserialize)]
struct CloudflareErrorEntry {
code: usize,
// message: String,
}

/// Send a lobby create fail message and cleanup the lobby if needed.
#[tracing::instrument]
async fn fail(
Expand Down
11 changes: 1 addition & 10 deletions svc/pkg/cf-custom-hostname/worker/src/workers/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@ use chirp_worker::prelude::*;
use proto::backend::pkg::*;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct CloudflareError {
errors: Vec<CloudflareErrorEntry>,
}

#[derive(Debug, Deserialize)]
struct CloudflareErrorEntry {
code: usize,
// message: String,
}
use crate::CloudflareError;

#[worker(name = "cf-custom-hostname-delete")]
async fn worker(
Expand Down
6 changes: 0 additions & 6 deletions svc/pkg/mm/util/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ pub async fn verify_config(
);
}
}
_ => {
bail_with!(
MATCHMAKER_CUSTOM_LOBBY_CONFIG_INVALID,
reason = "given publicity not allowed"
);
}
}

// Verify lobby count
Expand Down

0 comments on commit d96a0b3

Please sign in to comment.