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

add authentication to autoreload, get rid of warning, add replica log… #1750

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 0 additions & 3 deletions src/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { getCandidAndCanisterMethods } from './get_candid_and_canister_methods';
import { getCanisterJavaScript } from './get_canister_javascript';
import { getNamesAfterCli, getNamesBeforeCli } from './get_names';
import { handleCli } from './handle_cli';
import { logAutoreloadWarning } from './log_auto_reload_warning';
import { prepareDockerImage } from './prepare_docker_image';
import { prepareRustStagingArea } from './prepare_rust_staging_area';
import { logSuccess, time, unwrap } from './utils';
Expand Down Expand Up @@ -128,8 +127,6 @@ async function azle() {
);

logSuccess(canisterName, canisterId, replicaWebServerPort);

logAutoreloadWarning();
}

function createAzleDirectories() {
Expand Down
14 changes: 0 additions & 14 deletions src/compiler/log_auto_reload_warning.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/compiler/rust/canister_methods/src/hash_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn get_hash_file() -> proc_macro2::TokenStream {
hash_file_by_parts(&path, 0)
}

#[ic_cdk_macros::query(guard = is_authenticated)]
#[ic_cdk_macros::query(guard = guard_against_non_controllers)]
pub fn get_file_hash(path: String) -> Option<String> {
Some(
load_hashes()
Expand All @@ -19,7 +19,7 @@ pub fn get_hash_file() -> proc_macro2::TokenStream {
)
}

#[ic_cdk_macros::query(guard = is_authenticated)]
#[ic_cdk_macros::query(guard = guard_against_non_controllers)]
pub fn get_hash_status(path: String) -> Option<(u64, u64)> {
Some((get_bytes_hashed(&path), get_file_size(&path)?))
}
Expand Down
6 changes: 2 additions & 4 deletions src/compiler/rust/canister_methods/src/reload_js.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use quote::quote;

// TODO there is no authentication on this method
// TODO it is up to the developer to not deploy with this function
// TODO in the binary if they are worried about it
pub fn get_reload_js(env_vars: &Vec<(String, String)>) -> proc_macro2::TokenStream {
let azle_autoreload_env_var = env_vars.iter().find(|(key, _)| key == "AZLE_AUTORELOAD");

if let Some((_, value)) = azle_autoreload_env_var {
if value == "true" {
return quote! {
#[ic_cdk_macros::update]
#[ic_cdk_macros::update(guard = guard_against_non_controllers)]
fn reload_js(timestamp: u64, chunk_number: u64, js_bytes: Vec<u8>, total_len: u64) {
RELOADED_JS_TIMESTAMP.with(|reloaded_js_timestamp| {
let mut reloaded_js_timestamp_mut = reloaded_js_timestamp.borrow_mut();
Expand All @@ -33,6 +30,7 @@ pub fn get_reload_js(env_vars: &Vec<(String, String)>) -> proc_macro2::TokenStre
if reloaded_js_complete_bytes.len() as u64 == total_len {
let js_string = String::from_utf8_lossy(&reloaded_js_complete_bytes);
initialize_js(&js_string, false);
ic_cdk::println!("Azle: Reloaded canister JavaScript");
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn get_upload_file_chunk() -> proc_macro2::TokenStream {
#check_if_latest_version_src
#hash_file_src

#[ic_cdk_macros::update(guard = is_authenticated)]
#[ic_cdk_macros::update(guard = guard_against_non_controllers)]
pub fn upload_file_chunk(
dest_path: String,
timestamp: u64,
Expand Down Expand Up @@ -46,11 +46,11 @@ pub fn get_upload_file_chunk() -> proc_macro2::TokenStream {
}
}

pub fn is_authenticated() -> Result<(), String> {
pub fn guard_against_non_controllers() -> Result<(), String> {
if ic_cdk::api::is_controller(&ic_cdk::api::caller()) {
return Ok(());
}
return Err("Not Authorized: must be a controller to call this method".to_string());
return Err("Not Authorized: only controllers of this canister may call this method".to_string());
}

pub fn start_hash(dest_path: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn get_check_if_latest_version_src() -> proc_macro2::TokenStream {
})
}

#[ic_cdk_macros::update(guard = is_authenticated)]
#[ic_cdk_macros::update(guard = guard_against_non_controllers)]
pub fn clear_file_and_info(path: String) {
reset_for_new_upload(&path, 0).unwrap()
}
Expand Down
Loading