org.sonatype.nexus.repository.view.matchers.token.TokenMatcher Java Examples

The following examples show how to use org.sonatype.nexus.repository.view.matchers.token.TokenMatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OrientPyPiProxyFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Content store(final Context context, final Content content) throws IOException {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  if (assetKind.equals(AssetKind.SEARCH)) {
    return content;  // we do not store search results
  }
  TokenMatcher.State state = matcherState(context);
  switch (assetKind) {
    case ROOT_INDEX:
      return putRootIndex(content);
    case INDEX:
      String name = name(state);
      return putIndex(name, content);
    case PACKAGE:
      return putPackage(path(state), content);
    default:
      throw new IllegalStateException();
  }
}
 
Example #2
Source File: GolangProxyFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nullable
@Override
protected Content getCachedContent(final Context context) throws IOException {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  TokenMatcher.State matcherState = golangPathUtils.matcherState(context);
  switch (assetKind) {
    case INFO:
    case MODULE:
    case PACKAGE:
      return getAsset(golangPathUtils.assetPath(matcherState));
    case LIST:
      return getAsset(golangPathUtils.listPath(matcherState));
    case LATEST:
      return getAsset(golangPathUtils.latestPath(matcherState));
    default:
      throw new IllegalStateException("Received an invalid AssetKind of type: " + assetKind.name());
  }
}
 
Example #3
Source File: ComposerHostedUploadHandlerTest.java    From nexus-repository-composer with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testHandle() throws Exception {
  when(repository.facet(ComposerHostedFacet.class)).thenReturn(composerHostedFacet);
  when(request.getPayload()).thenReturn(payload);
  when(context.getRepository()).thenReturn(repository);
  when(context.getAttributes()).thenReturn(attributes);
  when(context.getRequest()).thenReturn(request);

  when(attributes.require(TokenMatcher.State.class)).thenReturn(state);
  when(state.getTokens()).thenReturn(tokens);
  when(tokens.get(VENDOR_TOKEN)).thenReturn("testvendor");
  when(tokens.get(PROJECT_TOKEN)).thenReturn("testproject");
  when(tokens.get(VERSION_TOKEN)).thenReturn("testversion");

  Response response = underTest.handle(context);
  assertThat(response.getStatus().getCode(), is(200));
  assertThat(response.getPayload(), is(nullValue()));

  verify(composerHostedFacet).upload("testvendor", "testproject", "testversion", payload);
}
 
Example #4
Source File: NpmHandlers.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  State state = context.getAttributes().require(TokenMatcher.State.class);
  Repository repository = context.getRepository();
  log.debug("[getPackage] repository: {} tokens: {}", repository.getName(), state.getTokens());

  NpmPackageId packageId = packageId(state);
  Content content = repository.facet(NpmHostedFacet.class)
      .getDistTags(packageId);
  if (content != null) {
    return NpmResponses.ok(content);
  }
  else {
    return NpmResponses.packageNotFound(packageId);
  }
}
 
Example #5
Source File: NpmHandlers.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  State state = context.getAttributes().require(TokenMatcher.State.class);
  Repository repository = context.getRepository();
  log.debug("[deletePackage] repository: {} tokens: {}", repository.getName(), state.getTokens());

  NpmPackageId packageId = packageId(state);
  Set<String> deleted = repository.facet(NpmHostedFacet.class).deletePackage(packageId, revision(state));
  if (!deleted.isEmpty()) {
    return NpmResponses.ok();
  }
  else {
    return NpmResponses.packageNotFound(packageId);
  }
}
 
Example #6
Source File: OrientPyPiProxyFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nullable
@Override
protected Content getCachedContent(final Context context) throws IOException {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  if (assetKind.equals(AssetKind.SEARCH)) {
    return null;  // we do not store search results
  }
  TokenMatcher.State state = matcherState(context);
  switch (assetKind) {
    case ROOT_INDEX:
      return getAsset(INDEX_PATH_PREFIX);
    case INDEX:
      return rewriteIndex(name(state));
    case PACKAGE:
      return getAsset(path(state));
    default:
      throw new IllegalStateException();
  }
}
 
Example #7
Source File: NpmHandlers.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  State state = context.getAttributes().require(TokenMatcher.State.class);
  Repository repository = context.getRepository();
  log.debug("[deleteTarball] repository: {} tokens: {}", repository.getName(), state.getTokens());

  NpmPackageId packageId = packageId(state);
  String tarballName = tarballName(state);
  Set<String> deleted = repository.facet(NpmHostedFacet.class).deleteTarball(packageId, tarballName);
  if (!deleted.isEmpty()) {
    return NpmResponses.ok();
  }
  else {
    return NpmResponses.tarballNotFound(packageId, tarballName);
  }
}
 
Example #8
Source File: ComposerProxyFacetImplTest.java    From nexus-repository-composer with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void storeZipball() throws Exception {
  when(contextAttributes.require(AssetKind.class)).thenReturn(ZIPBALL);
  when(contextAttributes.require(TokenMatcher.State.class)).thenReturn(state);

  when(composerContentFacet.put(ZIPBALL_PATH, content, ZIPBALL)).thenReturn(content);

  when(state.getTokens()).thenReturn(new ImmutableMap.Builder<String, String>()
      .put("vendor", "vendor")
      .put("project", "project")
      .put("version", "version")
      .put("name", "project-version")
      .build());

  assertThat(underTest.store(context, content), is(content));

  verify(composerContentFacet).put(ZIPBALL_PATH, content, ZIPBALL);
}
 
Example #9
Source File: ComposerProxyFacetImplTest.java    From nexus-repository-composer with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void getUrlZipball() throws Exception {
  when(contextAttributes.require(AssetKind.class)).thenReturn(ZIPBALL);
  when(contextAttributes.require(TokenMatcher.State.class)).thenReturn(state);

  when(viewFacet.dispatch(any(Request.class), eq(context))).thenReturn(response);
  when(composerJsonProcessor.getDistUrl("vendor", "project", "version", payload)).thenReturn("distUrl");

  when(state.getTokens()).thenReturn(new ImmutableMap.Builder<String, String>()
      .put("vendor", "vendor")
      .put("project", "project")
      .put("version", "version")
      .put("name", "project-version")
      .build());

  assertThat(underTest.getUrl(context), is("distUrl"));
}
 
Example #10
Source File: ComposerProxyFacetImplTest.java    From nexus-repository-composer with Eclipse Public License 1.0 6 votes vote down vote up
@Test(expected = NonResolvableProviderJsonException.class)
public void getUrlZipballMissingProviderJson() throws Exception {
  when(contextAttributes.require(AssetKind.class)).thenReturn(ZIPBALL);
  when(contextAttributes.require(TokenMatcher.State.class)).thenReturn(state);

  when(viewFacet.dispatch(any(Request.class), eq(context))).thenReturn(response);
  when(response.getPayload()).thenReturn(null);

  when(state.getTokens()).thenReturn(new ImmutableMap.Builder<String, String>()
      .put("vendor", "vendor")
      .put("project", "project")
      .put("version", "version")
      .put("name", "project-version")
      .build());

  underTest.getUrl(context);
}
 
Example #11
Source File: ConanUrlIndexer.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
public String updateAbsoluteUrls(final Context context,
                                 final Content content,
                                 final Repository repository) throws IOException
{
  Map<String, URL> downloadUrlContents = readIndex(content.openInputStream());
  Map<String, String> remappedContents = new HashMap<>();

  State state = context.getAttributes().require(TokenMatcher.State.class);
  ConanCoords coords = OrientConanProxyHelper.convertFromState(state);

  for (Map.Entry<String, URL> entry : downloadUrlContents.entrySet()) {
    String fileName = entry.getKey();
    AssetKind assetKind = OrientConanProxyHelper.ASSET_KIND_FILENAMES.get(fileName);
    remappedContents.put(entry.getKey(), repository.getUrl() + "/" + getProxyAssetPath(coords, assetKind));
  }

  return MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(remappedContents);
}
 
Example #12
Source File: NpmHandlers.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  State state = context.getAttributes().require(TokenMatcher.State.class);
  Repository repository = context.getRepository();
  log.debug("[putDistTags] repository: {} tokens: {}", repository.getName(), state.getTokens());

  try {
    repository.facet(NpmHostedFacet.class)
        .deleteDistTags(packageId(state), state.getTokens().get(T_PACKAGE_TAG), context.getRequest().getPayload());
    return NpmResponses.ok();
  }
  catch (IOException e) { //NOSONAR
    return NpmResponses.badRequest(e.getMessage());
  }
}
 
Example #13
Source File: NpmHandlers.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  State state = context.getAttributes().require(TokenMatcher.State.class);
  Repository repository = context.getRepository();
  log.debug("[putDistTags] repository: {} tokens: {}", repository.getName(), state.getTokens());

  try {
    repository.facet(NpmHostedFacet.class)
        .putDistTags(packageId(state), state.getTokens().get(T_PACKAGE_TAG), context.getRequest().getPayload());
    return NpmResponses.ok();
  }
  catch (IOException e) { //NOSONAR
    return NpmResponses.badRequest(e.getMessage());
  }
}
 
Example #14
Source File: ConanHostedRecipeTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnConanfileUploadPackage() {
  when(request.getAction()).thenReturn(PUT);
  when(request.getPath()).thenReturn("/v1/conans/group/project/2.1.1/stable/packages/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/conanfile.py");

  assertTrue(ConanRoutes.uploadConanfile().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("group")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("project")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
  assertThat(matcherState.getTokens().get("sha"), is(equalTo("5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")));
}
 
Example #15
Source File: GolangPathUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Utility method encapsulating getting a particular token by name from a matcher, including preconditions.
 */
private String match(final TokenMatcher.State state, final String name) {
  checkNotNull(state);
  String result = state.getTokens().get(name);
  checkNotNull(result);
  return result;
}
 
Example #16
Source File: ConanHostedRecipeTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnConanPackage() {
  when(request.getAction()).thenReturn(POST);
  when(request.getPath()).thenReturn("/v1/conans/project/2.1.1/group/stable/packages/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/upload_urls");

  assertTrue(ConanRoutes.uploadUrls().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("group")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("project")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
  assertThat(matcherState.getTokens().get("sha"), is(equalTo("5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9")));
}
 
Example #17
Source File: ConanHostedRecipeTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnConanUploadManifest() {
  when(request.getAction()).thenReturn(PUT);
  when(request.getPath()).thenReturn("/v1/conans/group/project/2.1.1/stable/conanmanifest.txt");

  assertTrue(ConanRoutes.uploadManifest().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("group")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("project")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
}
 
Example #18
Source File: ConanHostedRecipeTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnConaninfoUpload() {
  when(request.getAction()).thenReturn(PUT);
  when(request.getPath()).thenReturn("/v1/conans/group/project/2.1.1/stable/conaninfo.txt");

  assertTrue(ConanRoutes.uploadConanInfo().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("group")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("project")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
  assertThat(matcherState.getTokens().get("sha"), is(equalTo(null)));
}
 
Example #19
Source File: UserController.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Matches on credential checking endpoint
 */
private static Builder authenticate(final String version) {
  return new Builder().matcher(
      and(
          new ActionMatcher(GET),
          new TokenMatcher(format(AUTHENTICATE_URL, version))
      )
  );
}
 
Example #20
Source File: ConanRoutesTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnDownloadUrls() {
  when(request.getPath()).thenReturn("/v1/conans/jsonformoderncpp/2.1.1/vthiery/stable/download_urls");
  assertTrue(underTest.downloadUrls().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("vthiery")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("jsonformoderncpp")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
}
 
Example #21
Source File: PyPiPathUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Utility method encapsulating getting a particular token by name from a matcher, including preconditions.
 */
private static String match(final TokenMatcher.State state, final String name) {
  checkNotNull(state);
  String result = state.getTokens().get(name);
  checkNotNull(result);
  return result;
}
 
Example #22
Source File: ConanProxyFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Nullable
@Override
protected Content getCachedContent(final Context context) throws IOException {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class);
  ConanCoords conanCoords = convertFromState(state);
  String assetPath = getProxyAssetPath(conanCoords, assetKind);
  return  getAssetContent(assetPath, context, assetKind);
}
 
Example #23
Source File: ConanRoutesTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnConanPackage() {
  when(request.getPath()).thenReturn("/vthiery/jsonformoderncpp/2.1.1/stable/packages/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/conan_package.tgz");
  assertTrue(underTest.conanPackage().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("vthiery")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("jsonformoderncpp")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
}
 
Example #24
Source File: HelmPathUtils.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Utility method encapsulating getting a particular token by name from a matcher, including preconditions.
 */
private String match(final TokenMatcher.State state, final String name) {
  checkNotNull(state);
  String result = state.getTokens().get(name);
  checkNotNull(result);
  return result;
}
 
Example #25
Source File: CondaProxyFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nullable
@Override
protected Content getCachedContent(final Context context) {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  TokenMatcher.State matcherState = matcherState(context);
  String assetPath;
  switch (assetKind) {
    case CHANNEL_INDEX_HTML:
      assetPath = buildAssetPath(matcherState, INDEX_HTML);
      break;
    case CHANNEL_DATA_JSON:
      assetPath = buildAssetPath(matcherState, CHANNELDATA_JSON);
      break;
    case CHANNEL_RSS_XML:
      assetPath = buildAssetPath(matcherState, RSS_XML);
      break;
    case ARCH_INDEX_HTML:
      assetPath = buildArchAssetPath(matcherState, INDEX_HTML);
      break;
    case ARCH_REPODATA_JSON:
      assetPath = buildArchAssetPath(matcherState, REPODATA_JSON);
      break;
    case ARCH_REPODATA_JSON_BZ2:
      assetPath = buildArchAssetPath(matcherState, REPODATA_JSON_BZ2);
      break;
    case ARCH_REPODATA2_JSON:
      assetPath = buildArchAssetPath(matcherState, REPODATA2_JSON);
      break;
    case ARCH_TAR_PACKAGE:
    case ARCH_CONDA_PACKAGE:
      assetPath = buildCondaPackagePath(matcherState);
      break;
    default:
      throw new IllegalStateException("Received an invalid AssetKind of type: " + assetKind.name());
  }
  return getAsset(assetPath);
}
 
Example #26
Source File: ConanRoutesTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnPackagesDownloadUrl() {
  when(request.getPath()).thenReturn("/v1/conans/jsonformoderncpp/2.1.1/vthiery/stable/packages/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/download_urls");
  assertTrue(underTest.downloadUrls().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("vthiery")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("jsonformoderncpp")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
}
 
Example #27
Source File: ConanRoutesTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void canMatchOnConanManifest() {
  when(request.getPath()).thenReturn("/vthiery/jsonformoderncpp/2.1.1/stable/conanmanifest.txt");
  assertTrue(underTest.conanManifest().handler(handler).create().getMatcher().matches(context));
  TokenMatcher.State matcherState = attributesMap.require(TokenMatcher.State.class);
  assertThat(matcherState.getTokens().get("group"), is(equalTo("vthiery")));
  assertThat(matcherState.getTokens().get("project"), is(equalTo("jsonformoderncpp")));
  assertThat(matcherState.getTokens().get("version"), is(equalTo("2.1.1")));
}
 
Example #28
Source File: NpmHandlers.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
  State state = context.getAttributes().require(TokenMatcher.State.class);
  Repository repository = context.getRepository();
  log.debug("[createToken] repository: {} tokens: {}", repository.getName(), state.getTokens());

  return repository.facet(NpmTokenFacet.class).login(context);
}
 
Example #29
Source File: HelmProxyFacetImpl.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Content store(final Context context, final Content content) throws IOException {
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  switch(assetKind) {
    case HELM_INDEX:
      return putMetadata(INDEX_YAML, content, assetKind);
    case HELM_PACKAGE:
      TokenMatcher.State matcherState = helmPathUtils.matcherState(context);
      return putComponent(content, helmPathUtils.filename(matcherState), assetKind);
    default:
      throw new IllegalStateException("Received an invalid AssetKind of type: " + assetKind.name());
  }
}
 
Example #30
Source File: ConanHostedFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
public Response get(final Context context) {
  log.debug("Request {}", context.getRequest().getPath());

  TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class);
  ConanCoords coord = ConanHostedHelper.convertFromState(state);
  AssetKind assetKind = context.getAttributes().require(AssetKind.class);
  String assetPath = ConanHostedHelper.getHostedAssetPath(coord, assetKind);

  Content content = doGet(assetPath);
  if (content == null) {
    return HttpResponses.notFound();
  }

  return new Response.Builder()
      .status(success(OK))
      .payload(new StreamPayload(
          new InputStreamSupplier()
          {
            @Nonnull
            @Override
            public InputStream get() throws IOException {
              return content.openInputStream();
            }
          },
          content.getSize(),
          content.getContentType()))
      .build();
}