6262import com .cloud .utils .component .ManagerBase ;
6363import com .cloud .utils .concurrency .NamedThreadFactory ;
6464import com .cloud .utils .db .GlobalLock ;
65+ import com .cloud .utils .exception .CloudRuntimeException ;
6566
6667public class ExtensionsShareManagerImpl extends ManagerBase implements ExtensionsShareManager {
6768
@@ -82,6 +83,7 @@ public class ExtensionsShareManagerImpl extends ManagerBase implements Extension
8283
8384 private ScheduledExecutorService extensionShareCleanupExecutor ;
8485 private int shareLinkValidityInterval ;
86+ private boolean serverShareEnabled = true ;
8587
8688 protected Path getExtensionsSharePath () {
8789 String shareBaseDir = ServerPropertiesUtil .getShareBaseDirectory ();
@@ -213,7 +215,10 @@ protected ArchiveInfo createArchiveForDownload(Extension extension) throws IOExc
213215 * @throws InvalidKeyException if the secret key is invalid
214216 */
215217 protected String generateSignedArchiveUrl (ManagementServerHost managementServer , Path archivePath )
216- throws DecoderException , NoSuchAlgorithmException , InvalidKeyException {
218+ throws DecoderException , NoSuchAlgorithmException , InvalidKeyException , CloudRuntimeException {
219+ if (!serverShareEnabled ) {
220+ throw new CloudRuntimeException ("Share context is disabled on this management server in server.properties" );
221+ }
217222 final String baseUrl = getManagementServerBaseUrl (managementServer );
218223 final long expiresAtEpochSec = System .currentTimeMillis () / 1000L + shareLinkValidityInterval ;
219224 final String secretKey = ServerPropertiesUtil .getShareSecret ();
@@ -442,6 +447,7 @@ public boolean start() {
442447 initialDelay , shareLinkValidityInterval );
443448 extensionShareCleanupExecutor .scheduleWithFixedDelay (new ShareCleanupWorker (),
444449 initialDelay , shareLinkValidityInterval , TimeUnit .SECONDS );
450+ serverShareEnabled = ServerPropertiesUtil .getShareEnabled ();
445451 return true ;
446452 }
447453
@@ -468,7 +474,7 @@ public Pair<Boolean, String> syncExtension(Extension extension, ManagementServer
468474 String signedUrl ;
469475 try {
470476 signedUrl = generateSignedArchiveUrl (sourceManagementServer , archiveInfo .getPath ());
471- } catch (DecoderException | NoSuchAlgorithmException | InvalidKeyException e ) {
477+ } catch (DecoderException | NoSuchAlgorithmException | InvalidKeyException | CloudRuntimeException e ) {
472478 String msg = "Failed to generate signed URL" ;
473479 logger .error ("{} for {} using {}" , msg , extension , sourceManagementServer , e );
474480 return new Pair <>(false , msg );
0 commit comments