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

[#112] Enable GPG checks of channel artifacts #268

Merged
merged 10 commits into from
Dec 19, 2024
53 changes: 48 additions & 5 deletions core/src/main/java/org/wildfly/channel/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class Channel {
private BlocklistCoordinate blocklistCoordinate;
private ChannelManifestCoordinate manifestCoordinate;
private NoStreamStrategy noStreamStrategy = NoStreamStrategy.NONE;
private Boolean gpgCheck;
private List<String> gpgUrls;

// no-arg constructor for maven plugins
public Channel() {
Expand All @@ -56,7 +58,7 @@ public Channel() {
/**
* Representation of a Channel resource using the current schema version.
*
* @see #Channel(String, String, String, Vendor, List, ChannelManifestCoordinate, BlocklistCoordinate, NoStreamStrategy)
* @see #Channel(String, String, String, Vendor, List, ChannelManifestCoordinate, BlocklistCoordinate, NoStreamStrategy, Boolean, String)
*/
public Channel(String name,
String description,
Expand All @@ -72,7 +74,8 @@ public Channel(String name,
repositories,
manifestCoordinate,
blocklistCoordinate,
noStreamStrategy);
noStreamStrategy,
null, null);
}

@JsonCreator
Expand All @@ -84,7 +87,9 @@ public Channel(@JsonProperty(value = "schemaVersion", required = true) String sc
@JsonInclude(NON_EMPTY) List<Repository> repositories,
@JsonProperty(value = "manifest") ChannelManifestCoordinate manifestCoordinate,
@JsonProperty(value = "blocklist") @JsonInclude(NON_EMPTY) BlocklistCoordinate blocklistCoordinate,
@JsonProperty(value = "resolve-if-no-stream") NoStreamStrategy noStreamStrategy) {
@JsonProperty(value = "resolve-if-no-stream") NoStreamStrategy noStreamStrategy,
@JsonProperty(value = "gpg-check") Boolean gpgCheck,
@JsonProperty(value = "gpg-urls") List<String> gpgUrls) {
this.schemaVersion = schemaVersion;
this.name = name;
this.description = description;
Expand All @@ -93,6 +98,8 @@ public Channel(@JsonProperty(value = "schemaVersion", required = true) String sc
this.blocklistCoordinate = blocklistCoordinate;
this.manifestCoordinate = manifestCoordinate;
this.noStreamStrategy = (noStreamStrategy != null) ? noStreamStrategy: NoStreamStrategy.NONE;
this.gpgCheck = gpgCheck;
this.gpgUrls = (gpgUrls != null) ? gpgUrls : emptyList();
}

public String getSchemaVersion() {
Expand Down Expand Up @@ -137,6 +144,25 @@ public NoStreamStrategy getNoStreamStrategy() {
return noStreamStrategy;
}

// using a private method to return a Boolean for serializing
// this way channels without gpg-check field can be read/written without modifications
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonProperty("gpg-check")
private Boolean _isGpgCheck() {
return gpgCheck;
}

@JsonIgnore
public boolean isGpgCheck() {
return gpgCheck!=null?gpgCheck:false;
}

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonProperty("gpg-urls")
public List<String> getGpgUrls() {
return gpgUrls;
}

/**
* Strategies for resolving artifact versions if it is not listed in streams.
* <ul>
Expand Down Expand Up @@ -197,22 +223,26 @@ public static class Builder {
private NoStreamStrategy strategy;
private String description;
private Vendor vendor;
private Boolean gpgCheck;
private List<String> gpgUrls;

public Builder() {
}

public Builder(Channel from) {
this.name = from.getName();
this.repositories = new ArrayList<>(from.getRepositories());
this.repositories = from.getRepositories() == null ? null : new ArrayList<>(from.getRepositories());
this.manifestCoordinate = from.getManifestCoordinate();
this.blocklistCoordinate = from.getBlocklistCoordinate();
this.strategy = from.getNoStreamStrategy();
this.description = from.getDescription();
this.vendor = from.getVendor();
this.gpgCheck = from._isGpgCheck();
this.gpgUrls = from.getGpgUrls() == null ? null : new ArrayList<>(from.getGpgUrls());
}

public Channel build() {
return new Channel(name, description, vendor, repositories, manifestCoordinate, blocklistCoordinate, strategy);
return new Channel(ChannelMapper.CURRENT_SCHEMA_VERSION, name, description, vendor, repositories, manifestCoordinate, blocklistCoordinate, strategy, gpgCheck, gpgUrls);
}

public Builder setName(String name) {
Expand Down Expand Up @@ -278,5 +308,18 @@ public Builder setResolveStrategy(NoStreamStrategy strategy) {
this.strategy = strategy;
return this;
}

public Builder setGpgCheck(boolean gpgCheck) {
this.gpgCheck = gpgCheck;
return this;
}

public Builder addGpgUrl(String gpgUrl) {
if (this.gpgUrls == null) {
this.gpgUrls = new ArrayList<>();
}
this.gpgUrls.add(gpgUrl);
return this;
}
}
}
15 changes: 11 additions & 4 deletions core/src/main/java/org/wildfly/channel/ChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void init(MavenVersionsResolver.Factory factory, List<ChannelImpl> channels) {
return;
}

resolver = factory.create(channelDefinition.getRepositories());
resolver = factory.create(channelDefinition);

final Channel.Builder resolvedChannelBuilder = new Channel.Builder(channelDefinition);
if (channelDefinition.getManifestCoordinate() != null) {
Expand Down Expand Up @@ -149,9 +149,16 @@ private ChannelImpl createNewChannelFromMaven(MavenVersionsResolver.Factory fact
version = latest.orElseThrow(() -> new RuntimeException(String.format("Can not determine the latest version for Maven artifact %s:%s:%s:%s",
groupId, artifactId, ChannelManifest.EXTENSION, ChannelManifest.CLASSIFIER)));
}
final ChannelImpl requiredChannel = new ChannelImpl(new Channel(null, null, null, channelDefinition.getRepositories(),
new ChannelManifestCoordinate(groupId, artifactId, version), null,
Channel.NoStreamStrategy.NONE));
final Channel requiredChannelDefinition = new Channel.Builder(channelDefinition)
.setName(null)
.setDescription(null)
.setVendor(null)
.setManifestCoordinate(groupId, artifactId, version)
.setResolveStrategy(Channel.NoStreamStrategy.NONE)
.build();

final ChannelImpl requiredChannel = new ChannelImpl(requiredChannelDefinition);

try {
requiredChannel.init(factory, channels);
} catch (UnresolvedMavenArtifactException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,31 @@ public ChannelManifestCoordinate(URL url) {
super(url);
}

public ChannelManifestCoordinate(URL url, URL signatureUrl) {
super(url, signatureUrl);
}

public ChannelManifestCoordinate() {
super(ChannelManifest.CLASSIFIER, ChannelManifest.EXTENSION);
}

public static ChannelManifestCoordinate create(String url,
MavenCoordinate gav) throws MalformedURLException {
return create(url, null, gav);
}

@JsonCreator
public static ChannelManifestCoordinate create(@JsonProperty(value = "url") String url, @JsonProperty(value = "maven") MavenCoordinate gav) throws MalformedURLException {
public static ChannelManifestCoordinate create(@JsonProperty(value = "url") String url,
@JsonProperty(value = "signature-url") String signatureUrl,
@JsonProperty(value = "maven") MavenCoordinate gav) throws MalformedURLException {
if (gav != null) {
if (gav.getVersion() == null || gav.getVersion().isEmpty()) {
return new ChannelManifestCoordinate(gav.getGroupId(), gav.getArtifactId());
} else {
return new ChannelManifestCoordinate(gav.getGroupId(), gav.getArtifactId(), gav.getVersion());
}
} else {
return new ChannelManifestCoordinate(new URL(url));
return new ChannelManifestCoordinate(new URL(url), signatureUrl == null ? null : new URL(signatureUrl));
}
}

Expand All @@ -81,4 +92,10 @@ private boolean isEmpty(String text) {
public URL getUrl() {
return super.getUrl();
}

@JsonProperty(value = "signature-url")
@JsonInclude(NON_NULL)
public URL getSignatureUrl() {
return super.getSignatureUrl();
}
}
5 changes: 4 additions & 1 deletion core/src/main/java/org/wildfly/channel/ChannelMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public class ChannelMapper {

public static final String SCHEMA_VERSION_1_0_0 = "1.0.0";
public static final String SCHEMA_VERSION_2_0_0 = "2.0.0";
public static final String CURRENT_SCHEMA_VERSION = SCHEMA_VERSION_2_0_0;
public static final String SCHEMA_VERSION_2_1_0 = "2.1.0";
public static final String CURRENT_SCHEMA_VERSION = SCHEMA_VERSION_2_1_0;

private static final String SCHEMA_1_0_0_FILE = "org/wildfly/channel/v1.0.0/schema.json";
private static final String SCHEMA_2_0_0_FILE = "org/wildfly/channel/v2.0.0/schema.json";
private static final String SCHEMA_2_1_0_FILE = "org/wildfly/channel/v2.1.0/schema.json";
private static final YAMLFactory YAML_FACTORY = new YAMLFactory()
.configure(YAMLGenerator.Feature.INDENT_ARRAYS_WITH_INDICATOR, true);
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(YAML_FACTORY)
Expand All @@ -71,6 +73,7 @@ public class ChannelMapper {
}
SCHEMAS.put(SCHEMA_VERSION_1_0_0, SCHEMA_FACTORY.getSchema(ChannelMapper.class.getClassLoader().getResourceAsStream(SCHEMA_1_0_0_FILE)));
SCHEMAS.put(SCHEMA_VERSION_2_0_0, SCHEMA_FACTORY.getSchema(ChannelMapper.class.getClassLoader().getResourceAsStream(SCHEMA_2_0_0_FILE)));
SCHEMAS.put(SCHEMA_VERSION_2_1_0, SCHEMA_FACTORY.getSchema(ChannelMapper.class.getClassLoader().getResourceAsStream(SCHEMA_2_1_0_FILE)));
}

private static JsonSchema getSchema(JsonNode node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ChannelMetadataCoordinate {
private String extension;

private URL url;
protected URL signatureUrl;

protected ChannelMetadataCoordinate() {
}
Expand All @@ -57,6 +58,12 @@ public ChannelMetadataCoordinate(URL url) {
requireNonNull(url);
}

public ChannelMetadataCoordinate(URL url, URL signatureUrl) {
this(null, null, null, null, null, url);
requireNonNull(url);
this.signatureUrl = signatureUrl;
}

private ChannelMetadataCoordinate(String groupId, String artifactId, String version, String classifier, String extension, URL url) {
this.groupId = groupId;
this.artifactId = artifactId;
Expand Down Expand Up @@ -94,6 +101,10 @@ public String getExtension() {
return extension;
}

public URL getSignatureUrl() {
return signatureUrl;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Loading
Loading