How to use getSharedAccessPolicy method of com.testsigma.service.AzureBlobStorageService class

Best Testsigma code snippet using com.testsigma.service.AzureBlobStorageService.getSharedAccessPolicy

Source:AzureBlobStorageService.java Github

copy

Full Screen

...89 log.debug("Generating Shared service access URL for: " + relativeFilePathFromRoot);90 URL url = null;91 try {92 CloudBlockBlob blob = container.getBlockBlobReference(relativeFilePathFromRoot);93 String sign = blob.generateSharedAccessSignature(getSharedAccessPolicy(storageAccessLevel, expiryTimeInMinutes),94 null);95 url = new URL(String.format("%s?%s", blob.getUri(), sign));96 log.debug("Azure blob Pre-signed URL :" + url);97 } catch (Exception e) {98 log.error("Unable to generate Shared Access URL,Please verify given account details in " +99 "azure-blob.properties. " + e.getMessage(), e);100 }101 return url;102 }103 @Override104 public Optional<URL> generatePreSignedURLIfExists(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel, Integer expiryTimeInMinutes) {105 relativeFilePathFromBase = removeLeadingSeparatorCharacterIfPresent(relativeFilePathFromBase);106 log.debug("Generating Shared service access URL if exists: " + relativeFilePathFromBase);107 Optional<URL> returnURL = Optional.empty();108 try {109 CloudBlockBlob blob = container.getBlockBlobReference(relativeFilePathFromBase);110 if (blob.exists()) {111 log.debug("File exists, generating presigned URL for: " + relativeFilePathFromBase);112 returnURL = Optional.ofNullable(generatePreSignedURL(relativeFilePathFromBase, storageAccessLevel, expiryTimeInMinutes));113 }114 } catch (Exception e) {115 log.error("Unable to generate Shared Access URL,Please verify given account details in " +116 "azure-blob.properties. " + e.getMessage(), e);117 }118 return returnURL;119 }120 @Override121 public Optional<URL> generatePreSignedURLIfExists(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) {122 relativeFilePathFromBase = removeLeadingSeparatorCharacterIfPresent(relativeFilePathFromBase);123 return generatePreSignedURLIfExists(relativeFilePathFromBase, storageAccessLevel,124 storageConfig.getAzureBlobPreSignedURLTimeout());125 }126 @Override127 public URL generatePreSignedURL(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) {128 relativeFilePathFromBase = removeLeadingSeparatorCharacterIfPresent(relativeFilePathFromBase);129 return generatePreSignedURL(relativeFilePathFromBase, storageAccessLevel,130 storageConfig.getAzureBlobPreSignedURLTimeout());131 }132 @Override133 public void deleteFile(String filePath) {134 filePath = removeLeadingSeparatorCharacterIfPresent(filePath);135 log.debug("Deleting file: " + filePath);136 try {137 CloudBlockBlob blob = container.getBlockBlobReference(filePath);138 blob.deleteIfExists();139 log.info("Successfully deleted file: " + filePath);140 } catch (Exception e) {141 log.error("Unable to delete file from Azure Blob,Please verify given account details in " +142 "azure-blob.properties. " + e.getMessage(), e);143 }144 }145 @Override146 protected String getRootDirectory() {147 return storageConfig.getAzureContainerName();148 }149 private SharedAccessBlobPolicy getSharedAccessPolicy(StorageAccessLevel storageAccessLevel, Integer expiryTimeInMinutes) {150 SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();151 policy.setPermissions(getBlobPermissions(storageAccessLevel));152 Calendar cal = Calendar.getInstance();153 cal.add(Calendar.MINUTE, expiryTimeInMinutes);154 policy.setSharedAccessExpiryTime(cal.getTime());155 return policy;156 }157 private EnumSet<SharedAccessBlobPermissions> getBlobPermissions(StorageAccessLevel storageAccessLevel) {158 if (storageAccessLevel == StorageAccessLevel.READ) {159 return EnumSet.of(SharedAccessBlobPermissions.READ);160 } else if (storageAccessLevel == StorageAccessLevel.WRITE) {161 return EnumSet.of(SharedAccessBlobPermissions.WRITE, SharedAccessBlobPermissions.READ,162 SharedAccessBlobPermissions.CREATE, SharedAccessBlobPermissions.ADD);163 } else if (storageAccessLevel == StorageAccessLevel.FULL_ACCESS) {...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testsigma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful