@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("[deleteToken] repository: {} tokens: {}", repository.getName(), state.getTokens()); return repository.facet(NpmTokenFacet.class).logout(context); } };
@Override public Response handle(Context context) throws Exception { String path = assetPath(context); String method = context.getRequest().getAction(); AptSigningFacet facet = context.getRepository().facet(AptSigningFacet.class); if ("repository-key.gpg".equals(path) && GET.equals(method)) { return HttpResponses.ok(facet.getPublicKey()); } return context.proceed(); }
@VisibleForTesting Context maybeCopyContextAttributes(final Repository repository, final Request request, final Context existingContext) { Context context = new Context(repository, request); copyLocalContextAttributes(existingContext, context); return context; }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { SecurityFacet securityFacet = context.getRepository().facet(SecurityFacet.class); //we employ the model that one security check per request is all that is necessary, if this handler is in a nested //repository (because this is a group repository), there is no need to check authz again if (context.getAttributes().get(AUTHORIZED_KEY) == null) { securityFacet.ensurePermitted(context.getRequest()); context.getAttributes().set(AUTHORIZED_KEY, true); } return context.proceed(); } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { Stopwatch watch = Stopwatch.createStarted(); try { return context.proceed(); } finally { String elapsed = watch.toString(); context.getAttributes().set(ELAPSED_KEY, elapsed); log.trace("Timing: {}", elapsed); } } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { // Ensure the extra handlers are inserted only once, in the case that a handler higher // on the stack calls proceed() twice for some reason if (!isMarkedExtended(context)) { ListIterator<ContributedHandler> handlerIterator = contributedHandlers.listIterator(contributedHandlers.size()); while (handlerIterator.hasPrevious()) { context.insertHandler(handlerIterator.previous()); } markExtended(context); } return context.proceed(); }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { Repository repository = context.getRepository(); Parameters parameters = context.getRequest().getParameters(); log.debug("[searchV1] repository: {} parameters: {}", repository.getName(), parameters); return NpmResponses.ok(repository.facet(NpmSearchFacet.class).searchV1(parameters)); } };
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { MavenPath path = context.getAttributes().require(MavenPath.class); Repository repository = context.getRepository(); String action = context.getRequest().getAction(); switch (action) { case GET: case HEAD: return doGet(path, repository); default: return HttpResponses.methodNotAllowed(context.getRequest().getAction(), GET, HEAD); } }
private String assetPath(Context context) { final AptSnapshotHandler.State snapshotState = context.getAttributes().require(AptSnapshotHandler.State.class); return snapshotState.assetPath; } }
@Override protected String getUrl(@Nonnull final Context context) { AssetKind assetKind = context.getAttributes().require(AssetKind.class); switch (assetKind) { case ZIPBALL: return getZipballUrl(context); default: return context.getRequest().getPath().substring(1); } }
@Override public boolean matches(final Context context) { final String action = context.getRequest().getAction(); return allowedActions.contains(action); } }
private Response handleSnapshotFetchRequest(Context context, String id, String path) throws Exception { Repository repository = context.getRepository(); AptSnapshotFacet snapshotFacet = repository.facet(AptSnapshotFacet.class); if (snapshotFacet.isSnapshotableFile(path)) { Content content = snapshotFacet.getSnapshotFile(id, path); return content == null ? HttpResponses.notFound() : HttpResponses.ok(content); } context.getAttributes().set(AptSnapshotHandler.State.class, new AptSnapshotHandler.State(path)); return context.proceed(); } }
@Override public Response handle(Context context) throws Exception { String path = context.getRequest().getPath(); Matcher matcher = SNAPSHOT_PATH_PATTERN.matcher(path); if (!matcher.matches()) { context.getAttributes().set(AptSnapshotHandler.State.class, new AptSnapshotHandler.State(path.substring(1))); return context.proceed(); } String id = matcher.group(1); path = matcher.group(2); if (path.length() == 0) { return handleSnapshotAdminRequest(context, id); } else { return handleSnapshotFetchRequest(context, id, path); } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { final Predicate<Response> requestPredicate = requestPredicate(context.getRequest()); if (requestPredicate != null) { makeUnconditional(context.getRequest()); try { return handleConditional(context, requestPredicate); } finally { makeConditional(context.getRequest()); } } return context.proceed(); }
@Nonnull @Override public Content searchIndex(@Nullable final DateTime since) throws IOException { try { final Request getRequest = new Request.Builder() .action(GET) .path("/" + NpmFacetUtils.REPOSITORY_ROOT_ASSET) .build(); Context context = new Context(getRepository(), getRequest); context.getAttributes().set(ProxyTarget.class, ProxyTarget.SEARCH_INDEX); Content fullIndex = getRepository().facet(ProxyFacet.class).get(context); if (fullIndex == null) { throw new IOException("Could not retrieve registry root"); } return NpmSearchIndexFilter.filterModifiedSince(fullIndex, since); } catch (Exception e) { throw new IOException(e); } }
private ProxyFacet proxyFacet(final Context context) { return context.getRepository().facet(ProxyFacet.class); } }
@Override public Response handle(Context context) throws Exception { UnitOfWork.begin(context.getRepository().facet(StorageFacet.class).txSupplier()); try { return context.proceed(); } finally { UnitOfWork.end(); } } }
/** * Start route. */ @Nonnull Response start(final Route route) throws Exception { checkNotNull(route); checkState(handlers == null, "Already started"); log.debug("Starting: {}", route); // Copy the handler list to allow modification this.handlers = new ArrayList<>(route.getHandlers()).listIterator(); return proceed(); } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { Repository repository = context.getRepository(); Parameters parameters = context.getRequest().getParameters(); log.debug("[searchIndex] repository: {} parameters: {}", repository.getName(), parameters); return NpmResponses.ok(repository.facet(NpmSearchIndexFacet.class).searchIndex(indexSince(parameters))); } };
@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("[putPackage] repository: {} tokens: {}", repository.getName(), state.getTokens()); repository.facet(NpmHostedFacet.class) .putPackage(packageId(state), revision(state), context.getRequest().getPayload()); return NpmResponses.ok(); } };