Search in sources :

Example 21 with TrackingKey

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, "", "", "");
}
Also used : StoreEffect(org.commonjava.indy.folo.model.StoreEffect) AccessChannel(org.commonjava.indy.model.core.AccessChannel) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Example 22 with TrackingKey

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);
}
Also used : TrackedContent(org.commonjava.indy.folo.model.TrackedContent) FoloUtils.zipTrackedContent(org.commonjava.indy.folo.FoloUtils.zipTrackedContent) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) File(java.io.File) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) HashSet(java.util.HashSet) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with TrackingKey

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);
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 24 with TrackingKey

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);
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 25 with TrackingKey

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;
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Aggregations

TrackingKey (org.commonjava.indy.folo.model.TrackingKey)46 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)18 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Path (javax.ws.rs.Path)12 StoreKey (org.commonjava.indy.model.core.StoreKey)11 Test (org.junit.Test)11 TrackedContent (org.commonjava.indy.folo.model.TrackedContent)10 TrackedContentEntry (org.commonjava.indy.folo.model.TrackedContentEntry)10 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)8 GET (javax.ws.rs.GET)6 HEAD (javax.ws.rs.HEAD)6 PUT (javax.ws.rs.PUT)6 AccessChannel (org.commonjava.indy.model.core.AccessChannel)6 Inject (javax.inject.Inject)4 Context (javax.ws.rs.core.Context)4 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)4 Location (org.commonjava.maven.galley.model.Location)4 Transfer (org.commonjava.maven.galley.model.Transfer)4 Logger (org.slf4j.Logger)4