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

ReST API based on Raw repository API #19

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ out
# ci config for local ci build
.circleci/local-config.yml
venv*
/.metadata/
**/bin
**/target
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The table below outlines what version of Nexus Repository the plugin was built a
| v0.2.1 | 3.31.0-01 |
| v0.2.2 | 3.38.0-01 / 3.39.0.01 |
| v0.3.0 | \>= 3.41.0 |
| v0.3.1 | \>= 3.41.0 |

If a new version of Nexus Repository is released and the plugin needs changes, a new release will be made, and this
table will be updated to indicate which version of Nexus Repository it will function against. This is done on a time
Expand Down
2 changes: 1 addition & 1 deletion nexus-repository-ansiblegalaxy-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.sonatype.nexus.plugins</groupId>
<artifactId>nexus-repository-ansiblegalaxy-parent</artifactId>
<version>0.3.0</version>
<version>0.3.2</version>
</parent>

<artifactId>nexus-repository-ansiblegalaxy-it</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion nexus-repository-ansiblegalaxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.sonatype.nexus.plugins</groupId>
<artifactId>nexus-repository-ansiblegalaxy-parent</artifactId>
<version>0.3.0</version>
<version>0.3.2</version>
</parent>

<artifactId>nexus-repository-ansiblegalaxy</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2020-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.plugins.ansiblegalaxy.api;

import javax.inject.Inject;
import javax.inject.Named;

import org.sonatype.nexus.common.collect.NestedAttributesMap;
import org.sonatype.nexus.common.text.Strings2;
import org.sonatype.nexus.repository.Repository;
import org.sonatype.nexus.repository.rest.api.SimpleApiRepositoryAdapter;
import org.sonatype.nexus.repository.rest.api.model.AbstractApiRepository;
import org.sonatype.nexus.repository.routing.RoutingRuleStore;
import org.sonatype.nexus.repository.types.HostedType;
import org.sonatype.nexus.repository.types.ProxyType;

import org.sonatype.nexus.plugins.ansiblegalaxy.AnsibleGalaxyFormat;
import org.sonatype.nexus.plugins.ansiblegalaxy.AnsibleGalaxyAttributes;
import org.sonatype.nexus.plugins.ansiblegalaxy.AnsibleGalaxyHostedApiRepository;
import org.sonatype.nexus.plugins.ansiblegalaxy.AnsibleGalaxyProxyApiRepository;

@Named(AnsibleGalaxyFormat.NAME)
public class AnsibleGalaxyApiRepositoryAdapter
extends SimpleApiRepositoryAdapter
{
private static final String ANSIBLEGALAXY = "ansiblegalaxy";

@Inject
public AnsibleGalaxyApiRepositoryAdapter(final RoutingRuleStore routingRuleStore) {
super(routingRuleStore);
}

@Override
public AbstractApiRepository adapt(final Repository repository) {
boolean online = repository.getConfiguration().isOnline();
String name = repository.getName();
String url = repository.getUrl();

switch( repository.getType().toString()) {
case HostedType.NAME:
return new AnsibleGalaxyHostedApiRepository(
repository.getName(),
repository.getUrl(),
repository.getConfiguration().isOnline(),
getHostedStorageAttributes(repository),
getCleanupPolicyAttributes(repository),
getComponentAttributes(repository),
createAnsibleGalaxyAttributes(repository)
);
case ProxyType.NAME:
return new AnsibleGalaxyProxyApiRepository(
repository.getName(),
repository.getUrl(),
repository.getConfiguration().isOnline(),
getHostedStorageAttributes(repository),
getCleanupPolicyAttributes(repository),
getProxyAttributes(repository),
getNegativeCacheAttributes(repository),
getHttpClientAttributes(repository),
getRoutingRuleName(repository),
getReplicationAttributes(repository),
createAnsibleGalaxyAttributes(repository)
);
default:
return super.adapt(repository);
}
}

private AnsibleGalaxyAttributes createAnsibleGalaxyAttributes(final Repository repository) {
String disposition = repository.getConfiguration().attributes(ANSIBLEGALAXY).get("contentDisposition", String.class);
return new AnsibleGalaxyAttributes(disposition);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2020-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.plugins.ansiblegalaxy;

import javax.validation.constraints.NotEmpty;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;

public class AnsibleGalaxyAttributes
{
@ApiModelProperty(value = "Content Disposition",
allowableValues = "INLINE,ATTACHMENT", example = "ATTACHMENT")
@NotEmpty
private final String contentDisposition;

@JsonCreator
public AnsibleGalaxyAttributes(
@JsonProperty("contentDisposition") final String contentDisposition) {
this.contentDisposition = contentDisposition;
}

public String getContentDisposition() {
return contentDisposition;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2020-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.plugins.ansiblegalaxy;

import javax.validation.constraints.NotNull;

import org.sonatype.nexus.plugins.ansiblegalaxy.AnsibleGalaxyFormat;
import org.sonatype.nexus.repository.rest.api.model.CleanupPolicyAttributes;
import org.sonatype.nexus.repository.rest.api.model.ComponentAttributes;
import org.sonatype.nexus.repository.rest.api.model.HostedStorageAttributes;
import org.sonatype.nexus.repository.rest.api.model.SimpleApiHostedRepository;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.sonatype.nexus.plugins.ansiblegalaxy.AnsibleGalaxyAttributes;

/**
* @since 3.41
*/
public class AnsibleGalaxyHostedApiRepository
extends SimpleApiHostedRepository
{
@NotNull
private final AnsibleGalaxyAttributes ansiblegalaxy;

@JsonCreator
public AnsibleGalaxyHostedApiRepository(
@JsonProperty("name") final String name,
@JsonProperty("url") final String url,
@JsonProperty("online") final Boolean online,
@JsonProperty("storage") final HostedStorageAttributes storage,
@JsonProperty("cleanup") final CleanupPolicyAttributes cleanup,
@JsonProperty("component") final ComponentAttributes component,
@JsonProperty("ansiblegalaxy") final AnsibleGalaxyAttributes ansiblegalaxy)
{
super(name, AnsibleGalaxyFormat.NAME, url, online, storage, cleanup, component);
this.ansiblegalaxy = ansiblegalaxy;
}

public AnsibleGalaxyAttributes getAnsibleGalaxy() {
return ansiblegalaxy;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2020-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.plugins.ansiblegalaxy;

import javax.validation.constraints.NotNull;

import org.sonatype.nexus.plugins.ansiblegalaxy.AnsibleGalaxyFormat;
import org.sonatype.nexus.repository.rest.api.model.CleanupPolicyAttributes;
import org.sonatype.nexus.repository.rest.api.model.HttpClientAttributes;
import org.sonatype.nexus.repository.rest.api.model.NegativeCacheAttributes;
import org.sonatype.nexus.repository.rest.api.model.ProxyAttributes;
import org.sonatype.nexus.repository.rest.api.model.ReplicationAttributes;
import org.sonatype.nexus.repository.rest.api.model.SimpleApiProxyRepository;
import org.sonatype.nexus.repository.rest.api.model.StorageAttributes;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

import org.sonatype.nexus.plugins.ansiblegalaxy.AnsibleGalaxyAttributes;

/**
* @since 3.41
*/
public class AnsibleGalaxyProxyApiRepository
extends SimpleApiProxyRepository
{

@NotNull
private final AnsibleGalaxyAttributes ansiblegalaxy;

public AnsibleGalaxyProxyApiRepository(
@JsonProperty("name") final String name,
@JsonProperty("url") final String url,
@JsonProperty("online") final Boolean online,
@JsonProperty("storage") final StorageAttributes storage,
@JsonProperty("cleanup") final CleanupPolicyAttributes cleanup,
@JsonProperty("proxy") final ProxyAttributes proxy,
@JsonProperty("negativeCache") final NegativeCacheAttributes negativeCache,
@JsonProperty("httpClient") final HttpClientAttributes httpClient,
@JsonProperty("routingRuleName") final String routingRuleName,
@JsonProperty("replication") @JsonInclude(value= Include.NON_EMPTY, content=Include.NON_NULL)
final ReplicationAttributes replication,
@JsonProperty("ansiblegalaxy") final AnsibleGalaxyAttributes ansiblegalaxy)
{
super(name, AnsibleGalaxyFormat.NAME, url, online, storage, cleanup, proxy, negativeCache, httpClient, routingRuleName, replication);
this.ansiblegalaxy = ansiblegalaxy;
}

public AnsibleGalaxyAttributes getAnsibleGalaxy() {
return ansiblegalaxy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum AssetKind {
API_METADATA(METADATA),
COLLECTION_DETAIL(METADATA),
COLLECTION_VERSION_LIST(METADATA),
COLLECTION_VERSION_LIST_LIMIT(METADATA),
COLLECTION_VERSION_DETAIL(METADATA),
COLLECTION_ARTIFACT(CONTENT),
ROLE_SEARCH(METADATA),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2020-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.plugins.ansiblegalaxy;

public enum ContentDisposition {
INLINE("inline"),
ATTACHMENT("attachment");

private final String value;

ContentDisposition(final String value) {
this.value = value;
}

public String getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2020-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
package org.sonatype.nexus.plugins.ansiblegalaxy;

import javax.annotation.Nonnull;
import javax.inject.Named;
import javax.inject.Singleton;

import org.sonatype.nexus.repository.view.Context;
import org.sonatype.nexus.repository.view.Handler;
import org.sonatype.nexus.repository.view.Response;

import static org.sonatype.nexus.repository.http.HttpMethods.GET;


public class ContentDispositionHandler
implements Handler
{
public static final String CONTENT_DISPOSITION_CONFIG_KEY = "contentDisposition";

@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
Response response = context.proceed();
String action = context.getRequest().getAction();
if (GET.equals(action)) {
String contentDisposition = context.getRepository().getConfiguration().attributes("ansiblegalaxy")
.get(CONTENT_DISPOSITION_CONFIG_KEY, String.class, ContentDisposition.INLINE.name());

response.getHeaders().replace("Content-Disposition", ContentDisposition.valueOf(contentDisposition).getValue());
}
return response;
}
}
Loading