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

Create component linked assets #28

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ orbs:
executors:
nxrm-maven-executor:
docker:
- image: circleci/openjdk:8-jdk
- image: cimg/openjdk:8.0
environment:
# limit max memory for JVM to allow more memory for non-JVM build processes (e.g. yarn)
MAVEN_OPTS: -Xmx2700m
Expand Down
4 changes: 2 additions & 2 deletions nexus-repository-terraform-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
<version>32.0.0-android</version>
</dependency>
<!--
Pax-Exam test driver - end
Expand All @@ -68,7 +68,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.4.1</version>
<version>2.13.4.2</version>
</dependency>

<!-- CVE-2020-17521 -->
Expand Down
2 changes: 1 addition & 1 deletion nexus-repository-terraform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.4.1</version>
<version>2.13.4.2</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.sonatype.nexus.plugins.terraform.internal;

import javax.inject.Named;
import javax.inject.Singleton;

import org.sonatype.nexus.repository.browse.AssetPathBrowseNodeGenerator;

/**
* Terraform places components at the same level as their assets.
*
* @since 0.0.8
*/

@Singleton
@Named(TerraformFormat.NAME)
public class TerraformBrowseNodeGenerator
extends AssetPathBrowseNodeGenerator
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
package org.sonatype.nexus.plugins.terraform.orient.internal;

import java.io.IOException;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map.Entry;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -110,24 +112,29 @@ private Content putTerraformPackage(final Content content,
StorageFacet storageFacet = facet(StorageFacet.class);

try (TempBlob tempBlob = storageFacet.createTempBlob(content.openInputStream(), TerraformDataAccess.HASH_ALGORITHMS)) {
Component component = findOrCreateComponent(assetPath);
Component component = findOrCreateComponent(assetPath, matcherState);

return findOrCreateAsset(tempBlob, content, assetKind, assetPath, component, matcherState);
}
}

@TransactionalStoreBlob
protected Component findOrCreateComponent(final String assetPath) {
protected Component findOrCreateComponent(final String assetPath, final TokenMatcher.State matcherState) {
StorageTx tx = UnitOfWork.currentTx();
Bucket bucket = tx.findBucket(getRepository());

String componentGroup = new File(assetPath).getParent();

Component component = terraformDataAccess.findComponent(tx,
getRepository(),
assetPath);
getRepository(), assetPath);

if (component == null) {
component = tx.createComponent(bucket, getRepository().getFormat())
.group(componentGroup)
.name(assetPath);
if (matcherState.getTokens().containsKey("version")) {
component.version(matcherState.getTokens().get("version"));
}
}
tx.saveComponent(component);

Expand Down Expand Up @@ -157,22 +164,24 @@ protected Content findOrCreateAsset(final TempBlob tempBlob,
Bucket bucket = tx.findBucket(getRepository());

Asset asset = terraformDataAccess.findAsset(tx, bucket, assetPath);
// @todo
// if (assetKind.equals(AssetKind.PROVIDER_ARCHIVE)) {
// if (asset == null) {
// asset = tx.createAsset(bucket, component);
// asset.name(assetPath);
// asset.formatAttributes().set(P_ASSET_KIND, assetKind.name());
// }
// } else {
if (asset == null) {

ArrayList<AssetKind> artifacts = new ArrayList<>(Arrays.asList(
AssetKind.PROVIDER_VERSION,
AssetKind.PROVIDER_VERSIONS,
AssetKind.PROVIDER_ARCHIVE)
);

if (asset == null) {
if (artifacts.contains(assetKind)) {
asset = tx.createAsset(bucket, component);
} else {
asset = tx.createAsset(bucket, getRepository().getFormat());
asset.name(assetPath);
for (String key : matcherState.getTokens().keySet()) {
asset.formatAttributes().set(key, matcherState.getTokens().get(key));
}
}
// }
asset.name(assetPath);
for (String key : matcherState.getTokens().keySet()) {
asset.formatAttributes().set(key, matcherState.getTokens().get(key));
}
}

return terraformDataAccess.saveAsset(tx, asset, tempBlob, content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.sonatype.nexus.repository.httpclient.HttpClientFacet
import org.sonatype.nexus.repository.purge.PurgeUnusedFacet
import org.sonatype.nexus.repository.search.ElasticSearchFacet
import org.sonatype.nexus.repository.security.SecurityHandler
import org.sonatype.nexus.repository.storage.DefaultComponentMaintenanceImpl
import org.sonatype.nexus.repository.storage.SingleAssetComponentMaintenance
import org.sonatype.nexus.repository.storage.StorageFacet
import org.sonatype.nexus.repository.storage.UnitOfWorkHandler
import org.sonatype.nexus.repository.view.ConfigurableViewFacet
Expand Down Expand Up @@ -83,7 +83,7 @@ abstract class TerraformRecipeSupport
HandlerContributor handlerContributor

@Inject
Provider<DefaultComponentMaintenanceImpl> componentMaintenanceFacet
Provider<SingleAssetComponentMaintenance> componentMaintenanceFacet

@Inject
Provider<HttpClientFacet> httpClientFacet
Expand Down