Skip to content

Commit d0b6a63

Browse files
committed
Allocator template environment set
1 parent af26215 commit d0b6a63

File tree

5 files changed

+11
-61
lines changed

5 files changed

+11
-61
lines changed

.github/workflows/deploy_to_prod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
"GH_PRIVATE_KEY": "${{secrets.GH_PRIVATE_KEY}}",
5353
"GITHUB_APP_ID": "${{vars.GH_APP_ID}}",
5454
"GITHUB_INSTALLATION_ID": "${{vars.GH_INSTALLATION_ID}}",
55-
"FILPLUS_ENV": "prod",
55+
"FILPLUS_ENV": "production",
5656
"RUST_LOG": "debug",
5757
"BOT_USER": "${{vars.BOT_USER}}",
5858
"BACKEND_URL": "${{vars.BACKEND_URL}}",

.github/workflows/deploy_to_staging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
"DB_URL": "${{secrets.DB_URL}}",
7171
"GITHUB_APP_ID": "${{vars.GH_APP_ID}}",
7272
"GITHUB_INSTALLATION_ID": "${{vars.GH_INSTALLATION_ID}}",
73-
"FILPLUS_ENV": "prod",
73+
"FILPLUS_ENV": "staging",
7474
"RUST_LOG": "debug",
7575
"BOT_USER": "${{vars.BOT_USER}}",
7676
"BACKEND_URL": "${{vars.BACKEND_URL}}",

fplus-lib/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn default_env_vars() -> &'static HashMap<&'static str, &'static str> {
1717
m.insert("ALLOCATOR_GOVERNANCE_OWNER", "fidlabs");
1818
m.insert("BOT_USER", "filplus-allocators-staging-bot[bot]");
1919
m.insert("BACKEND_URL", "https://fp-core.dp04sa0tdc6pk.us-east-1.cs.amazonlightsail.com");
20+
m.insert("FILPLUS_ENV", "staging");
2021

2122
m
2223
})

fplus-lib/src/core/allocator/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,17 @@ pub async fn is_allocator_repo_created(owner: &str, repo: &str) -> Result<bool,
9494
pub async fn create_allocator_repo(owner: &str, repo: &str) -> Result<(), LDNError> {
9595
let gh = github_async_new(owner.to_string(), repo.to_string()).await;
9696
let mut dirs = Vec::new();
97-
let backend_url = get_env_var_or_default("BACKEND_URL");
98-
gh.create_or_update_secret("BACKEND_URL", &backend_url).await.map_err(|e| {
99-
LDNError::Load(format!("Failed to create or update secret in GitHub. Reason: {}", e))
100-
})?;
97+
let branch = match get_env_var_or_default("FILPLUS_ENV").as_str() {
98+
"staging" => "staging",
99+
"production" => "main",
100+
_ => "main",
101+
};
102+
101103
dirs.push("".to_string());
102104

103105
while dirs.len() > 0 {
104106
let dir = dirs.pop().unwrap();
105-
let files_list = gh.get_files_from_public_repo("clriesco", "filplus-allocator-template", Some(&dir)).await.map_err(|e| {
107+
let files_list = gh.get_files_from_public_repo("fidlabs", "allocator-template", branch, Some(&dir)).await.map_err(|e| {
106108
LDNError::Load(format!("Failed to retrieve all files from GitHub. Reason: {}", e))
107109
})?;
108110

fplus-lib/src/external_services/github.rs

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,9 @@ impl GithubWrapper {
721721
&self,
722722
owner: &str,
723723
repo: &str,
724+
branch: &str,
724725
path: Option<&str>
725726
) -> Result<ContentItems, OctocrabError> {
726-
let branch = "main";
727727
let octocrab = Octocrab::builder().build()?;
728728
let gh = octocrab.repos(owner, repo);
729729

@@ -735,57 +735,4 @@ impl GithubWrapper {
735735

736736
Ok(contents_items)
737737
}
738-
739-
/**
740-
* Create or update a secret in the repository
741-
* This function will receive the secret name and value and will create or update the secret in the repository
742-
* The secret value will be encrypted using the public key of the repository, as required by the GitHub API
743-
* More information here: https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-a-repository-secret
744-
*/
745-
pub async fn create_or_update_secret(
746-
&self,
747-
secret_name: &str,
748-
secret_value: &str,
749-
) -> Result<(), OctocrabError> {
750-
let pk = self
751-
.inner
752-
.repos(&self.owner, &self.repo)
753-
.secrets()
754-
.get_public_key()
755-
.await?;
756-
757-
let pk_bytes = match decode(pk.key) {
758-
Ok(bytes) => bytes,
759-
Err(e) => {
760-
log::error!("Failed to decode public key: {:?}", e);
761-
return Ok(());
762-
}
763-
};
764-
assert_eq!(pk_bytes.len(), sodium::crypto_box_PUBLICKEYBYTES as usize, "Invalid public key length");
765-
//Create a buffer to store the encrypted secret
766-
let mut encrypted_secret = vec![0u8; sodium::crypto_box_SEALBYTES as usize + secret_value.len()];
767-
//Encrypt the secret using the public key
768-
let _encrypt_res = unsafe {
769-
sodium::crypto_box_seal(
770-
encrypted_secret.as_mut_ptr(),
771-
secret_value.as_ptr(),
772-
secret_value.len() as u64,
773-
pk_bytes.as_ptr(),
774-
)
775-
};
776-
//Encode the encrypted secret to base64
777-
let encrypted_secret_base64 = encode(&encrypted_secret);
778-
779-
//Encrypt using libsodium
780-
let _create_secret_res = self
781-
.inner
782-
.repos(&self.owner, &self.repo)
783-
.secrets()
784-
.create_or_update_secret(secret_name, &CreateRepositorySecret{
785-
key_id: &pk.key_id,
786-
encrypted_value: &encrypted_secret_base64,
787-
})
788-
.await?;
789-
Ok(())
790-
}
791738
}

0 commit comments

Comments
 (0)