3535 "offers" : { "@type" :"Offer" , "price" :"0" , "priceCurrency" :"GBP" }
3636 }
3737 </ script >
38+
39+
40+ < script src ='https://ajaxorg.github.io/ace-builds/src-noconflict/ace.js '> </ script >
3841
42+ < script src ='generate.js '> </ script >
3943
44+
4045 < script src ='https://libs.ext-code.com/js/dom/component/component.js '> </ script >
4146
4247 < script init >
4752 var df = true , version = 'v2.0'
4853 ;
4954
55+ var ace ;
56+
5057 var ext ;
5158 var $ ;
5259 var datatype ;
5764 var menu ;
5865
5966 var hdr ;
67+ var script ;
6068 var log ;
6169
6270
6371 async function init ( ) {
6472
65- menu = menumod ( ) ;
73+ menu = menumod ( ) ;
6674
67- hdr = mod [ 'gcloud-hdr' ] ;
68- log = mod [ 'log-mod' ] ;
75+ hdr = mod [ 'gcloud-hdr' ] ;
76+ script = mod [ 'script' ] ;
77+ log = mod [ 'log-mod' ] ;
6978
7079 hdr . initmod ( { ext, $, menu} ) ;
80+ script . initmod ( { ext, $, menu, ace} ) ;
7181 log . initmod ( { ext, $} ) ;
7282
7383 await Promise . all ( [
7484 hdr . init ( ) ,
85+ script . init ( ) ,
7586 log . init ( ) ,
7687 ] ) ;
7788
113124
114125 body
115126 {height : calc (100% - 40px );display : flex;flex-direction : column;gap : 10px ;margin : 20px }
116-
117- # output
118- {overflow : auto;flex : 1 ;
119- white-space : pre-wrap;font-family : monospace;word-break : break-all;
120- }
121-
122127
123128 input
124129 {font-size : 16px ;padding : 5px 10px }
125130 input [type = button ]
126131 {cursor : pointer}
127132
128133
129- .visually-hidden
130- {position : absolute;clip : rect (0 0 0 0 );width : 1px ;height : 1px ;overflow : hidden;}
134+
135+
136+ # output
137+ {white-space : pre-wrap;font-family : monospace;word-break : break-all;border : 1px solid lightgray;border-radius : 10px ;padding : 10px ;
138+ height : 350px ;flex : 0 0 auto;
139+ }
140+
141+ web-editor
142+ {border : 1px solid lightgray;padding : 10px ;flex : 1 }
143+
144+ .visually-hidden
145+ {position : absolute;clip : rect (0 0 0 0 );width : 1px ;height : 1px ;overflow : hidden;}
131146
132147 </ style >
133148
@@ -158,6 +173,10 @@ <h1 class=visually-hidden>generate access token from service account keyfile</h1
158173 < div id =output >
159174 </ div >
160175
176+
177+ < web-editor id =script component src ='generate.js '> </ web-editor >
178+
179+
161180 < log-mod component > </ log-mod >
162181
163182 </ body >
@@ -175,6 +194,10 @@ <h1 class=visually-hidden>generate access token from service account keyfile</h1
175194 function initdom ( ) {
176195
177196
197+ hdr . initdom ( ) ;
198+ script . initdom ( ) ;
199+ log . initdom ( ) ;
200+
178201
179202 document . querySelector ( '[value=copy]' ) . onclick = e => {
180203
@@ -188,13 +211,33 @@ <h1 class=visually-hidden>generate access token from service account keyfile</h1
188211 } //copy
189212
190213
191- document . querySelector ( '[value=new]' ) . onclick = e => {
214+ document . querySelector ( '[value=new]' ) . onclick = async e => {
192215
193216 if ( ! keyfile ) {
194217 disp ( 'no service account file selected' ) ;
195218 return ;
196219 }
197- generate ( ) ;
220+
221+
222+
223+ output . replaceChildren ( ) ;
224+
225+ var json ;
226+ ( { json, token} = await generate ( keyfile ) ) ;
227+
228+
229+ disp ( JSON . stringify ( json , null , 4 ) ) ;
230+
231+ disp ( ) ;
232+
233+ disp ( 'token' ) ;
234+ disp ( token ) ;
235+
236+ disp ( ) ;
237+
238+ navigator . clipboard . writeText ( token ) ;
239+ disp ( 'copied to clipboard' ) ;
240+
198241
199242 } //new
200243
@@ -204,7 +247,26 @@ <h1 class=visually-hidden>generate access token from service account keyfile</h1
204247 var blob = file . files [ 0 ] ;
205248 var txt = await blob . text ( ) ;
206249 keyfile = JSON . parse ( txt ) ;
207- generate ( ) ;
250+
251+
252+ output . replaceChildren ( ) ;
253+
254+
255+ var { json, token} = await generate ( keyfile ) ;
256+
257+
258+ disp ( JSON . stringify ( json , null , 4 ) ) ;
259+
260+ disp ( ) ;
261+
262+ disp ( 'token' ) ;
263+ disp ( token ) ;
264+
265+ disp ( ) ;
266+
267+ navigator . clipboard . writeText ( token ) ;
268+ disp ( 'copied to clipboard' ) ;
269+
208270
209271 } //onchange
210272
@@ -216,32 +278,25 @@ <h1 class=visually-hidden>generate access token from service account keyfile</h1
216278 //:
217279
218280
219- async function generate ( ) {
220-
221- output . replaceChildren ( ) ;
222281
223-
224- const assertion = await buildJwtAssertion ( {
225- clientEmail : keyfile . client_email ,
226- privateKeyPem : keyfile . private_key . replace ( / \\ n / g, '\n' ) ,
227- scope : 'https://www.googleapis.com/auth/devstorage.read_write'
228- } ) ;
229- const json = await exchangeForAccessToken ( assertion ) ;
230- token = json . access_token ;
282+ /*
231283
284+
285+ async function generate(keyfile){
232286
233- disp ( JSON . stringify ( json , null , 4 ) ) ;
234-
235- disp ( ) ;
287+
288+
289+ var clientEmail = keyfile.client_email;
290+ var privateKeyPem = keyfile.private_key.replace(/\\n/g,'\n');
291+ var scope = 'https://www.googleapis.com/auth/devstorage.read_write';
236292
237- disp ( 'token' ) ;
238- disp ( token ) ;
293+ var assertion = await buildJwtAssertion({clientEmail,privateKeyPem,scope});
294+ var json = await exchangeForAccessToken(assertion);
295+ var token = json.access_token;
296+
239297
240- disp ( ) ;
298+ return {json,token} ;
241299
242- navigator . clipboard . writeText ( token ) ;
243- disp ( 'copied to clipboard' ) ;
244-
245300
246301
247302 function base64url(input){
@@ -344,7 +399,7 @@ <h1 class=visually-hidden>generate access token from service account keyfile</h1
344399 var err;
345400 try{
346401
347- var res = await fetch ( url , { method :'psot ' , headers, body} ) ;
402+ var res = await fetch(url,{method:'post ',headers,body});
348403
349404 }//try
350405 catch(err2){
@@ -371,6 +426,8 @@ <h1 class=visually-hidden>generate access token from service account keyfile</h1
371426 }//generate
372427
373428
429+ */
430+
374431 function disp ( ) {
375432
376433 console . log . apply ( console , arguments ) ;
0 commit comments