Best Testsigma code snippet using com.testsigma.service.CertificateService.s3Prefix
Source:ProvisioningProfileService.java
...50 provisioningProfile = this.provisioningProfileRepository.save(provisioningProfile);51 try {52 log.info(String.format("Generating CSR for provisioningProfile [%s] - [%s]", provisioningProfile.getId(),53 provisioningProfile.getName()));54 String csrPathPrefix = certificateService.s3Prefix(provisioningProfile.getId());55 String csrFileName = +provisioningProfile.getId() + CertificateService.CSR_FILE_SUFFIX;56 String privateKeyFileName = provisioningProfile.getId()57 + CertificateService.PRIVATE_KEY_FILE_SUFFIX;58 String csrS3FileName = csrPathPrefix + CertificateService.CSR_FILE_SUFFIX;59 String privateKeyS3FileName = csrPathPrefix + CertificateService.PRIVATE_KEY_FILE_SUFFIX;60 File csrFile = File.createTempFile(csrFileName, CertificateService.CSR_EXTENSION);61 File privateKeyFile = File.createTempFile(privateKeyFileName, CertificateService.PEM_EXTENSION);62 certificateService.writeCSR(csrFile, privateKeyFile);63 log.info(String.format("Uploading CSR for provisioningProfile [%s] - [%s]", provisioningProfile.getId(),64 provisioningProfile.getName()));65 storageServiceFactory.getStorageService().addFile(csrS3FileName + CertificateService.CSR_EXTENSION, csrFile);66 storageServiceFactory.getStorageService().addFile(privateKeyS3FileName + CertificateService.PEM_EXTENSION, privateKeyFile);67 provisioningProfile.setStatus(ProvisioningProfileStatus.AWAITING_FOR_CERTIFICATE);68 provisioningProfile = this.provisioningProfileRepository.save(provisioningProfile);69 certificateService.setPreSignedURLs(provisioningProfile);70 } catch (Exception e) {71 log.error(e.getMessage(), e);72 }73 return provisioningProfile;74 }75 public ProvisioningProfile update(ProvisioningProfile provisioningProfile) throws TestsigmaException {76 try {77 MultipartFile cer = provisioningProfile.getCer();78 MultipartFile provFile = provisioningProfile.getProvisioningProfile();79 if (cer != null) {80 log.info(String.format("Uploading Certificate files(cer, crt, pem) for provisioningProfile [%s] - [%s]",81 provisioningProfile.getId(), provisioningProfile.getName()));82 updateCRT(cer, provisioningProfile);83 provisioningProfile.setStatus(ProvisioningProfileStatus.AWAITING_FOR_PROVISIONING_PROFILE);84 provisioningProfile.setUpdatedDate(new Timestamp(System.currentTimeMillis()));85 provisioningProfile = this.provisioningProfileRepository.save(provisioningProfile);86 }87 if (provFile != null) {88 log.info(String.format("Uploading Certificate mobile provisioning file for provisioningProfile [%s] - [%s]",89 provisioningProfile.getId(), provisioningProfile.getName()));90 File tempProvFile = File.createTempFile(provisioningProfile.getId() + CertificateService.MOBILE_PROVISION_FILE_SUFFIX,91 CertificateService.MOBILE_PROVISION_EXTENSION);92 provFile.transferTo(tempProvFile.toPath());93 parseDeviceInfoFromProvisioningProfile(tempProvFile, provisioningProfile);94 updateProvisioningProfile(tempProvFile, provisioningProfile);95 provisioningProfile.setStatus(ProvisioningProfileStatus.READY);96 provisioningProfile.setUpdatedDate(new Timestamp(System.currentTimeMillis()));97 provisioningProfileRepository.save(provisioningProfile);98 certificateService.setPreSignedURLs(provisioningProfile);99 ReSignTask reSignTask = new ReSignTask(webApplicationContext, provisioningProfile, null);100 ReSignTaskFactory.getInstance().startTask(reSignTask);101 }102 } catch (IOException e) {103 throw new TestsigmaException(e.getMessage(), e);104 }105 return provisioningProfile;106 }107 private void checkIfDevicesIsAlreadyProvisioned(List<String> deviceUDIDs, ProvisioningProfile provisioningProfile)108 throws TestsigmaException {109 List<ProvisioningProfileDevice> conflictingDevices = provisioningProfileDeviceService110 .findAllByDeviceUDIdInAndProvisioningProfileIdNot(deviceUDIDs, provisioningProfile.getId());111 if (conflictingDevices.size() > 0) {112 List<String> conflictingDeviceUDIDs = conflictingDevices.stream()113 .map(ProvisioningProfileDevice::getDeviceUDId).collect(Collectors.toList());114 String errorMsg = "These devices are already provisioned through difference provisioning profile"115 + conflictingDeviceUDIDs + " Devices with multiple provisioning profiles are not allowed.";116 throw new TestsigmaException(errorMsg, errorMsg);117 }118 }119 private void removeProvisionedDevicesNotInProvisioningProfile(List<String> deviceUDIDs, ProvisioningProfile provisioningProfile)120 throws TestsigmaException {121 List<ProvisioningProfileDevice> existingDevices = provisioningProfileDeviceService122 .findAllByProvisioningProfileId(provisioningProfile.getId());123 if (existingDevices.size() > 0) {124 List<String> existingDeviceUDIDs = existingDevices.stream()125 .map(ProvisioningProfileDevice::getDeviceUDId).collect(Collectors.toList());126 existingDeviceUDIDs.removeAll(deviceUDIDs);127 if (existingDeviceUDIDs.size() > 0) {128 log.info("Removing existing device from provisioning profile devices - " + existingDeviceUDIDs);129 List<ProvisioningProfileDevice> removableDevices = provisioningProfileDeviceService130 .findAllByDeviceUDIdIn(existingDeviceUDIDs);131 List<Long> removedAgentDeviceIds = removableDevices.stream()132 .map(ProvisioningProfileDevice::getAgentDeviceId).collect(Collectors.toList());133 List<TestDevice> testDeviceServices = testDeviceService134 .findAllByAgentDeviceIds(removedAgentDeviceIds);135 if (testDeviceServices.size() > 0) {136 List<Long> existingExecutionIds = testDeviceServices.stream()137 .map(TestDevice::getTestPlanId).collect(Collectors.toList());138 throw new TestsigmaException("There are bellow devices removed from provision profile but have executions ::"139 + existingExecutionIds);140 }141 provisioningProfileDeviceService.deleteAllByDeviceUDIDIn(existingDeviceUDIDs);142 }143 log.info("Final list of device UUID's post cleanup - " + deviceUDIDs);144 }145 }146 private void parseDeviceInfoFromProvisioningProfile(File tempProvFile, ProvisioningProfile provisioningProfile)147 throws TestsigmaException, IOException {148 List<String> deviceUDIDs = profileParserService.parseDevices(tempProvFile);149 String teamId = profileParserService.getTeamId(tempProvFile);150 log.info("Identified devices from provisioning profile - " + deviceUDIDs);151 log.info("Identified team id from provisioning profile - " + teamId);152 provisioningProfile.setDeviceUDIDs(deviceUDIDs);153 provisioningProfile.setTeamId(teamId);154 checkIfDevicesIsAlreadyProvisioned(deviceUDIDs, provisioningProfile);155 removeProvisionedDevicesNotInProvisioningProfile(deviceUDIDs, provisioningProfile);156 provisioningProfileDeviceService.create(deviceUDIDs, provisioningProfile);157 }158 private void updateCRT(MultipartFile cer, ProvisioningProfile provisioningProfile) throws TestsigmaException {159 try {160 String profilePathPrefix = certificateService.s3Prefix(provisioningProfile.getId());161 String certificateLocalName = provisioningProfile.getId()162 + CertificateService.CERTIFICATE_FILE_SUFFIX;163 String certificateS3Name = profilePathPrefix + CertificateService.CERTIFICATE_FILE_SUFFIX;164 File cerFile = File.createTempFile(certificateLocalName, CertificateService.CERTIFICATE_CER_EXTENSION);165 File crt = File.createTempFile(certificateLocalName, CertificateService.CERTIFICATE_CRT_EXTENSION);166 File pem = File.createTempFile(certificateLocalName, CertificateService.PEM_EXTENSION);167 cer.transferTo(cerFile.toPath());168 log.info(String.format("Uploading certificate(cer) for provisioningProfile [%s] - [%s]", provisioningProfile.getId(),169 provisioningProfile.getName()));170 storageServiceFactory.getStorageService().addFile(certificateS3Name + CertificateService.CERTIFICATE_CER_EXTENSION, cerFile);171 log.info(String.format("Uploading certificate(crt) for provisioningProfile [%s] - [%s]", provisioningProfile.getId(),172 provisioningProfile.getName()));173 certificateService.writeCRT(cerFile, crt);174 storageServiceFactory.getStorageService().addFile(certificateS3Name + CertificateService.CERTIFICATE_CRT_EXTENSION, crt);175 log.info(String.format("Uploading certificate(pem) for provisioningProfile [%s] - [%s]", provisioningProfile.getId(),176 provisioningProfile.getName()));177 certificateService.writePem(crt, pem);178 storageServiceFactory.getStorageService().addFile(certificateS3Name + CertificateService.PEM_EXTENSION, pem);179 } catch (Exception e) {180 throw new TestsigmaException(e.getMessage(), e);181 }182 }183 private void updateProvisioningProfile(File provFile, ProvisioningProfile provisioningProfile) throws IOException {184 log.debug(String.format("Uploading ProvisioningProfile for provisioningProfile [%s] - [%s]",185 provisioningProfile.getId(), provisioningProfile.getName()));186 String profilePathPrefix = certificateService.s3Prefix(provisioningProfile.getId());187 storageServiceFactory.getStorageService().addFile(profilePathPrefix + CertificateService.MOBILE_PROVISION_FILE_SUFFIX188 + CertificateService.MOBILE_PROVISION_EXTENSION, provFile);189 }190 public void destroy(Long id) throws ResourceNotFoundException {191 ProvisioningProfile profile = find(id);192 this.provisioningProfileRepository.delete(profile);193 }194}...
Source:CertificateService.java
...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) {111 return "/provisioning_profiles/" + profileId;112 }113 public List<File> unzipFiles(HttpResponse response, File csrOutput, File privateKeyOutput) throws IOException {114 List<File> res = new ArrayList<>();115 res.add(csrOutput);116 res.add(privateKeyOutput);117 File fileZip = File.createTempFile("csrAndPemopensource", ".zip");118 BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent());119 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fileZip));120 int inByte;121 while ((inByte = bis.read()) != -1) bos.write(inByte);122 bis.close();123 bos.close();124 byte[] buffer = new byte[1024];...
s3Prefix
Using AI Code Generation
1package com.testsigma.service;2import java.io.File;3import java.io.FileInputStream;4import java.io.FileNotFoundException;5import java.io.IOException;6import java.util.Properties;7import org.apache.commons.io.FileUtils;8import org.apache.commons.io.IOUtils;9import org.apache.commons.lang.StringUtils;10import org.apache.log4j.Logger;11import org.apache.log4j.PropertyConfigurator;12import org.springframework.beans.factory.annotation.Autowired;13import org.springframework.beans.factory.annotation.Value;14import org.springframework.stereotype.Service;15import org.springframework.web.multipart.MultipartFile;16import com.amazonaws.AmazonServiceException;17import com.amazonaws.auth.AWSCredentials;18import com.amazonaws.auth.AWSStaticCredentialsProvider;19import com.amazonaws.auth.BasicAWSCredentials;20import com.amazonaws.services.s3.AmazonS3;21import com.amazonaws.services.s3.AmazonS3ClientBuilder;22import com.amazonaws.services.s3.model.CannedAccessControlList;23import com.amazonaws.services.s3.model.ObjectMetadata;24import com.amazonaws.services.s3.model.PutObjectRequest;25import com.amazonaws.services.s3.transfer.TransferManager;26import com.amazonaws.services.s3.transfer.TransferManagerBuilder;27import com.amazonaws.services.s3.transfer.Upload;28import com.testsigma.config.ApplicationProperties;29import com.testsigma.config.Constants;30import com.testsigma.config.TestSigmaProperties;31import com.testsigma.exception.TestSigmaException;32import com.testsigma.util.FileUtil;33public class CertificateService {34private static final Logger logger = Logger.getLogger(CertificateService.class);35private TestSigmaProperties testSigmaProperties;36private ApplicationProperties applicationProperties;37private AWSCredentials awsCredentials;38private AmazonS3 s3client;39private String bucketName;40private String s3Prefix;41private TransferManager transferManager;42private String bucketRegion;43private String s3AccessKey;44private String s3SecretKey;45private String s3BucketName;46private String s3BucketRegion;47private String s3BucketPrefix;48private String s3BucketURL;49private String s3BucketURLPrefix;50private String s3BucketURLSuffix;51private String s3BucketURLSuffixWithSlash;52private String s3BucketURLSuffixWithoutSlash;53private String s3BucketURLSuffixWithSlashAndPrefix;54private String s3BucketURLSuffixWithoutSlashAndPrefix;55private String s3BucketURLSuffixWithPrefix;56private String s3BucketURLSuffixWithoutPrefix;57private String s3BucketURLSuffixWithSlashAndPrefixAndFileName;58private String s3BucketURLSuffixWithoutSlashAndPrefixAndFileName;
s3Prefix
Using AI Code Generation
1package com.testsigma.service;2public class CertificateService {3 public void s3Prefix(String s3Prefix) {4 this.s3Prefix = s3Prefix;5 }6}7package com.testsigma.service;8import com.testsigma.service.CertificateService;9public class CertificateService {10 public void s3Prefix(String s3Prefix) {11 this.s3Prefix = s3Prefix;12 }13}14package com.testsigma.service;15import com.testsigma.service.CertificateService;16public class CertificateService {17 public void s3Prefix(String s3Prefix) {18 this.s3Prefix = s3Prefix;19 }20}21package com.testsigma.service;22import com.testsigma.service.CertificateService;23public class CertificateService {24 public void s3Prefix(String s3Prefix) {25 this.s3Prefix = s3Prefix;26 }27}28package com.testsigma.service;29import com.testsigma.service.CertificateService;30public class CertificateService {31 public void s3Prefix(String s3Prefix) {32 this.s3Prefix = s3Prefix;33 }34}35package com.testsigma.service;36import com.testsigma.service.CertificateService;37public class CertificateService {38 public void s3Prefix(String s3Prefix) {39 this.s3Prefix = s3Prefix;40 }41}42package com.testsigma.service;43import com.testsigma.service.CertificateService;44public class CertificateService {45 public void s3Prefix(String s3Prefix) {46 this.s3Prefix = s3Prefix;47 }48}49package com.testsigma.service;50import com.testsigma.service.CertificateService;
s3Prefix
Using AI Code Generation
1package com.testsigma.service;2public class CertificateService {3 public static String s3Prefix(String s) {4 if (s.startsWith(prefix)) {5 return s.substring(prefix.length());6 }7 return s;8 }9}10package com.testsigma.service;11public class CertificateService {12 public static String s3Prefix(String s) {13 if (s.startsWith(prefix)) {14 return s.substring(prefix.length());15 }16 return s;17 }18}19package com.testsigma.service;20public class CertificateService {21 public static String s3Prefix(String s) {22 if (s.startsWith(prefix)) {23 return s.substring(prefix.length());24 }25 return s;26 }27}28package com.testsigma.service;29public class CertificateService {30 public static String s3Prefix(String s) {31 if (s.startsWith(prefix)) {32 return s.substring(prefix.length());33 }34 return s;35 }36}37package com.testsigma.service;38public class CertificateService {39 public static String s3Prefix(String s) {40 if (s.startsWith(prefix)) {41 return s.substring(prefix.length());42 }43 return s;44 }45}46package com.testsigma.service;47public class CertificateService {48 public static String s3Prefix(String s) {49 if (s.startsWith(prefix)) {50 return s.substring(prefix.length());51 }52 return s;53 }54}55package com.testsigma.service;56public class CertificateService {
s3Prefix
Using AI Code Generation
1package com.testsigma.service;2import java.io.IOException;3import java.util.ArrayList;4import java.util.List;5import org.apache.commons.lang3.RandomStringUtils;6import com.amazonaws.services.s3.AmazonS3;7import com.amazonaws.services.s3.AmazonS3ClientBuilder;8import com.amazonaws.services.s3.model.Bucket;9import com.amazonaws.services.s3.model.ObjectMetadata;10import com.amazonaws.services.s3.model.PutObjectRequest;11import com.amazonaws.services.s3.model.S3ObjectSummary;12import com.amazonaws.services.s3.model.S3VersionSummary;13import com.amazonaws.services.s3.model.VersionListing;14public class CertificateService {15 public static void main(String[] args) throws IOException {16 AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();17 List<Bucket> buckets = s3.listBuckets();18 String bucketName = "";19 for (Bucket b : buckets) {20 if (b.getName().startsWith("testsigma")) {21 bucketName = b.getName();22 break;23 }24 }25 List<String> keys = new ArrayList<>();26 VersionListing versionListing = s3.listVersions(bucketName, "");27 List<S3VersionSummary> versionSummaries = versionListing.getVersionSummaries();28 for (S3VersionSummary s : versionSummaries) {29 keys.add(s.getKey());30 }31 while (versionListing.isTruncated()) {32 versionListing = s3.listNextBatchOfVersions(versionListing);33 for (S3VersionSummary s : versionListing.getVersionSummaries()) {34 keys.add(s.getKey());35 }36 }37 ObjectMetadata metadata = new ObjectMetadata();38 metadata.setContentLength(0);39 String prefix = "testsigma" + RandomStringUtils.randomAlphanumeric(10);40 PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, prefix + "/", null, metadata);41 s3.putObject(putObjectRequest);42 System.out.println("Prefix: " + prefix);43 for (String key : keys) {44 if (key.startsWith(prefix)) {45 System.out.println("Found key: " + key);46 }47 }48 }49}50package com.testsigma.service;51import java.io.IOException;52import java.util.ArrayList;53import java.util.List;54import org.apache.commons.lang3.RandomStringUtils;55import com.amazonaws.services.s3.AmazonS3;56import
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!