Skip to content

Commit

Permalink
Check the validity of the json data
Browse files Browse the repository at this point in the history
  • Loading branch information
mackdk committed May 6, 2024
1 parent 0797994 commit d130c6e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
public class PaygAuthDataExtractor {

private static final Path PAYG_INSTANCE_INFO_JSON = Path.of("/var/cache/rhn/payg.json");

private static final int VALIDITY_MINUTES = 10;
private static final int VALIDITY_MINUTES = 11;

private static final String CONNECTION_TIMEOUT_PROPEERRTY = "java.payg.connection_timeout";
private static final String WAIT_RESPONSE_TIMEOUT_PROPEERRTY = "java.payg.repsonse_timeout";
Expand Down
10 changes: 9 additions & 1 deletion java/code/src/com/suse/cloud/CloudPaygManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
*/
public class CloudPaygManager {
private static final Logger LOG = LogManager.getLogger(CloudPaygManager.class);
public static final Path PAYG_COMPLIANCE_INFO_JSON = Path.of("/var/cache/rhn/payg_compliance.json");

private static final Path PAYG_COMPLIANCE_INFO_JSON = Path.of("/var/cache/rhn/payg_compliance.json");
private static final int VALIDITY_MINUTES = 11;

private final Gson gson = new GsonBuilder().create();

Expand Down Expand Up @@ -142,6 +144,12 @@ private boolean detectIsCompliant() {
// Parse the compliance info from the external json file, if available
complainceInfo = getInstanceComplianceInfo();

// Verify the information is correctly updated
if (Duration.between(complainceInfo.getTimestamp(), Instant.now()).toMinutes() > VALIDITY_MINUTES) {
LOG.error("The instance compliance info is not up-to-date.");
return false;
}

// If it's not payg, it's always compliant
if (!complainceInfo.isPaygInstance()) {
return true;
Expand Down

0 comments on commit d130c6e

Please sign in to comment.