@@ -6,99 +6,131 @@ import { requestAuthentication, saveAuthToken } from "../utils/authenticate.ts";
66
77const MIN_TIME_BETWEEN_STEPS_MS = 1_000 ; // 1s
88
9- export default createPlugin ( ( { context, outputChannel, telemetry } ) => {
10- context . subscriptions . push (
11- commands . registerCommand ( "localstack.authenticate" , async ( ) => {
12- const startedAt = new Date ( ) . toISOString ( ) ;
13- const selection = await window . showInformationMessage (
14- "Choose authentication method" ,
15- "Sign in to LocalStack" ,
16- "Enter auth token" ,
17- ) ;
18- if ( selection === "Sign in to LocalStack" ) {
19- window . withProgress (
20- {
21- location : ProgressLocation . Notification ,
22- title : "Authenticate" ,
23- cancellable : true ,
24- } ,
25- async ( progress , cancellationToken ) => {
26- /////////////////////////////////////////////////////////////////////
27- progress . report ( {
28- message :
29- "Waiting for authentication response from the browser..." ,
30- } ) ;
31- const { authToken } = await pMinDelay (
32- requestAuthentication ( context , undefined ) ,
33- MIN_TIME_BETWEEN_STEPS_MS ,
34- ) ;
35- if ( cancellationToken . isCancellationRequested ) {
9+ export default createPlugin (
10+ "authenticate" ,
11+ ( { context, outputChannel, telemetry } ) => {
12+ context . subscriptions . push (
13+ commands . registerCommand ( "localstack.authenticate" , async ( ) => {
14+ const startedAt = new Date ( ) . toISOString ( ) ;
15+ const selection = await window . showInformationMessage (
16+ "Choose authentication method" ,
17+ "Sign in to LocalStack" ,
18+ "Enter auth token" ,
19+ ) ;
20+ if ( selection === "Sign in to LocalStack" ) {
21+ window . withProgress (
22+ {
23+ location : ProgressLocation . Notification ,
24+ title : "Authenticate" ,
25+ cancellable : true ,
26+ } ,
27+ async ( progress , cancellationToken ) => {
28+ /////////////////////////////////////////////////////////////////////
29+ progress . report ( {
30+ message :
31+ "Waiting for authentication response from the browser..." ,
32+ } ) ;
33+ const { authToken } = await pMinDelay (
34+ requestAuthentication ( context , undefined ) ,
35+ MIN_TIME_BETWEEN_STEPS_MS ,
36+ ) ;
37+ if ( cancellationToken . isCancellationRequested ) {
38+ telemetry . track ( {
39+ name : "auth_token_configured" ,
40+ payload : {
41+ namespace : "onboarding" ,
42+ origin : "manual_trigger" ,
43+ position : 2 ,
44+ started_at : startedAt ,
45+ ended_at : new Date ( ) . toISOString ( ) ,
46+ status : "CANCELLED" ,
47+ } ,
48+ } ) ;
49+ return ;
50+ }
51+
52+ /////////////////////////////////////////////////////////////////////
53+ progress . report ( {
54+ message : "Authenticating to file..." ,
55+ } ) ;
56+ await pMinDelay (
57+ saveAuthToken ( authToken , outputChannel ) ,
58+ MIN_TIME_BETWEEN_STEPS_MS ,
59+ ) ;
60+
61+ /////////////////////////////////////////////////////////////////////
62+ window . showInformationMessage ( "Authentication successful." ) ;
3663 telemetry . track ( {
3764 name : "auth_token_configured" ,
3865 payload : {
3966 namespace : "onboarding" ,
4067 origin : "manual_trigger" ,
4168 position : 2 ,
69+ auth_token : authToken ,
4270 started_at : startedAt ,
4371 ended_at : new Date ( ) . toISOString ( ) ,
44- status : "CANCELLED " ,
72+ status : "COMPLETED " ,
4573 } ,
4674 } ) ;
47- return ;
48- }
75+ } ,
76+ ) ;
77+ } else if ( selection === "Enter auth token" ) {
78+ const token = await window . showInputBox ( {
79+ prompt : "Enter your LocalStack Auth Token" ,
80+ placeHolder : "Paste your auth token here" ,
81+ ignoreFocusOut : true ,
82+ } ) ;
4983
50- /////////////////////////////////////////////////////////////////////
51- progress . report ( {
52- message : "Authenticating to file..." ,
84+ if ( ! token ) {
85+ telemetry . track ( {
86+ name : "auth_token_configured" ,
87+ payload : {
88+ namespace : "onboarding" ,
89+ origin : "manual_trigger" ,
90+ position : 2 ,
91+ started_at : startedAt ,
92+ ended_at : new Date ( ) . toISOString ( ) ,
93+ status : "FAILED" ,
94+ errors : [ "No token was provided." ] ,
95+ } ,
5396 } ) ;
54- await pMinDelay (
55- saveAuthToken ( authToken , outputChannel ) ,
56- MIN_TIME_BETWEEN_STEPS_MS ,
57- ) ;
97+ return ;
98+ }
99+
100+ if ( ! token . startsWith ( "ls-" ) ) {
101+ const error_msg = 'The auth token should start with "ls-".' ;
102+ window . showErrorMessage ( error_msg ) ;
58103
59- /////////////////////////////////////////////////////////////////////
60- window . showInformationMessage ( "Authentication successful." ) ;
61104 telemetry . track ( {
62105 name : "auth_token_configured" ,
63106 payload : {
64107 namespace : "onboarding" ,
65108 origin : "manual_trigger" ,
66109 position : 2 ,
67- auth_token : authToken ,
68110 started_at : startedAt ,
69111 ended_at : new Date ( ) . toISOString ( ) ,
70- status : "COMPLETED" ,
112+ status : "FAILED" ,
113+ errors : [ error_msg ] ,
71114 } ,
72115 } ) ;
73- } ,
74- ) ;
75- } else if ( selection === "Enter auth token" ) {
76- const token = await window . showInputBox ( {
77- prompt : "Enter your LocalStack Auth Token" ,
78- placeHolder : "Paste your auth token here" ,
79- ignoreFocusOut : true ,
80- } ) ;
116+ return ;
117+ }
81118
82- if ( ! token ) {
119+ await saveAuthToken ( token , outputChannel ) ;
120+ window . showInformationMessage ( "Authentication successful." ) ;
83121 telemetry . track ( {
84122 name : "auth_token_configured" ,
85123 payload : {
86124 namespace : "onboarding" ,
87125 origin : "manual_trigger" ,
88126 position : 2 ,
127+ auth_token : token ,
89128 started_at : startedAt ,
90129 ended_at : new Date ( ) . toISOString ( ) ,
91- status : "FAILED" ,
92- errors : [ "No token was provided." ] ,
130+ status : "COMPLETED" ,
93131 } ,
94132 } ) ;
95- return ;
96- }
97-
98- if ( ! token . startsWith ( "ls-" ) ) {
99- const error_msg = 'The auth token should start with "ls-".' ;
100- window . showErrorMessage ( error_msg ) ;
101-
133+ } else if ( selection === undefined ) {
102134 telemetry . track ( {
103135 name : "auth_token_configured" ,
104136 payload : {
@@ -107,40 +139,11 @@ export default createPlugin(({ context, outputChannel, telemetry }) => {
107139 position : 2 ,
108140 started_at : startedAt ,
109141 ended_at : new Date ( ) . toISOString ( ) ,
110- status : "FAILED" ,
111- errors : [ error_msg ] ,
142+ status : "CANCELLED" ,
112143 } ,
113144 } ) ;
114- return ;
115145 }
116-
117- await saveAuthToken ( token , outputChannel ) ;
118- window . showInformationMessage ( "Authentication successful." ) ;
119- telemetry . track ( {
120- name : "auth_token_configured" ,
121- payload : {
122- namespace : "onboarding" ,
123- origin : "manual_trigger" ,
124- position : 2 ,
125- auth_token : token ,
126- started_at : startedAt ,
127- ended_at : new Date ( ) . toISOString ( ) ,
128- status : "COMPLETED" ,
129- } ,
130- } ) ;
131- } else if ( selection === undefined ) {
132- telemetry . track ( {
133- name : "auth_token_configured" ,
134- payload : {
135- namespace : "onboarding" ,
136- origin : "manual_trigger" ,
137- position : 2 ,
138- started_at : startedAt ,
139- ended_at : new Date ( ) . toISOString ( ) ,
140- status : "CANCELLED" ,
141- } ,
142- } ) ;
143- }
144- } ) ,
145- ) ;
146- } ) ;
146+ } ) ,
147+ ) ;
148+ } ,
149+ ) ;
0 commit comments