Skip to content

Commit 8aab9f8

Browse files
authored
fix(auth tokens) Added support for auth tokens (#49)
1 parent 071a980 commit 8aab9f8

File tree

7 files changed

+75
-37
lines changed

7 files changed

+75
-37
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IMAGE?=localstack/localstack-docker-desktop
2-
TAG?=0.5.1
2+
TAG?=0.5.2
33

44
BUILDER=buildx-multi-arch
55

ui/src/components/Header/Controller.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import {
1111
} from '../../services';
1212
import {
1313
DEFAULT_CONFIGURATION_ID,
14-
START_ARGS,
1514
FLAGS,
16-
IMAGE,
1715
PRO_IMAGE,
16+
COMMUNITY_IMAGE,
1817
} from '../../constants';
1918
import { LongMenu } from './Menu';
2019
import { DockerContainer, DockerImage } from '../../types';
2120
import { DownloadProgressDialog } from '../Feedback/DownloadProgressDialog';
2221
import { ProgressButton } from '../Feedback';
22+
import { generateCLIArgs } from '../../services/util/cli';
2323

2424
const EXCLUDED_ERROR_TOAST = ['INFO', 'WARN', 'DEBUG'];
2525

@@ -28,7 +28,7 @@ export const Controller = (): ReactElement => {
2828
const { data, mutate } = useLocalStack();
2929
const { user, os, hasSkippedConfiguration } = useMountPoint();
3030
const [runningConfig, setRunningConfig] = useState<string>(configData.runningConfig ?? DEFAULT_CONFIGURATION_ID);
31-
const [downloadProps, setDownloadProps] = useState({ open: false, image: IMAGE });
31+
const [downloadProps, setDownloadProps] = useState({ open: false, image: COMMUNITY_IMAGE });
3232
const [isStarting, setIsStarting] = useState<boolean>(false);
3333
const [isStopping, setIsStopping] = useState<boolean>(false);
3434
const ddClient = useDDClient();
@@ -48,38 +48,49 @@ export const Controller = (): ReactElement => {
4848
}
4949
}, [isLoading]);
5050

51-
52-
const buildMountArg = () => {
51+
const buildHostArgs = () => {
5352
let location = 'LOCALSTACK_VOLUME_DIR=/tmp/localstack/volume';
53+
let homeDir = `HOME=/home/${user}`;
5454

5555
if (!hasSkippedConfiguration) {
5656
switch (ddClient.host.platform) {
5757
case 'win32':
5858
location = `LOCALSTACK_VOLUME_DIR=\\\\wsl$\\${os}\\home\\${user}\\.cache\\localstack\\volume`;
59+
homeDir = `HOME=\\\\wsl$\\${os}\\home\\${user}`;
5960
break;
6061
case 'darwin':
6162
location = `LOCALSTACK_VOLUME_DIR=/Users/${user}/Library/Caches/localstack/volume`;
63+
homeDir = `HOME=/Users/${user}`;
6264
break;
6365
default:
6466
location = `LOCALSTACK_VOLUME_DIR=/home/${user}/.cache/localstack/volume`;
67+
homeDir = `HOME=/home/${user}`;
6568
}
6669
}
67-
return ['-e', location];
70+
return ['-e', location, '-e', homeDir];
6871
};
6972

7073
const normalizeArguments = async () => {
7174
const extendedFlag = FLAGS.map(x => x); // clone
72-
75+
let isPro = false;
7376
const addedArgs = configData.configs.find(config => config.id === runningConfig)
7477
.vars.map(item => {
7578
if (item.variable === 'DOCKER_FLAGS') {
7679
extendedFlag[1] = FLAGS.at(1).slice(0, -1).concat(` ${item.value}'`);
7780
}
81+
if (item.variable === 'LOCALSTACK_AUTH_TOKEN') {
82+
isPro = true;
83+
}
7884

7985
return ['-e', `${item.variable}=${item.value}`];
8086
}).flat();
8187

82-
return [...extendedFlag, ...buildMountArg(), ...addedArgs, ...START_ARGS];
88+
return [
89+
...extendedFlag,
90+
...buildHostArgs(),
91+
...addedArgs,
92+
...generateCLIArgs({ call: 'start', pro: isPro }),
93+
];
8394
};
8495

8596
const start = async () => {
@@ -89,26 +100,25 @@ export const Controller = (): ReactElement => {
89100
.vars.some(item => (item.variable === 'LOCALSTACK_API_KEY' ||
90101
item.variable === 'LOCALSTACK_AUTH_TOKEN') && item.value);
91102

92-
const haveCommunity = images.some(image => image.RepoTags?.at(0) === IMAGE);
93-
if (!haveCommunity) {
94-
setDownloadProps({ open: true, image: IMAGE });
103+
const havePro = images.some(image => removeTagFromImage(image) === PRO_IMAGE);
104+
if (!havePro && isPro) {
105+
setDownloadProps({ open: true, image: PRO_IMAGE });
95106
return;
96107
}
97108

98-
if (isPro) {
99-
const havePro = images.some(image => removeTagFromImage(image) === PRO_IMAGE);
100-
if (!havePro) {
101-
setDownloadProps({ open: true, image: PRO_IMAGE });
102-
return;
103-
}
109+
const haveCommunity = images.some(image => removeTagFromImage(image) === COMMUNITY_IMAGE);
110+
if (!haveCommunity) {
111+
setDownloadProps({ open: true, image: COMMUNITY_IMAGE });
112+
return;
104113
}
105114

106115
const args = await normalizeArguments();
116+
107117
setIsStarting(true);
108118
ddClient.docker.cli.exec('run', args, {
109119
stream: {
110120
onOutput(data): void {
111-
const shouldDisplayError = !EXCLUDED_ERROR_TOAST.some(item => data.stderr.includes(item));
121+
const shouldDisplayError = !EXCLUDED_ERROR_TOAST.some(item => data.stderr?.includes(item)) && data.stderr;
112122
if (shouldDisplayError) {
113123
ddClient.desktopUI.toast.error(data.stderr);
114124
setIsStarting(false);

ui/src/components/Views/Update/UpdateDialog.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
Typography,
77
} from '@mui/material';
88
import React, { ReactElement, useEffect, useState } from 'react';
9-
import { UPDATE_ARGS } from '../../../constants';
109
import { useDDClient } from '../../../services';
10+
import { generateCLIArgs } from '../../../services/util/cli';
1111

1212
type Props = {
1313
open: boolean,
@@ -20,14 +20,18 @@ export const UpdateDialog = ({ open, onClose }: Props): ReactElement => {
2020
const [isUpdating, setIsUpdating] = useState<boolean>(true);
2121

2222
useEffect(() => {
23-
const listener = ddClient.docker.cli.exec('run', UPDATE_ARGS, {
23+
const listener = ddClient.docker.cli.exec('run', generateCLIArgs({ call: 'update' }), {
2424
stream: {
2525
onOutput(data): void {
2626
let resultStr = data.stdout
2727
.replaceAll('─', '')
2828
.replaceAll('✔', '✅')
2929
.replaceAll('✖', '❌');
3030

31+
if (data.stdout.includes('Updating docker images')) {
32+
resultStr = 'Updating Docker images';
33+
}
34+
3135
if (resultStr.endsWith('updated.')) {
3236
resultStr = resultStr.concat(' 🔼');
3337
}

ui/src/constants/common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const DEFAULT_CONFIGURATION_ID='00000000-0000-0000-0000-000000000000';
2-
export const CORS_ALLOW_DEFAULT='http://localhost:3000';
3-
export const IMAGE = 'localstack/localstack:2.1.0';
1+
export const DEFAULT_CONFIGURATION_ID = '00000000-0000-0000-0000-000000000000';
2+
export const CORS_ALLOW_DEFAULT = 'http://localhost:3000';
3+
export const COMMUNITY_IMAGE = 'localstack/localstack';
44
export const PRO_IMAGE = 'localstack/localstack-pro';

ui/src/constants/docker.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
import { IMAGE } from './common';
1+
import { PRO_IMAGE, COMMUNITY_IMAGE } from './common';
22

3-
const COMMON_ARGS = [
3+
export const COMMON_ARGS = [
44
'--label',
55
'cloud.localstack.spawner=true',
66
'--rm',
77
'-i',
88
'--entrypoint=',
99
'-v',
1010
'/var/run/docker.sock:/var/run/docker.sock',
11-
IMAGE,
12-
'bin/localstack',
1311
];
1412

13+
export const PRO_CLI = [
14+
PRO_IMAGE,
15+
'./.venv/bin/python3',
16+
'-m',
17+
'localstack.cli.main',
18+
];
19+
20+
export const COMMUNITY_CLI = [COMMUNITY_IMAGE, 'bin/localstack'];
21+
1522
export const START_ARGS = [
16-
...COMMON_ARGS,
1723
'start',
1824
'-d',
1925
];
2026

21-
export const STATUS_ARGS = [
22-
...COMMON_ARGS,
23-
'status',
24-
];
25-
2627
export const UPDATE_ARGS = [
27-
...COMMON_ARGS,
2828
'update',
2929
'docker-images',
3030
];
3131

3232
export const FLAGS = [
3333
'-e',
3434
// eslint-disable-next-line max-len
35-
'DOCKER_FLAGS=\'--label com.docker.compose.project=localstack_localstack-docker-desktop-desktop-extension --label com.docker.desktop.extension=true --label com.docker.compose.project.config_files\'',
35+
'DOCKER_FLAGS=--label com.docker.compose.project=localstack_localstack-docker-desktop-desktop-extension --label com.docker.desktop.extension=true --label com.docker.compose.project.config_files',
3636
];

ui/src/services/util/cli.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { COMMON_ARGS, COMMUNITY_CLI, PRO_CLI, START_ARGS, UPDATE_ARGS } from '../../constants';
2+
3+
export interface generateCLIArgsProps {
4+
call: 'start' | 'update',
5+
pro?: boolean,
6+
}
7+
8+
export const generateCLIArgs = ({ call, pro = false }: generateCLIArgsProps): string[] => {
9+
const callArgs = [...COMMON_ARGS];
10+
if (pro) {
11+
callArgs.push(...PRO_CLI);
12+
} else {
13+
callArgs.push(...COMMUNITY_CLI);
14+
}
15+
16+
switch (call) {
17+
case 'start': callArgs.push(...START_ARGS);
18+
break;
19+
default: callArgs.push(...UPDATE_ARGS);
20+
break;
21+
}
22+
return callArgs;
23+
24+
};

ui/src/services/util/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const EXCLUDED_USER_WSL = ['[.]', '[..]', '\r'];
2121

2222
export function getUsersFromBinaryWindows(res: string): string[] {
2323
return res.split('\n').filter(string => string.startsWith('[')) // get only directory rows (they are in form "[user1] [user2]" )
24-
.map(elem =>elem.split(' ').filter(item => item.length > 0 && !EXCLUDED_USER_WSL.includes(item)))// get only dir names
24+
.map(elem => elem.split(' ').filter(item => item.length > 0 && !EXCLUDED_USER_WSL.includes(item)))// get only dir names
2525
.reduce((accumulator, currentValue) => accumulator.concat(currentValue), []) // combine multiple lines into one
2626
.map(user => user.slice(1, -1)); // remove "[" and "]" from names
2727
}

0 commit comments

Comments
 (0)