-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,025 additions
and
926 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
backend/src/main/java/org/cryptomator/hub/api/LicenseResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.cryptomator.hub.api; | ||
|
||
import com.auth0.jwt.interfaces.DecodedJWT; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
import org.cryptomator.hub.entities.EffectiveVaultAccess; | ||
import org.cryptomator.hub.license.LicenseHolder; | ||
import org.eclipse.microprofile.openapi.annotations.Operation; | ||
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; | ||
|
||
import java.time.Instant; | ||
import java.util.Optional; | ||
|
||
@Path("/license") | ||
public class LicenseResource { | ||
|
||
@Inject | ||
LicenseHolder licenseHolder; | ||
|
||
@GET | ||
@Path("/user-info") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@RolesAllowed("user") | ||
@Operation(summary = "Get license information for regular users", description = "Information includes the licensed seats, the already used seats and if defined, the license expiration date.") | ||
@APIResponse(responseCode = "200") | ||
public LicenseUserInfoDto get() { | ||
return LicenseUserInfoDto.create(licenseHolder); | ||
} | ||
|
||
|
||
public record LicenseUserInfoDto(@JsonProperty("licensedSeats") Integer licensedSeats, | ||
@JsonProperty("usedSeats") Integer usedSeats, | ||
@JsonProperty("expiresAt") Instant expiresAt) { | ||
|
||
public static LicenseUserInfoDto create(LicenseHolder licenseHolder) { | ||
var licensedSeats = (int) licenseHolder.getSeats(); | ||
var usedSeats = (int) EffectiveVaultAccess.countSeatOccupyingUsers(); | ||
var expiresAt = Optional.ofNullable(licenseHolder.get()).map(DecodedJWT::getExpiresAtAsInstant).orElse(null); | ||
return new LicenseUserInfoDto(licensedSeats, usedSeats, expiresAt); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.