@Override public boolean apply(ArtifactId input) { // should check if the artifact is from SYSTEM namespace, if not, check if it is from the scoped namespace. // by default, the scoped namespace is for USER scope return (((pluginScope == null && NamespaceId.SYSTEM.equals(input.getParent())) || pluginArtifactNamespace.equals(input.getParent())) && (pluginArtifactName == null || pluginArtifactName.equals(input.getArtifact())) && (pluginRange == null || pluginRange.versionIsInRange(new ArtifactVersion(input.getVersion())))); } };
@Override public boolean apply(ArtifactId input) { // should check if the artifact is from SYSTEM namespace, if not, check if it is from the scoped namespace. // by default, the scoped namespace is for USER scope return (((pluginScope == null && NamespaceId.SYSTEM.equals(input.getParent())) || pluginArtifactNamespace.equals(input.getParent())) && (pluginArtifactName == null || pluginArtifactName.equals(input.getArtifact())) && (pluginRange == null || pluginRange.versionIsInRange(new ArtifactVersion(input.getVersion())))); } };
/** * Add an artifact. * * @param artifactId the id of the artifact to add * @param parentArtifacts the set of artifacts this artifact extends * @param artifactContents an input supplier for the contents of the artifact * @throws ArtifactAlreadyExistsException if the artifact already exists * @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid * @throws ArtifactRangeNotFoundException if the parent artifacts do not exist * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public void add(ArtifactId artifactId, @Nullable Set<ArtifactRange> parentArtifacts, ContentProvider<? extends InputStream> artifactContents) throws UnauthenticatedException, BadRequestException, ArtifactRangeNotFoundException, ArtifactAlreadyExistsException, IOException, UnauthorizedException { add(artifactId.getParent(), artifactId.getArtifact(), artifactContents, artifactId.getVersion(), parentArtifacts); }
@Override public ArtifactDetail getArtifact(Id.Artifact artifactId) throws Exception { ArtifactId artifact = artifactId.toEntityId(); // No authorization for system artifacts if (!NamespaceId.SYSTEM.equals(artifact.getParent())) { // need at least one privilege to get the artifact detail AuthorizationUtil.ensureOnePrivilege(artifact, EnumSet.allOf(Action.class), authorizationEnforcer, authenticationContext.getPrincipal()); } return delegate.getArtifact(artifactId); }
@Override public ArtifactDetail getArtifact(Id.Artifact artifactId) throws Exception { ArtifactId artifact = artifactId.toEntityId(); // No authorization for system artifacts if (!NamespaceId.SYSTEM.equals(artifact.getParent())) { // need at least one privilege to get the artifact detail AuthorizationUtil.ensureOnePrivilege(artifact, EnumSet.allOf(Action.class), authorizationEnforcer, authenticationContext.getPrincipal()); } return delegate.getArtifact(artifactId); }
public static Artifact fromEntityId(ArtifactId artifactId) { return from(Namespace.fromEntityId(artifactId.getParent()), artifactId.getArtifact(), artifactId.getVersion()); }
public static Artifact fromEntityId(ArtifactId artifactId) { return from(Namespace.fromEntityId(artifactId.getParent()), artifactId.getArtifact(), artifactId.getVersion()); }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, @Nullable Set<PluginClass> additionalPlugins, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, additionalPlugins, pluginClass, pluginClasses); return artifactManagerFactory.create(artifactId); }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, @Nullable Set<PluginClass> additionalPlugins, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, additionalPlugins, pluginClass, pluginClasses); return new RemoteArtifactManager(clientConfig, restClient, artifactId); }
private Set<ArtifactRange> toRange(ArtifactId parent) { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange(parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); return parents; } }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, @Nullable Set<PluginClass> additionalPlugins, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, additionalPlugins, pluginClass, pluginClasses); return artifactManagerFactory.create(artifactId); }
private Set<ArtifactRange> toRange(ArtifactId parent) { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange(parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); return parents; } }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, pluginClass, pluginClasses); return new RemoteArtifactManager(clientConfig, restClient, artifactId); }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, pluginClass, pluginClasses); return artifactManagerFactory.create(artifactId); }
@Override public ArtifactManager addPluginArtifact(ArtifactId artifactId, ArtifactId parent, Class<?> pluginClass, Class<?>... pluginClasses) throws Exception { Set<ArtifactRange> parents = new HashSet<>(); parents.add(new ArtifactRange( parent.getParent().getNamespace(), parent.getArtifact(), new ArtifactVersion(parent.getVersion()), true, new ArtifactVersion(parent.getVersion()), true)); addPluginArtifact(artifactId, parents, pluginClass, pluginClasses); return artifactManagerFactory.create(artifactId); }
/** * Gets information about a specific artifact version. * * @param artifactId the id of the artifact to get * @param scope the scope of the artifact * @return information about the given artifact * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server * @throws ArtifactNotFoundException if the given artifact does not exist */ public ArtifactInfo getArtifactInfo(ArtifactId artifactId, ArtifactScope scope) throws IOException, UnauthenticatedException, ArtifactNotFoundException, UnauthorizedException { String path = String.format("artifacts/%s/versions/%s?scope=%s", artifactId.getArtifact(), artifactId.getVersion(), scope.name()); URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path); HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new ArtifactNotFoundException(artifactId); } return ObjectResponse.fromJsonBody(response, ArtifactInfo.class, GSON).getResponseObject(); }
/** * Delete an artifact. * * @param artifactId the artifact to delete * * @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public void delete(ArtifactId artifactId) throws IOException, UnauthenticatedException, BadRequestException, UnauthorizedException { URL url = config.resolveNamespacedURLV3(artifactId.getParent(), String.format("artifacts/%s/versions/%s", artifactId.getArtifact(), artifactId.getVersion())); HttpRequest request = HttpRequest.delete(url).build(); HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST); int responseCode = response.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException(response.getResponseBodyAsString()); } }
/** * Gets all the plugin types available to a specific artifact. * * @param artifactId the id of the artifact to get * @param scope the scope of the artifact * @return list of plugin types available to the given artifact. * @throws ArtifactNotFoundException if the given artifact does not exist * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public List<String> getPluginTypes(ArtifactId artifactId, ArtifactScope scope) throws IOException, UnauthenticatedException, ArtifactNotFoundException, UnauthorizedException { String path = String.format("artifacts/%s/versions/%s/extensions?scope=%s", artifactId.getArtifact(), artifactId.getVersion(), scope.name()); URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path); HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new ArtifactNotFoundException(artifactId); } return ObjectResponse.<List<String>>fromJsonBody(response, EXTENSIONS_TYPE).getResponseObject(); }
/** * Gets all the plugins of the given type and name available to the given artifact. * * @param artifactId the id of the artifact to get * @param pluginType the type of plugins to get * @param pluginName the name of the plugins to get * @param scope the scope of the artifact * @return list of {@link PluginInfo} * @throws NotFoundException if the given artifact does not exist or plugins for that artifact do not exist * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public List<PluginInfo> getPluginInfo(ArtifactId artifactId, String pluginType, String pluginName, ArtifactScope scope) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { String path = String.format("artifacts/%s/versions/%s/extensions/%s/plugins/%s?scope=%s", artifactId.getArtifact(), artifactId.getVersion(), pluginType, pluginName, scope.name()); URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path); HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NotFoundException(response.getResponseBodyAsString()); } return ObjectResponse.<List<PluginInfo>>fromJsonBody(response, PLUGIN_INFOS_TYPE).getResponseObject(); }
/** * Delete all properties for an artifact. If no properties exist, this will be a no-op. * * @param artifactId the artifact to delete properties from * @throws BadRequestException if the request is invalid. For example, if the artifact name or version is invalid * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server * @throws ArtifactNotFoundException if the artifact does not exist * @throws IOException if a network error occurred */ public void deleteProperties(ArtifactId artifactId) throws IOException, UnauthenticatedException, ArtifactNotFoundException, BadRequestException, UnauthorizedException { String path = String.format("artifacts/%s/versions/%s/properties", artifactId.getArtifact(), artifactId.getVersion()); URL url = config.resolveNamespacedURLV3(artifactId.getParent(), path); HttpRequest.Builder requestBuilder = HttpRequest.delete(url); HttpRequest request = requestBuilder.build(); HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND); int responseCode = response.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) { throw new ArtifactNotFoundException(artifactId); } else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException(response.getResponseBodyAsString()); } }