Skip to content

Commit

Permalink
fix: migrate old state env variable to new env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Nov 18, 2023
1 parent b9dc8b6 commit e9a3b15
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
27 changes: 4 additions & 23 deletions backend/windmill-common/src/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,6 @@ pub async fn get_reserved_variables(
step_id: Option<String>,
) -> [ContextualVariable; 15] {
let state_path = {
let flow_path = flow_path
.clone()
.unwrap_or_else(|| "NO_FLOW_PATH".to_string());
let script_path = path.clone().unwrap_or_else(|| "NO_JOB_PATH".to_string());
let schedule_path = schedule_path
.clone()
.map(|x| format!("/{x}"))
.unwrap_or_else(String::new);

let script_path = if script_path.ends_with("/") {
"NO_NAME".to_string()
} else {
script_path
};

format!("{permissioned_as}/{flow_path}/{script_path}{schedule_path}")
};

let state_path_2 = {
let trigger = if schedule_path.is_some() {
username.to_string()
} else {
Expand Down Expand Up @@ -200,13 +181,13 @@ pub async fn get_reserved_variables(
},
ContextualVariable {
name: "WM_STATE_PATH".to_string(),
value: state_path,
description: "State resource path unique to a script and its trigger (legacy, in a migration period against WM_STATE_PATH_NEW)".to_string(),
value: state_path.clone(),
description: "State resource path unique to a script and its trigger".to_string(),
},
ContextualVariable {
name: "WM_STATE_PATH_NEW".to_string(),
value: state_path_2,
description: "State resource path unique to a script and its trigger".to_string(),
value: state_path,
description: "State resource path unique to a script and its trigger (legacy)".to_string(),
},
ContextualVariable {
name: "WM_FLOW_STEP_ID".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion deno-client/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function resolveDefaultResource(obj: any): Promise<any> {
}

export function getStatePath(): string {
const state_path = Deno.env.get("WM_STATE_PATH_NEW");
const state_path = Deno.env.get("WM_STATE_PATH_NEW") ?? Deno.env.get("WM_STATE_PATH");
if (state_path === undefined) {
throw Error("State path not set");
}
Expand Down
6 changes: 5 additions & 1 deletion go-client/windmill.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ func SetVariable(path string, value string) error {
}

func GetStatePath() string {
return os.Getenv("WM_STATE_PATH_NEW")
value := os.Getenv("WM_STATE_PATH_NEW")
if len(value) == 0 {
return os.Getenv("WM_STATE_PATH")
}
return value
}

func GetState() (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion typescript-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export async function resolveDefaultResource(obj: any): Promise<any> {
}

export function getStatePath(): string {
const state_path = getEnv("WM_STATE_PATH_NEW");
const state_path = getEnv("WM_STATE_PATH_NEW") ?? getEnv("WM_STATE_PATH");
if (state_path === undefined) {
throw Error("State path not set");
}
Expand Down

0 comments on commit e9a3b15

Please sign in to comment.