public gpg key download on management screen

This commit is contained in:
Konstantin Schaper
2020-08-05 21:23:55 +02:00
parent 0ac8b90c2f
commit acaf70feab
10 changed files with 30 additions and 12 deletions

View File

@@ -61,6 +61,7 @@ public abstract class PublicKeyMapper {
if (UserPermissions.changePublicKeys(rawGpgKey.getOwner()).isPermitted() && !rawGpgKey.isReadonly()) {
linksBuilder.single(Link.link("delete", createDeleteLink(rawGpgKey)));
}
linksBuilder.single(Link.link("raw", createDownloadLink(rawGpgKey)));
return new RawGpgKeyDto(linksBuilder.build());
}
@@ -77,4 +78,11 @@ public abstract class PublicKeyMapper {
.parameters(rawGpgKey.getOwner(), rawGpgKey.getId())
.href();
}
private String createDownloadLink(RawGpgKey rawGpgKey) {
return new LinkBuilder(scmPathInfoStore.get().get(), PublicKeyResource.class)
.method("findByIdGpg")
.parameters(rawGpgKey.getId())
.href();
}
}

View File

@@ -90,7 +90,9 @@ public class PublicKeyResource {
public Response findByIdGpg(@PathParam("id") String id) {
Optional<RawGpgKey> byId = store.findById(id);
if (byId.isPresent()) {
return Response.ok(byId.get().getRaw()).build();
return Response.ok(byId.get().getRaw())
.header("Content-Disposition", "attachment; filename=\"" + byId.get().getDisplayName() + ".asc\"")
.build();
}
return Response.status(Response.Status.NOT_FOUND).build();
}