Skip to content

Commit

Permalink
Merge pull request #102 from astronomer/env
Browse files Browse the repository at this point in the history
Migrate Environment Variables
  • Loading branch information
fritz-astronomer authored May 23, 2024
2 parents cb97bbc + 192a95a commit 0d13beb
Show file tree
Hide file tree
Showing 6 changed files with 283 additions and 64 deletions.
39 changes: 35 additions & 4 deletions astronomer_starship/src/State.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const initialState = {
isProductSelected: false,
isTokenTouched: false,
token: null,
deploymentId: null,

// Software Specific:
releaseName: null,
workspaceId: null,

// ### VARIABLES PAGE ####
variablesLocalData: [],
variablesRemoteData: [],
Expand All @@ -51,6 +57,7 @@ export const initialState = {
envRemoteData: [],
envLoading: false,
envError: null,
organizationId: null,
// ### DAGS PAGE ####
dagsData: {},
dagsLoading: false,
Expand Down Expand Up @@ -79,15 +86,15 @@ export const reducer = (state, action) => {
urlDeploymentPart: action.urlDeploymentPart,
urlOrgPart: action.urlOrgPart,
isValidUrl: action.urlOrgPart && action.urlDeploymentPart,
isSetupComplete: action.urlOrgPart && action.urlDeploymentPart && state.token,
isSetupComplete: state.isStarship && state.isAirflow && state.token && action.urlOrgPart && action.urlDeploymentPart,
};
}
case 'set-token': {
return {
...state,
isTokenTouched: true,
token: action.token,
isSetupComplete: action.token && state.isValidUrl,
isSetupComplete: state.isStarship && state.isAirflow && action.token && state.isValidUrl,
};
}
case 'toggle-is-astro': {
Expand All @@ -96,17 +103,34 @@ export const reducer = (state, action) => {
isAstro: !state.isAstro,
isProductSelected: true,
targetUrl: getTargetUrlFromParts(state.urlOrgPart, state.urlDeploymentPart, !state.isAstro),
token: null,
isSetupComplete: false,
};
}
case 'set-is-product-selected': {
return { ...state, isProductSelected: true };
}
case 'set-is-starship': {
return { ...state, isStarship: action.isStarship };
return {
...state,
isStarship: action.isStarship,
isSetupComplete: action.isStarship && state.isAirflow && state.token && state.isValidUrl,
};
}
case 'set-is-airflow': {
return { ...state, isAirflow: action.isAirflow };
return {
...state,
isAirflow: action.isAirflow,
isSetupComplete: action.isAirflow && state.isStarship && state.token && state.isValidUrl,
};
}
case 'set-software-info': {
return {
...state,
releaseName: action.releaseName,
workspaceId: action.workspaceId,
deploymentId: action.deploymentId,
};
}

// ### VARIABLES PAGE ####
Expand All @@ -131,6 +155,7 @@ export const reducer = (state, action) => {
return action.error.response.status === 401 ? {
...state,
variablesError: action.error,
variablesLoading: false,
isSetupComplete: false,
isTokenTouched: false,
token: null,
Expand Down Expand Up @@ -159,6 +184,7 @@ export const reducer = (state, action) => {
return action.error.response.status === 401 ? {
...state,
connectionsError: action.error,
connectionsLoading: false,
isSetupComplete: false,
isTokenTouched: false,
token: null,
Expand Down Expand Up @@ -187,6 +213,7 @@ export const reducer = (state, action) => {
return action.error.response.status === 401 ? {
...state,
poolsError: action.error,
poolsLoading: false,
isSetupComplete: false,
isTokenTouched: false,
token: null,
Expand All @@ -208,13 +235,16 @@ export const reducer = (state, action) => {
...state,
envLocalData: action.envLocalData,
envRemoteData: action.envRemoteData,
organizationId: action.envRemoteData['ASTRO_ORGANIZATION_ID'] || state.organizationId,
deploymentId: action.envRemoteData['ASTRO_DEPLOYMENT_ID'] || state.deploymentId,
envLoading: false,
};
}
case 'set-env-error': {
return action.error.response.status === 401 ? {
...state,
envError: action.error,
envLoading: false,
isSetupComplete: false,
isTokenTouched: false,
token: null,
Expand All @@ -241,6 +271,7 @@ export const reducer = (state, action) => {
return action.error.response.status === 401 ? {
...state,
dagsError: action.error,
dagsLoading: false,
isSetupComplete: false,
isTokenTouched: false,
token: null,
Expand Down
28 changes: 22 additions & 6 deletions astronomer_starship/src/component/ValidatedUrlCheckbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@ export default function ValidatedUrlCheckbox({
useEffect(() => {
// noinspection JSCheckFunctionSignatures
axios.get(proxyUrl(url), { headers: proxyHeaders(token) })
.then((res) => setValid(res.status === 200))
.then((res) => {
// Valid if it's a 200, has data, and is JSON
const isValid = (
res.status === 200 &&
res.data &&
(res.headers['content-type'] === 'application/json' || res.data === "OK")
);
setValid(isValid);
})
.catch((err) => {
toast({
title: err.response?.data?.error || err.response?.data || err.message,
status: 'error',
isClosable: true,
});
if (err.response.status === 404) {
toast({
title: 'Not found',
status: 'error',
isClosable: true,
});
} else {
toast({
title: err.response?.data?.error || err.message || err.response?.data,
status: 'error',
isClosable: true,
});
}
setValid(false);
})
.finally(() => setLoading.off());
Expand Down
2 changes: 1 addition & 1 deletion astronomer_starship/src/pages/DAGHistoryPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ DAGHistoryMigrateButton.defaultProps = {
isDisabled: false,
};

export function setDagData(localData, remoteData, key = 'dag_id') {
function setDagData(localData, remoteData, key = 'dag_id') {
const output = {};
localData.forEach((i) => {
const keyValue = i[key];
Expand Down
Loading

0 comments on commit 0d13beb

Please sign in to comment.