How to use StorageService class of com.testsigma.service package

Best Testsigma code snippet using com.testsigma.service.StorageService

Source:CertificateService.java Github

copy

Full Screen

1package com.testsigma.service;2import com.google.common.collect.Lists;3import com.testsigma.config.StorageServiceFactory;4import com.testsigma.model.StorageAccessLevel;5import com.testsigma.exception.TestsigmaException;6import com.testsigma.model.ProvisioningProfile;7import lombok.RequiredArgsConstructor;8import lombok.extern.log4j.Log4j2;9import org.apache.http.Header;10import org.apache.http.HttpEntity;11import org.apache.http.HttpHeaders;12import org.apache.http.HttpResponse;13import org.apache.http.client.methods.HttpGet;14import org.apache.http.client.methods.HttpPost;15import org.apache.http.entity.ContentType;16import org.apache.http.entity.mime.MultipartEntityBuilder;17import org.apache.http.entity.mime.content.FileBody;18import org.apache.http.impl.client.CloseableHttpClient;19import org.apache.http.impl.client.HttpClients;20import org.apache.http.message.BasicHeader;21import org.springframework.beans.factory.annotation.Autowired;22import org.springframework.http.HttpStatus;23import org.springframework.stereotype.Service;24import javax.annotation.PostConstruct;25import java.io.*;26import java.util.ArrayList;27import java.util.List;28import java.util.zip.ZipEntry;29import java.util.zip.ZipInputStream;30@Log4j231@Service32@RequiredArgsConstructor(onConstructor = @__({@Autowired}))33public class CertificateService {34 public static final String CSR_EXTENSION = ".csr";35 public static final String CERTIFICATE_CER_EXTENSION = ".cer";36 public static final String CERTIFICATE_CRT_EXTENSION = ".crt";37 public static final String PEM_EXTENSION = ".pem";38 public static final String MOBILE_PROVISION_EXTENSION = ".mobileprovision";39 public static final String CSR_FILE_SUFFIX = "_csr";40 public static final String PRIVATE_KEY_FILE_SUFFIX = "_private_key";41 public static final String CERTIFICATE_FILE_SUFFIX = "_certificate";42 public static final String MOBILE_PROVISION_FILE_SUFFIX = "_mobileprovision";43 private final StorageServiceFactory storageServiceFactory;44 private final TestsigmaOSConfigService osService;45 private String certificateApiURL = null;46 @PostConstruct47 public void init() {48 certificateApiURL = osService.getTestsigmaOsProxyUrl() + "/api_public/ios/certificates/";49 }50 public void writeCSR(File csrOutput, File privateKeyOutPut) throws Exception {51 CloseableHttpClient closeableHttpClient = HttpClients.custom().build();52 HttpGet getRequest = new HttpGet(certificateApiURL + "csr");53 org.apache.http.HttpResponse response = closeableHttpClient.execute(getRequest);54 if (response.getStatusLine().getStatusCode() == HttpStatus.OK.value()) {55 unzipFiles(response, csrOutput, privateKeyOutPut);56 log.info("csr and pem generated");57 } else {58 throw new TestsigmaException("Error while generating csr");59 }60 }61 public void writeCRT(File cer, File crtOutput) throws IOException, TestsigmaException {62 log.info("Generating CRT....");63 MultipartEntityBuilder builder = MultipartEntityBuilder.create();64 builder.addPart("certificate", new FileBody(cer, ContentType.DEFAULT_BINARY));65 HttpResponse response = postRequest(certificateApiURL + "cer", builder.build());66 Integer status = response.getStatusLine().getStatusCode();67 if (status.equals(HttpStatus.OK.value())) {68 writeResponseToFile(response, crtOutput);69 log.info("crt generated");70 } else {71 throw new TestsigmaException("Error while generating CRT");72 }73 }74 public void writePem(File crt, File pemOutput) throws IOException, TestsigmaException {75 log.info("Generating Certificate PEM....");76 MultipartEntityBuilder builder = MultipartEntityBuilder.create();77 builder.addPart("certificate", new FileBody(crt, ContentType.DEFAULT_BINARY));78 HttpResponse response = postRequest(certificateApiURL + "cer_pem", builder.build());79 Integer status = response.getStatusLine().getStatusCode();80 if (status.equals(HttpStatus.OK.value())) {81 writeResponseToFile(response, pemOutput);82 log.info("Private key for certificate(CRT) updated successfully");83 } else {84 log.error("Error while updating private key for CRT");85 throw new TestsigmaException("Error while updating private key for CRT");86 }87 }88 public void setPreSignedURLs(ProvisioningProfile provisioningProfile) {89 String profilePathPrefix = s3Prefix(provisioningProfile.getId());90 String csrFile = profilePathPrefix + CSR_FILE_SUFFIX + CSR_EXTENSION;91 String privateKeyFile = profilePathPrefix + PRIVATE_KEY_FILE_SUFFIX + PEM_EXTENSION;92 String certificateCerFile = profilePathPrefix + CERTIFICATE_FILE_SUFFIX + CERTIFICATE_CER_EXTENSION;93 String certificateCrtFile = profilePathPrefix + CERTIFICATE_FILE_SUFFIX + CERTIFICATE_CRT_EXTENSION;94 String certificatePemFile = profilePathPrefix + CERTIFICATE_FILE_SUFFIX + PEM_EXTENSION;95 String mobileProvisionFile = profilePathPrefix + MOBILE_PROVISION_FILE_SUFFIX + MOBILE_PROVISION_EXTENSION;96 StorageService storageService = storageServiceFactory.getStorageService();97 provisioningProfile.setCsrPresignedUrl(storageService.generatePreSignedURLIfExists(csrFile,98 StorageAccessLevel.READ, 180).orElse(null));99 provisioningProfile.setPrivateKeyPresignedUrl(storageService.generatePreSignedURLIfExists(privateKeyFile,100 StorageAccessLevel.READ, 180).orElse(null));101 provisioningProfile.setCertificateCerPresignedUrl(storageService.generatePreSignedURLIfExists(certificateCerFile,102 StorageAccessLevel.READ, 180).orElse(null));103 provisioningProfile.setCertificateCrtPresignedUrl(storageService.generatePreSignedURLIfExists(certificateCrtFile,104 StorageAccessLevel.READ, 180).orElse(null));105 provisioningProfile.setCertificatePemPresignedUrl(storageService.generatePreSignedURLIfExists(certificatePemFile,106 StorageAccessLevel.READ, 180).orElse(null));107 provisioningProfile.setProvisioningProfilePresignedUrl(storageService.generatePreSignedURLIfExists(mobileProvisionFile,108 StorageAccessLevel.READ, 180).orElse(null));109 }110 public String s3Prefix(Long profileId) {...

Full Screen

Full Screen

Source:StorageServiceFactory.java Github

copy

Full Screen

...9@Configuration10@Data11@RequiredArgsConstructor(onConstructor = @__(@Autowired))12@Component13public class StorageServiceFactory {14 private static AwsS3StorageService awsS3StorageService;15 private static AzureBlobStorageService azureBlobStorageService;16 private static OnPremiseStorageService onPremiseStorageService;17 private static TestsigmaStorageService testsigmaStorageService;18 private final ApplicationConfig applicationConfig;19 private final HttpClient httpClient;20 private final JWTTokenService jwtTokenService;21 private final StorageConfigService storageConfigService;22 private final TestsigmaOSConfigService osConfigService;23 public StorageService getStorageService() {24 com.testsigma.model.StorageConfig storageConfig = storageConfigService.getStorageConfig();25 switch (storageConfig.getStorageType()) {26 case AWS_S3:27 if (awsS3StorageService != null && !isStorageConfigChanged(awsS3StorageService))28 return awsS3StorageService;29 awsS3StorageService = new AwsS3StorageService(storageConfigService.getStorageConfig(), applicationConfig, httpClient);30 return awsS3StorageService;31 case AZURE_BLOB:32 if (azureBlobStorageService != null && !isStorageConfigChanged(azureBlobStorageService))33 return azureBlobStorageService;34 azureBlobStorageService = new AzureBlobStorageService(storageConfigService.getStorageConfig(), applicationConfig, httpClient);35 return azureBlobStorageService;36 case ON_PREMISE:37 if (onPremiseStorageService != null && !isStorageConfigChanged(onPremiseStorageService))38 return onPremiseStorageService;39 onPremiseStorageService = new OnPremiseStorageService(storageConfigService.getStorageConfig(), applicationConfig,40 httpClient, jwtTokenService);41 return onPremiseStorageService;42 case TESTSIGMA:43 if (testsigmaStorageService != null)44 return testsigmaStorageService;45 testsigmaStorageService = new TestsigmaStorageService(storageConfigService.getStorageConfig(), applicationConfig,46 osConfigService, httpClient);47 return testsigmaStorageService;48 }49 return null;50 }51 public boolean isStorageConfigChanged(StorageService storageService) {52 com.testsigma.model.StorageConfig storageConfig = storageConfigService.getStorageConfig();53 com.testsigma.model.StorageConfig serviceStorageConfig = storageService.getStorageConfig();54 if ((storageConfig.getAwsBucketName() != null) && (!storageConfig.getAwsBucketName().equals(serviceStorageConfig.getAwsBucketName())))55 return true;56 if ((storageConfig.getAwsAccessKey() != null) && (!storageConfig.getAwsAccessKey().equals(serviceStorageConfig.getAwsAccessKey())))57 return true;58 if ((storageConfig.getAwsEndpoint() != null) && !storageConfig.getAwsEndpoint().equals(serviceStorageConfig.getAwsEndpoint()))59 return true;60 if ((storageConfig.getAwsRegion() != null) && (!storageConfig.getAwsRegion().equals(serviceStorageConfig.getAwsRegion())))61 return true;62 if ((storageConfig.getAwsSecretKey() != null) && (!storageConfig.getAwsSecretKey().equals(serviceStorageConfig.getAwsSecretKey())))63 return true;64 if ((storageConfig.getAzureContainerName() != null) && (!storageConfig.getAzureConnectionString().equals(serviceStorageConfig.getAzureConnectionString())))65 return true;...

Full Screen

Full Screen

StorageService

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.StorageService;2public class TestStorageService {3 public static void main(String[] args) {4 StorageService service = new StorageService();5 service.add(1, 2);6 service.add(3, 4);7 service.add(5, 6);8 System.out.println(service.getSum());9 }10}

Full Screen

Full Screen

StorageService

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.StorageService;2public class TestStorageService {3 public static void main(String[] args) {4 StorageService service = new StorageService();5 service.store("key", "value");6 String value = service.getValue("key");7 System.out.println(value);8 }9}

Full Screen

Full Screen

StorageService

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.StorageService;2public class 2{3 public static void main(String[] args){4 StorageService storageService = new StorageService();5 storageService.getStorageDetails();6 }7}8import com.testsigma.service.StorageService;9public class 3{10 public static void main(String[] args){11 StorageService storageService = new StorageService();12 storageService.getStorageDetails();13 }14}15import com.testsigma.service.StorageService;16public class 4{17 public static void main(String[] args){18 StorageService storageService = new StorageService();19 storageService.getStorageDetails();20 }21}22import com.testsigma.service.StorageService;23public class 5{24 public static void main(String[] args){25 StorageService storageService = new StorageService();26 storageService.getStorageDetails();27 }28}29import com.testsigma.service.StorageService;30public class 6{31 public static void main(String[] args){32 StorageService storageService = new StorageService();33 storageService.getStorageDetails();34 }35}36import com.testsigma.service.StorageService;37public class 7{38 public static void main(String[] args){39 StorageService storageService = new StorageService();40 storageService.getStorageDetails();41 }42}43import com.testsigma.service.StorageService;44public class 8{

Full Screen

Full Screen

StorageService

Using AI Code Generation

copy

Full Screen

1import com.testsigma.service.StorageService;2class StorageServiceDemo{3public static void main(String[] args){4StorageService storageService = new StorageService();5storageService.store("Hello World");6}7}8package com.testsigma.service;9public class StorageService{10public void store(String data){11System.out.println(data);12}13}

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.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful