@@ -22,6 +22,8 @@ <h3>Operations</h3>
2222 < ul >
2323 < li > < a href ="# " id ="doMeta "> Get Metadata</ a > </ li >
2424 < li > < a href ="# " id ="doList "> List Cloud Encryption Keys</ a > </ li >
25+ < li > < a href ="# " id ="doRotate "> Rotate Cloud Encryption Keys</ a > </ li >
26+ < li > < a href ="# " id ="doEncrypt "> Re-encrypt All S3 Files</ a > </ li >
2527 </ ul >
2628
2729 < br >
@@ -46,7 +48,21 @@ <h3>Output</h3>
4648 {
4749 name : "Site" ,
4850 formatter : ( cell , row ) => {
49- return gridjs . html ( `<span class="${ row . cells [ 4 ] . data } ">${ cell . siteId } - ${ cell . siteName } </span>` )
51+ return gridjs . html ( `<span class="${ row . cells [ 4 ] . data } ">${ formatSite ( cell ) } </span>` )
52+ } ,
53+ sort : {
54+ compare : ( a , b ) => {
55+ const fullA = formatSite ( a ) ;
56+ const fullB = formatSite ( b ) ;
57+
58+ if ( fullA > fullB ) {
59+ return 1 ;
60+ } else if ( fullA < fullB ) {
61+ return - 1 ;
62+ } else {
63+ return 0 ;
64+ }
65+ }
5066 }
5167 } ,
5268 {
@@ -73,7 +89,7 @@ <h3>Output</h3>
7389 if ( cellIndex === 0 ) {
7490 return cell ;
7591 } else if ( cellIndex === 1 ) {
76- return ` ${ cell . siteId } - ${ cell . siteName } ` ;
92+ return formatSite ( cell ) ;
7793 }
7894 }
7995 } ,
@@ -97,7 +113,11 @@ <h3>Output</h3>
97113 timeZoneName : "short"
98114 } ;
99115 return date . toLocaleString ( "en-US" , options ) ;
100- }
116+ } ;
117+
118+ const formatSite = ( site ) => {
119+ return `${ site . siteId } - ${ site . siteName } ` ;
120+ } ;
101121
102122 const updateGrid = ( grid , data ) => {
103123 const groupedData = data . cloudEncryptionKeys . reduce ( ( acc , key ) => {
@@ -123,36 +143,49 @@ <h3>Output</h3>
123143 grid
124144 . updateConfig ( { data : gridData } )
125145 . forceRender ( ) ;
126- }
146+ } ;
127147
128148 const clearGrid = ( grid ) => {
129149 grid
130150 . updateConfig ( { data : [ ] } )
131151 . forceRender ( ) ;
132- }
152+ } ;
153+
154+ const doList = ( ) => {
155+ clearGrid ( grid ) ;
156+ doApiCallWithCallback ( "GET" , "/api/site/list" , ( text ) => {
157+ const sites = JSON . parse ( text ) ;
158+ const siteDict = sites . reduce ( ( acc , site ) => {
159+ acc [ site . id ] = site . name ;
160+ return acc ;
161+ } , { } ) ;
162+
163+ doApiCallWithCallback ( "GET" , "/api/cloud-encryption-key/list" , ( text ) => {
164+ const data = JSON . parse ( text ) ;
165+ data . cloudEncryptionKeys . forEach ( ( key ) => {
166+ key . siteName = ! siteDict [ key . siteId ] ? "Unknown site" : siteDict [ key . siteId ]
167+ } ) ;
168+ updateGrid ( grid , data ) ;
169+ } , errorCallback ) ;
170+ } , errorCallback ) ;
171+ } ;
133172
134- $ ( document ) . ready ( function ( ) {
135- $ ( "#doMeta" ) . on ( "click" , function ( ) {
173+ $ ( document ) . ready ( ( ) => {
174+ $ ( "#doMeta" ) . on ( "click" , ( ) => {
136175 doApiCall ( "GET" , "/api/cloud-encryption-key/metadata" , "#standardOutput" , "#errorOutput" ) ;
137176 } ) ;
138177
139- $ ( "#doList" ) . on ( "click" , function ( ) {
140- clearGrid ( grid ) ;
141- doApiCallWithCallback ( "GET" , "/api/site/list" , ( text ) => {
142- const sites = JSON . parse ( text ) ;
143- const siteDict = sites . reduce ( ( acc , site ) => {
144- acc [ site . id ] = site . name ;
145- return acc ;
146- } , { } ) ;
147-
148- doApiCallWithCallback ( "GET" , "/api/cloud-encryption-key/list" , ( text ) => {
149- const data = JSON . parse ( text ) ;
150- data . cloudEncryptionKeys . forEach ( ( key ) => {
151- key . siteName = ! siteDict [ key . siteId ] ? "Unknown site" : siteDict [ key . siteId ]
152- } ) ;
153- updateGrid ( grid , data ) ;
154- } , errorCallback ) ;
155- } , errorCallback ) ;
178+ $ ( "#doList" ) . on ( "click" , ( ) => {
179+ doList ( ) ;
180+ } ) ;
181+
182+ $ ( "#doRotate" ) . on ( "click" , ( ) => {
183+ doApiCall ( "POST" , "/api/cloud-encryption-key/rotate" , "#standardOutput" , "#errorOutput" ) ;
184+ doList ( ) ;
185+ } ) ;
186+
187+ $ ( "#doEncrypt" ) . on ( "click" , ( ) => {
188+ doApiCall ( "POST" , "/api/encrypted-files/syncNow" , "#standardOutput" , "#errorOutput" ) ;
156189 } ) ;
157190 } ) ;
158191</ script >
0 commit comments