File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,14 @@ impl RpcHandler {
178178 Ok ( ( ) )
179179 }
180180
181+ fn ensure_admin ( & self , token : & str ) -> Result < ( ) > {
182+ let token_hash = sha2:: Sha256 :: new_with_prefix ( token) . finalize ( ) ;
183+ if token_hash. as_slice ( ) != self . state . config . admin_token_hash . as_slice ( ) {
184+ bail ! ( "Invalid token" ) ;
185+ }
186+ Ok ( ( ) )
187+ }
188+
181189 fn get_cached_mrs ( & self , key : & str ) -> Result < Mrs > {
182190 let path = self . mr_cache_dir ( ) . join ( key) ;
183191 if !path. exists ( ) {
@@ -609,10 +617,7 @@ impl KmsRpc for RpcHandler {
609617 }
610618
611619 async fn clear_image_cache ( self , request : ClearImageCacheRequest ) -> Result < ( ) > {
612- let token_hash = sha2:: Sha256 :: new_with_prefix ( & request. token ) . finalize ( ) ;
613- if token_hash. as_slice ( ) != self . state . config . admin_token_hash . as_slice ( ) {
614- bail ! ( "Invalid token" ) ;
615- }
620+ self . ensure_admin ( & request. token ) ?;
616621 self . remove_cache_dir ( & self . image_cache_dir ( ) , & request. image_hash )
617622 . context ( "Failed to clear image cache" ) ?;
618623 self . remove_cache_dir ( & self . mr_cache_dir ( ) , & request. config_hash )
You can’t perform that action at this time.
0 commit comments