use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.
the class TrackedContentEntry2StringMapper method getKeyMapping.
@Override
public Object getKeyMapping(String stringKey) {
String[] parts = stringKey.split(FIELD_SPLITTER);
final TrackingKey trackingKey = NULL_STR.equals(parts[0]) ? null : new TrackingKey(parts[0]);
final String path = NULL_STR.equals(parts[1]) ? null : parts[1];
final StoreKey storeKey = NULL_STR.equals(parts[2]) ? null : StoreKey.fromString(parts[2]);
final AccessChannel channel = NULL_STR.equals(parts[3]) ? null : AccessChannel.valueOf(parts[3]);
final StoreEffect effect = NULL_STR.equals(parts[4]) ? null : StoreEffect.valueOf(parts[4]);
return new TrackedContentEntry(trackingKey, storeKey, channel, "", path, effect, 0L, "", "", "");
}
use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.
the class FoloRecordZipTest method zipTrackedContentTest.
@Ignore
@Test
public void zipTrackedContentTest() throws IOException {
TrackingKey trackingKey = new TrackingKey(keyId);
Set<TrackedContentEntry> uploads = new HashSet<>();
Set<TrackedContentEntry> downloads = new HashSet<>();
String inputFile = "/tmp/" + keyId + ".json";
TrackedContentDTO contentDTO = mapper.readValue(new File(inputFile), TrackedContentDTO.class);
contentDTO.getDownloads().forEach(dto -> downloads.add(getTrackedContentEntryByDTO(trackingKey, dto, DOWNLOAD)));
contentDTO.getUploads().forEach(dto -> uploads.add(getTrackedContentEntryByDTO(trackingKey, dto, UPLOAD)));
Set<TrackedContent> sealed = new HashSet<>();
TrackedContent rec = new TrackedContent(trackingKey, uploads, downloads);
sealed.add(rec);
zipTrackedContent(new File(inputFile.replace(".json", ".zip")), sealed);
}
use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.
the class FoloNPMContentAccessResource method doHead.
@ApiOperation("Store and track file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 404, message = "Content is not available"), @ApiResponse(code = 200, message = "Header metadata for content (or rendered listing when path ends with '/index.html' or '/'") })
@HEAD
@Path("/{packageName}/{versionTarball: (.*)}")
public Response doHead(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @PathParam("name") final String name, @PathParam("packageName") final String packageName, @PathParam("versionTarball") final String versionTarball, @QueryParam(CHECK_CACHE_ONLY) final Boolean cacheOnly, @Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
final TrackingKey tk = new TrackingKey(id);
EventMetadata metadata = new EventMetadata().set(TRACKING_KEY, tk).set(ACCESS_CHANNEL, AccessChannel.NATIVE);
RequestContextHelper.setContext(CONTENT_TRACKING_ID, id);
final String baseUri = getBasePath(uriInfo, id);
final String path = Paths.get(packageName, versionTarball).toString();
return handler.doHead(NPM_PKG_KEY, type, name, path, cacheOnly, baseUri, request, metadata);
}
use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.
the class FoloNPMContentAccessResource method doGet.
@ApiOperation("Retrieve and track NPM file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 404, message = "Content is not available"), @ApiResponse(code = 200, response = String.class, message = "Rendered content listing (when path ends with '/index.html' or '/')"), @ApiResponse(code = 200, response = StreamingOutput.class, message = "Content stream") })
@GET
@Path("/{packageName}/{versionTarball: (.*)}")
public Response doGet(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @PathParam("name") final String name, @PathParam("packageName") final String packageName, @PathParam("versionTarball") final String versionTarball, @Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
final TrackingKey tk = new TrackingKey(id);
EventMetadata metadata = new EventMetadata().set(TRACKING_KEY, tk).set(ACCESS_CHANNEL, AccessChannel.NATIVE);
RequestContextHelper.setContext(CONTENT_TRACKING_ID, id);
final String path = Paths.get(packageName, versionTarball).toString();
final String baseUri = getBasePath(uriInfo, id);
return handler.doGet(NPM_PKG_KEY, type, name, path, baseUri, request, metadata);
}
use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.
the class ProxyResponseWriter method createEventMetadata.
private EventMetadata createEventMetadata(final boolean writeBody, final UserPass proxyUserPass, final String path, final RemoteRepository repo) throws IndyWorkflowException {
final EventMetadata eventMetadata = new EventMetadata();
if (writeBody) {
TrackingKey tk = null;
switch(config.getTrackingType()) {
case ALWAYS:
{
if (proxyUserPass == null) {
throw new IndyWorkflowException(ApplicationStatus.BAD_REQUEST.code(), "Tracking is always-on, but no username was provided! Cannot initialize tracking key.");
}
tk = new TrackingKey(proxyUserPass.getUser());
break;
}
case SUFFIX:
{
if (proxyUserPass != null) {
final String user = proxyUserPass.getUser();
// TODO: Will this always be non-null here? Can we have an unsecured proxy?
if (user.endsWith(TRACKED_USER_SUFFIX) && user.length() > TRACKED_USER_SUFFIX.length()) {
tk = new TrackingKey(StringUtils.substring(user, 0, -TRACKED_USER_SUFFIX.length()));
}
}
break;
}
default:
{
}
}
if (tk != null) {
logger.debug("TRACKING {} in {} (KEY: {})", path, repo, tk);
eventMetadata.set(FoloConstants.TRACKING_KEY, tk);
eventMetadata.set(FoloConstants.ACCESS_CHANNEL, AccessChannel.GENERIC_PROXY);
} else {
logger.debug("NOT TRACKING: {} in {}", path, repo);
}
} else {
logger.debug("NOT TRACKING non-body request: {} in {}", path, repo);
}
eventMetadata.setPackageType(PKG_TYPE_GENERIC_HTTP);
return eventMetadata;
}
Aggregations