aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2021-05-30 19:14:03 +0200
committerMartin Stockhammer <martin_s@apache.org>2021-05-30 19:14:03 +0200
commit79c61a7c6a63be33a2221a0bd75fdfea7f6b1bf6 (patch)
tree5a12b8ad5d8755f5d0f0b6c189bd6a69ceee2bc3 /archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src
parentfe117fcc4be288a37db07788a2fd3cc857beeb28 (diff)
downloadarchiva-79c61a7c6a63be33a2221a0bd75fdfea7f6b1bf6.tar.gz
archiva-79c61a7c6a63be33a2221a0bd75fdfea7f6b1bf6.zip
Improving storage handling with assets
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/FileInfo.java16
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/MavenManagedRepository.java149
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/MavenManagedRepositoryUpdate.java47
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/ErrorKeys.java42
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/MavenManagedRepositoryService.java39
5 files changed, 277 insertions, 16 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/FileInfo.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/FileInfo.java
index e1f423d2b..d5612c6f3 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/FileInfo.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/FileInfo.java
@@ -35,9 +35,11 @@ package org.apache.archiva.rest.api.model.v2;/*
*/
import io.swagger.v3.oas.annotations.media.Schema;
+import org.apache.archiva.repository.storage.StorageAsset;
import java.io.Serializable;
import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
/**
* @author Martin Stockhammer <martin_s@apache.org>
@@ -50,7 +52,19 @@ public class FileInfo implements Serializable
private String fileName;
private String path;
- @Schema(description = "Time when the file was last modified")
+ public FileInfo( )
+ {
+ }
+
+ public static FileInfo of( StorageAsset asset ) {
+ FileInfo fileInfo = new FileInfo( );
+ fileInfo.setFileName( asset.getName() );
+ fileInfo.setPath( asset.getPath() );
+ fileInfo.setModified( asset.getModificationTime( ).atOffset( ZoneOffset.UTC ) );
+ return fileInfo;
+ }
+
+ @Schema(description = "Time when the file was last modified")
public OffsetDateTime getModified( )
{
return modified;
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/MavenManagedRepository.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/MavenManagedRepository.java
index 6a045b438..99455f148 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/MavenManagedRepository.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/MavenManagedRepository.java
@@ -35,9 +35,17 @@ package org.apache.archiva.rest.api.model.v2;/*
*/
import io.swagger.v3.oas.annotations.media.Schema;
+import org.apache.archiva.repository.ManagedRepository;
+import org.apache.archiva.repository.RepositoryType;
+import org.apache.archiva.repository.features.ArtifactCleanupFeature;
+import org.apache.archiva.repository.features.IndexCreationFeature;
+import org.apache.archiva.repository.features.StagingRepositoryFeature;
+import java.time.Period;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
/**
* @author Martin Stockhammer <martin_s@apache.org>
@@ -49,6 +57,52 @@ public class MavenManagedRepository extends Repository
boolean blocksRedeployments;
List<String> releaseSchemes = new ArrayList<>( );
+ boolean deleteSnapshotsOfRelease = false;
+ private Period retentionPeriod;
+ private int retentionCount;
+ private String indexPath;
+ private String packedIndexPath;
+ private boolean skipPackedIndexCreation;
+ private boolean hasStagingRepository;
+ private String stagingRepository;
+
+
+ public MavenManagedRepository( )
+ {
+ super.setCharacteristic( Repository.CHARACTERISTIC_MANAGED );
+ super.setType( RepositoryType.MAVEN.name( ) );
+ }
+
+ protected static void update(MavenManagedRepository repo, ManagedRepository beanRepo) {
+ repo.setDescription( beanRepo.getDescription() );
+ repo.setId( beanRepo.getId() );
+ repo.setIndex( true );
+ repo.setLayout( beanRepo.getLayout() );
+ repo.setBlocksRedeployments( beanRepo.blocksRedeployments() );
+ repo.setReleaseSchemes( beanRepo.getActiveReleaseSchemes().stream().map( Objects::toString).collect( Collectors.toList()) );
+ repo.setLocation( beanRepo.getLocation().toString() );
+ repo.setName( beanRepo.getName());
+ repo.setScanned( beanRepo.isScanned() );
+ repo.setSchedulingDefinition( beanRepo.getSchedulingDefinition() );
+ ArtifactCleanupFeature artifactCleanupFeature = beanRepo.getFeature( ArtifactCleanupFeature.class ).get( );
+ repo.setDeleteSnapshotsOfRelease( artifactCleanupFeature.isDeleteReleasedSnapshots());
+ repo.setRetentionCount( artifactCleanupFeature.getRetentionCount());
+ repo.setRetentionPeriod( artifactCleanupFeature.getRetentionPeriod() );
+ IndexCreationFeature icf = beanRepo.getFeature( IndexCreationFeature.class ).get( );
+ repo.setIndex( icf.hasIndex( ) );
+ repo.setIndexPath( icf.getIndexPath( ).getPath( ) );
+ repo.setPackedIndexPath( icf.getPackedIndexPath( ).getPath( ) );
+ repo.setSkipPackedIndexCreation( icf.isSkipPackedIndexCreation() );
+ StagingRepositoryFeature srf = beanRepo.getFeature( StagingRepositoryFeature.class ).get( );
+ repo.setHasStagingRepository( srf.isStageRepoNeeded( ) );
+ repo.setStagingRepository( srf.getStagingRepository()!=null?srf.getStagingRepository().getId():"" );
+ }
+
+ public static MavenManagedRepository of( ManagedRepository beanRepo ) {
+ MavenManagedRepository repo = new MavenManagedRepository( );
+ update( repo, beanRepo );
+ return repo;
+ }
@Schema(name="blocks_redeployments",description = "True, if redeployments to this repository are not allowed")
public boolean isBlocksRedeployments( )
@@ -72,6 +126,101 @@ public class MavenManagedRepository extends Repository
this.releaseSchemes = new ArrayList<>( releaseSchemes );
}
+ public void addReleaseScheme(String scheme) {
+ if (!this.releaseSchemes.contains( scheme ))
+ {
+ this.releaseSchemes.add( scheme );
+ }
+ }
+
+ @Schema(name="delete_snaphots_of_release", description = "True, if snapshots are deleted, after a version is released")
+ public boolean isDeleteSnapshotsOfRelease( )
+ {
+ return deleteSnapshotsOfRelease;
+ }
+
+ public void setDeleteSnapshotsOfRelease( boolean deleteSnapshotsOfRelease )
+ {
+ this.deleteSnapshotsOfRelease = deleteSnapshotsOfRelease;
+ }
+
+ @Schema(name="retention_period", description = "The period after which snapshots are deleted.")
+ public Period getRetentionPeriod( )
+ {
+ return retentionPeriod;
+ }
+
+ public void setRetentionPeriod( Period retentionPeriod )
+ {
+ this.retentionPeriod = retentionPeriod;
+ }
+
+ @Schema(name="retention_count", description = "Number of snapshot artifacts to keep.")
+ public int getRetentionCount( )
+ {
+ return retentionCount;
+ }
+
+ public void setRetentionCount( int retentionCount )
+ {
+ this.retentionCount = retentionCount;
+ }
+
+ @Schema( name = "index_path", description = "Path to the directory that contains the index, relative to the repository base directory" )
+ public String getIndexPath( )
+ {
+ return indexPath;
+ }
+
+ public void setIndexPath( String indexPath )
+ {
+ this.indexPath = indexPath;
+ }
+
+ @Schema( name = "packed_index_path", description = "Path to the directory that contains the packed index, relative to the repository base directory" )
+ public String getPackedIndexPath( )
+ {
+ return packedIndexPath;
+ }
+
+ public void setPackedIndexPath( String packedIndexPath )
+ {
+ this.packedIndexPath = packedIndexPath;
+ }
+
+ @Schema(name="skip_packed_index_creation", description = "True, if packed index is not created during index update")
+ public boolean isSkipPackedIndexCreation( )
+ {
+ return skipPackedIndexCreation;
+ }
+
+ public void setSkipPackedIndexCreation( boolean skipPackedIndexCreation )
+ {
+ this.skipPackedIndexCreation = skipPackedIndexCreation;
+ }
+
+ @Schema(name="has_staging_repository", description = "True, if this repository has a staging repository assigned")
+ public boolean isHasStagingRepository( )
+ {
+ return hasStagingRepository;
+ }
+
+ public void setHasStagingRepository( boolean hasStagingRepository )
+ {
+ this.hasStagingRepository = hasStagingRepository;
+ }
+
+ @Schema(name="staging_repository", description = "The id of the assigned staging repository")
+ public String getStagingRepository( )
+ {
+ return stagingRepository;
+ }
+
+ public void setStagingRepository( String stagingRepository )
+ {
+ this.stagingRepository = stagingRepository;
+ }
+
@Override
public boolean equals( Object o )
{
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/MavenManagedRepositoryUpdate.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/MavenManagedRepositoryUpdate.java
new file mode 100644
index 000000000..32809f63c
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/v2/MavenManagedRepositoryUpdate.java
@@ -0,0 +1,47 @@
+package org.apache.archiva.rest.api.model.v2;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.archiva.repository.ManagedRepository;
+
+import java.io.Serializable;
+
+/**
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */
+public class MavenManagedRepositoryUpdate extends MavenManagedRepository implements Serializable
+{
+ private static final long serialVersionUID = -9181643343284109862L;
+ private boolean resetStats = false;
+
+ public static MavenManagedRepositoryUpdate of( ManagedRepository repository ) {
+ MavenManagedRepositoryUpdate repo = new MavenManagedRepositoryUpdate( );
+ update( repo, repository );
+ return repo;
+ }
+
+ public boolean isResetStats( )
+ {
+ return resetStats;
+ }
+
+ public void setResetStats( boolean resetStats )
+ {
+ this.resetStats = resetStats;
+ }
+}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/ErrorKeys.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/ErrorKeys.java
index 793f2d7d1..ab74ceaec 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/ErrorKeys.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/ErrorKeys.java
@@ -78,8 +78,48 @@ public interface ErrorKeys
String TASK_QUEUE_FAILED = PREFIX + "task.queue_failed";
String REPOSITORY_SCAN_FAILED = REPOSITORY_PREFIX + "scan.failed";
String ARTIFACT_EXISTS_AT_DEST = REPOSITORY_PREFIX + "artifact.dest.exists";
-
String REPOSITORY_REMOTE_INDEX_DOWNLOAD_FAILED = REPOSITORY_PREFIX + "remote.index.download_failed";
+ String REPOSITORY_WRONG_TYPE = REPOSITORY_PREFIX + "wrong_type";
+ String REPOSITORY_DELETE_FAILED = REPOSITORY_PREFIX + "delete.failed";
+ String REPOSITORY_INVALID_ID = REPOSITORY_PREFIX + "invalid.id";
+ String REPOSITORY_ID_EXISTS = REPOSITORY_PREFIX + "id.exists";
+ String REPOSITORY_UPDATE_FAILED = REPOSITORY_PREFIX + "update.failed";
+ String ARTIFACT_NOT_FOUND = REPOSITORY_PREFIX + "artifact.notfound";
+ String REPOSITORY_LAYOUT_ERROR = REPOSITORY_PREFIX + "layout.error";
+
+ String ARTIFACT_COPY_ERROR = REPOSITORY_PREFIX + "artifact.copy.error";
+
+ /**
+ * The given user was not found
+ * Parameters:
+ * - User Id
+ */
+ String USER_NOT_FOUND = PREFIX+"user.not_found";
+
+ /**
+ * Error from UserManager
+ * Parameters:
+ * - Error Message
+ */
+ String USER_MANAGER_ERROR = PREFIX+"user_manager.error";
+
+ /**
+ * Permission to the repository denied.
+ * Parameters:
+ * - Repository Id
+ * - Permission ID
+ */
+ String PERMISSION_REPOSITORY_DENIED = PREFIX + "permission.repository.denied";
+ /**
+ * A generic authorization error thrown during the authorization check.
+ * Parameters:
+ * - Error message
+ */
+ String AUTHORIZATION_ERROR = PREFIX + "authorization.error";
+ /**
+ * When the operation needs authentication, but not authenticated user was found in the request context.
+ */
+ String NOT_AUTHENTICATED = PREFIX + "user.not_authenticated";
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/MavenManagedRepositoryService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/MavenManagedRepositoryService.java
index dd931217c..5aff95ef6 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/MavenManagedRepositoryService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/MavenManagedRepositoryService.java
@@ -23,13 +23,14 @@ import io.swagger.v3.oas.annotations.headers.Header;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import io.swagger.v3.oas.annotations.security.OAuthScope;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.archiva.components.rest.model.PagedResult;
import org.apache.archiva.redback.authorization.RedbackAuthorization;
-import org.apache.archiva.rest.api.model.v2.Artifact;
import org.apache.archiva.rest.api.model.v2.FileInfo;
import org.apache.archiva.rest.api.model.v2.MavenManagedRepository;
+import org.apache.archiva.rest.api.model.v2.MavenManagedRepositoryUpdate;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import javax.ws.rs.Consumes;
@@ -199,14 +200,14 @@ public interface MavenManagedRepositoryService
content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
}
)
- MavenManagedRepository updateManagedRepository( MavenManagedRepository managedRepository )
+ MavenManagedRepository updateManagedRepository( @PathParam( "id" ) String repositoryId, MavenManagedRepositoryUpdate managedRepository )
throws ArchivaRestServiceException;
- @Path( "{id}/a/{filePath: .+}" )
+ @Path( "{id}/path/{filePath: .+}" )
@GET
@Produces( {MediaType.APPLICATION_JSON} )
- @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION )
+ @RedbackAuthorization( permissions = ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS, resource = "{id}")
@Operation( summary = "Returns the status of a given file in the repository",
security = {
@SecurityRequirement(
@@ -229,18 +230,28 @@ public interface MavenManagedRepositoryService
/**
- * permissions are checked in impl
+ * Permissions are checked in impl
* will copy an artifact from the source repository to the target repository
*/
- @Path ("{srcId}/a/{path: .+}/copyto/{dstId}")
+ @Path ("{srcId}/path/{path: .+}/copyto/{dstId}")
@POST
@Produces({APPLICATION_JSON})
@RedbackAuthorization (noPermission = true)
@Operation( summary = "Copies a artifact from the source repository to the destination repository",
security = {
@SecurityRequirement(
- name = ArchivaRoleConstants.OPERATION_RUN_INDEXER
+ name = ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS,
+ scopes = {
+ "{srcId}"
+ }
+ ),
+ @SecurityRequirement(
+ name= ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD,
+ scopes = {
+ "{dstId}"
+ }
)
+
},
responses = {
@ApiResponse( responseCode = "200",
@@ -257,7 +268,7 @@ public interface MavenManagedRepositoryService
throws ArchivaRestServiceException;
- @Path ("{id}/a/{path: .+}")
+ @Path ("{id}/path/{path: .+}")
@DELETE
@Consumes ({ APPLICATION_JSON })
@RedbackAuthorization (noPermission = true)
@@ -280,7 +291,7 @@ public interface MavenManagedRepositoryService
Response deleteArtifact( @PathParam( "id" ) String repositoryId, @PathParam( "path" ) String path )
throws ArchivaRestServiceException;
- @Path ("{id}/c/{namespace}/{projectId}/{version}")
+ @Path ( "{id}/co/{group}/{project}/{version}" )
@DELETE
@Produces ({ MediaType.APPLICATION_JSON })
@RedbackAuthorization (noPermission = true)
@@ -301,12 +312,12 @@ public interface MavenManagedRepositoryService
}
)
Response removeProjectVersion( @PathParam ( "id" ) String repositoryId,
- @PathParam ( "namespace" ) String namespace, @PathParam ( "projectId" ) String projectId,
- @PathParam ( "version" ) String version )
+ @PathParam ( "group" ) String namespace, @PathParam ( "project" ) String projectId,
+ @PathParam ( "version" ) String version )
throws org.apache.archiva.rest.api.services.ArchivaRestServiceException;
- @Path ( "{id}/c/{namespace}/{projectId}" )
+ @Path ( "{id}/co/{group}/{project}" )
@DELETE
@Produces ({ MediaType.APPLICATION_JSON })
@RedbackAuthorization (noPermission = true)
@@ -326,10 +337,10 @@ public interface MavenManagedRepositoryService
content = @Content( mediaType = APPLICATION_JSON, schema = @Schema( implementation = ArchivaRestError.class ) ) )
}
)
- Response deleteProject( @PathParam ("id") String repositoryId, @PathParam ( "namespace" ) String namespace, @PathParam ("projectId") String projectId )
+ Response deleteProject( @PathParam ("id") String repositoryId, @PathParam ( "group" ) String namespace, @PathParam ( "project" ) String projectId )
throws org.apache.archiva.rest.api.services.ArchivaRestServiceException;
- @Path ( "{id}/c/{namespace}" )
+ @Path ( "{id}/co/{namespace}" )
@DELETE
@Produces ({ MediaType.APPLICATION_JSON })
@RedbackAuthorization (noPermission = true)