private String assetPath(Context context) { final AptSnapshotHandler.State snapshotState = context.getAttributes().require(AptSnapshotHandler.State.class); return snapshotState.assetPath; } }
public static void copyLocalContextAttributes(final Context existingContext, final Context newContext) { if (existingContext != null) { existingContext.getAttributes().keys().stream() .filter(key -> !key.startsWith(LOCAL_ATTRIBUTE_PREFIX)) .forEach(key -> newContext.getAttributes().set(key, existingContext.getAttributes().get(key))); } } }
/** * Returns the {@link TokenMatcher.State} for the content. */ public TokenMatcher.State matcherState(final Context context) { return context.getAttributes().require(TokenMatcher.State.class); }
@Nonnull private MavenPath mavenPath(@Nonnull final Context context) { return context.getAttributes().require(MavenPath.class); } }
private String assetPath(Context context) { final AptSnapshotHandler.State snapshotState = context.getAttributes().require(AptSnapshotHandler.State.class); return snapshotState.assetPath; } }
/** * Pull the parsed content name/path out of the context. */ @Nonnull private String contentName(final Context context) { TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class); String name = state.getTokens().get("name"); checkState(name != null, "Missing token: name"); return name; } }
/** * Returns the vendor token from a path in a context. The vendor token must be present or the operation will fail. */ public static String getVendorToken(final Context context) { TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class); return checkNotNull(state.getTokens().get(VENDOR_TOKEN)); }
/** * Returns the project token from a path in a context. The project token must be present or the operation will fail. */ public static String getProjectToken(final Context context) { TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class); return checkNotNull(state.getTokens().get(PROJECT_TOKEN)); }
/** * Determines what 'component' this request relates to. */ private String componentPath(final Context context) { final TokenMatcher.State tokenMatcherState = context.getAttributes().require(TokenMatcher.State.class); return tokenMatcherState.getTokens().get("name"); }
@Override @Nonnull protected CacheController getCacheController(@Nonnull final Context context) { final ProxyTarget proxyTarget = context.getAttributes().require(ProxyTarget.class); return cacheControllerHolder.require(proxyTarget.getCacheType()); }
@Nonnull @Override protected CacheController getCacheController(@Nonnull final Context context) { final AssetKind assetKind = context.getAttributes().require(AssetKind.class); return cacheControllerHolder.require(assetKind.getCacheType()); }
/** * Builds the path to a provider json file based on the path contained in a particular context. The vendor token and * the project token must be present in the context in order to successfully generate the path. */ public static String buildProviderPath(final Context context) { TokenMatcher.State state = context.getAttributes().require(TokenMatcher.State.class); Map<String, String> tokens = state.getTokens(); return buildProviderPath(tokens.get(VENDOR_TOKEN), tokens.get(PROJECT_TOKEN)); }
@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 protected Response buildNotFoundResponse(final Context context) { State state = context.getAttributes().require(TokenMatcher.State.class); NpmPackageId packageId = NpmHandlers.packageId(state); return NpmResponses.packageNotFound(packageId); } }
@Override public boolean matches(final Context context) { final String path = context.getRequest().getPath(); if (predicate.apply(path)) { final MavenPath mavenPath = mavenPathParser.parsePath(path); context.getAttributes().set(MavenPath.class, mavenPath); return true; } return false; } }
@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); } };
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { MavenPath mavenPath = context.getAttributes().require(MavenPath.class); MavenFacet mavenFacet = context.getRepository().facet(MavenFacet.class); Content content = mavenFacet.get(mavenPath); if (content == null) { return HttpResponses.notFound(mavenPath.getPath()); } return HttpResponses.ok(content); } }
@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(); } };
@Override protected Response buildResponse(final Status status, final Context context) { if (status.getCode() == HttpStatus.SC_NOT_FOUND) { State state = context.getAttributes().require(TokenMatcher.State.class); NpmPackageId packageId = NpmHandlers.packageId(state); return NpmResponses.packageNotFound(packageId); } return super.buildResponse(status, context); } }
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(); } }