Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1049 Operator: issue personal license pack to dedicated folder #1052

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@
import org.eclipse.passage.lic.base.diagnostic.NoSevereErrors;
import org.eclipse.passage.lic.base.diagnostic.SumOfLists;
import org.eclipse.passage.lic.base.io.FloatingFileExtension;
import org.eclipse.passage.lic.base.io.UserHomeProductResidence;
import org.eclipse.passage.lic.emf.validation.ErrorMessages;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
import org.eclipse.passage.lic.licenses.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.licenses.model.api.FloatingLicensePack;
import org.eclipse.passage.lic.licenses.model.api.LicenseRequisites;
import org.eclipse.passage.lic.licenses.model.api.ProductRef;
import org.eclipse.passage.lic.licenses.model.api.UserGrant;
import org.eclipse.passage.loc.internal.agreements.AgreementRegistry;
Expand Down Expand Up @@ -95,7 +93,7 @@ ServiceInvocationResult<IssuedFloatingLicense> issue(FloatingLicensePack pack,
private ServiceInvocationResult<IssuedFloatingLicense> persistLicenseFiles(FloatingLicensePack pack,
Collection<FloatingLicenseAccess> configs) {
LicensedProduct product = product(pack.getLicense().getProduct());
Path residence = residence(pack.getLicense());
Path residence = new LicensePackResidence(pack.getLicense()).get();
ServiceInvocationResult<List<Path>> license = //
persist(pack, product, residence, decryptedFile(pack), encryptedFile(pack));
BinaryOperator<ServiceInvocationResult<List<Path>>> sum = new BaseServiceInvocationResult.Sum<>(
Expand Down Expand Up @@ -149,14 +147,6 @@ private ServiceInvocationResult<List<Path>> replicateKey(LicensedProduct product
return new BaseServiceInvocationResult<>(Collections.singletonList(key));
}

private Path residence(LicenseRequisites license) {
return new UserHomeProductResidence(//
license.getProduct().getIdentifier(), //
license.getProduct().getVersion())//
.get()//
.resolve(license.getIdentifier());
}

private LicensedProduct product(ProductRef ref) {
return new BaseLicensedProduct(ref.getIdentifier(), ref.getVersion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.eclipse.passage.lic.base.BaseLicensedProduct;
import org.eclipse.passage.lic.base.BaseServiceInvocationResult;
import org.eclipse.passage.lic.base.io.PassageFileExtension;
import org.eclipse.passage.lic.base.io.UserHomeProductResidence;
import org.eclipse.passage.lic.emf.validation.ErrorMessages;
import org.eclipse.passage.lic.internal.licenses.model.AssignGrantIdentifiers;
import org.eclipse.passage.lic.licenses.LicensePlanDescriptor;
Expand Down Expand Up @@ -85,8 +84,7 @@ ServiceInvocationResult<IssuedLicense> issue(Supplier<PersonalLicensePack> templ
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_error_io, e));
}
LicensedProduct product = product(license);
Path path = new UserHomeProductResidence(product).get();
Path path = new LicensePackResidence(license.getLicense()).get();

Path decrypted;
try {
Expand All @@ -98,7 +96,7 @@ ServiceInvocationResult<IssuedLicense> issue(Supplier<PersonalLicensePack> templ

Path encrypted;
try {
encrypted = encrypted(license, product, decrypted);
encrypted = encrypted(license, product(license), decrypted);
} catch (LicensingException e) {
return new BaseServiceInvocationResult<>(new Trouble(new LicenseIssuingFailed(),
LicensesCoreMessages.LicenseOperatorServiceImpl_export_error, e));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2022 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.loc.internal.licenses.core;

import java.nio.file.Path;
import java.util.function.Supplier;

import org.eclipse.passage.lic.base.io.UserHomeProductResidence;
import org.eclipse.passage.lic.licenses.model.api.LicenseRequisites;

final class LicensePackResidence implements Supplier<Path> {

private final LicenseRequisites license;

LicensePackResidence(LicenseRequisites license) {
this.license = license;
}

@Override
public Path get() {
return existing(residence());
}

private Path residence() {
return new UserHomeProductResidence(//
license.getProduct().getIdentifier(), //
license.getProduct().getVersion())//
.get()//
.resolve(license.getIdentifier());
}

private Path existing(Path folder) {
folder.toFile().mkdirs();
return folder;
}

}