Skip to content

Commit

Permalink
PaygInstanceInfo has a long as timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer committed May 25, 2024
1 parent 9e796de commit d41147b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Arrays;

Expand Down Expand Up @@ -242,7 +243,7 @@ private PaygInstanceInfo extractAuthDataSSH(PaygSshData instance) throws Excepti
protected PaygInstanceInfo extractAuthDataLocal() {
try (BufferedReader json = Files.newBufferedReader(PAYG_INSTANCE_INFO_JSON)) {
PaygInstanceInfo instanceInfo = GSON.fromJson(json, PaygInstanceInfo.class);
if (Duration.between(instanceInfo.getTimestamp(), LocalDateTime.now()).toMinutes() > VALIDITY_MINUTES) {
if (Duration.between(instanceInfo.getTimestamp(), Instant.now()).toMinutes() > VALIDITY_MINUTES) {
throw new PaygDataExtractException("Local PAYG Instance info is outdated.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import com.google.gson.annotations.SerializedName;

import java.time.LocalDateTime;
import java.time.Instant;
import java.util.List;
import java.util.Map;

Expand All @@ -37,7 +37,7 @@ public class PaygInstanceInfo {
@SerializedName("certs")
private Map<String, String> certificates;
@SerializedName("timestamp")
private LocalDateTime timestamp;
private long timestamp;

/**
* Constructor for type CLOUDRMT
Expand All @@ -53,7 +53,7 @@ public PaygInstanceInfo(List<PaygProductInfo> productsIn, Map<String, String> ba
this.basicAuth = basicAuthIn;
this.headerAuth = headerAuthIn;
this.rmtHost = rmtHostIn;
this.timestamp = LocalDateTime.now();
this.timestamp = Instant.now().getEpochSecond();
}

/**
Expand All @@ -68,7 +68,7 @@ public PaygInstanceInfo(Map<String, String> headerAuthIn, Map<String, String> ce
this.headerAuth = headerAuthIn;
this.certificates = certificatesIn;
this.repositories = repositoriesIn;
this.timestamp = LocalDateTime.now();
this.timestamp = Instant.now().getEpochSecond();
}

public String getType() {
Expand Down Expand Up @@ -127,11 +127,11 @@ public void setCertificates(Map<String, String> certificatesIn) {
certificates = certificatesIn;
}

public LocalDateTime getTimestamp() {
return timestamp;
public Instant getTimestamp() {
return Instant.ofEpochSecond(timestamp);
}

public void setTimestamp(LocalDateTime timestampIn) {
public void setTimestamp(long timestampIn) {
this.timestamp = timestampIn;
}
}
1 change: 1 addition & 0 deletions java/spacewalk-java.changes.mc.fix-payg-findings
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- fix PAYG data timestamp parsing

0 comments on commit d41147b

Please sign in to comment.