Skip to content

Commit

Permalink
simplify logic in OSS STS
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenRi committed Nov 17, 2022
1 parent 0b82ffa commit 25ca781
Showing 1 changed file with 2 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,8 @@ private void initializeOssClient(UnderFileSystemConfiguration ossConfiguration)
}

boolean tokenWillExpiredAfter(long after) {
boolean in = true;
Date now = convertLongToDate(System.currentTimeMillis());
if (null != mStsTokenExpiration && mStsTokenExpiration.getTime() - now.getTime() > after) {
in = false;
}
return in;
return null == mStsTokenExpiration
|| mStsTokenExpiration.getTime() - System.currentTimeMillis() <= after;
}

private void createOrRefreshStsOssClient(
Expand Down Expand Up @@ -195,19 +191,6 @@ public OSS getOSSClient() {
return mOssClient;
}

private Date convertLongToDate(long timeMs) {
TimeZone zeroTimeZone = TimeZone.getTimeZone("ETC/GMT-0");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
sdf.setTimeZone(zeroTimeZone);
Date date = null;
try {
date = sdf.parse(sdf.format(new Date(timeMs)));
} catch (ParseException e) {
LOG.error("convert String to Date type error", e);
}
return date;
}

private Date convertStringToDate(String dateString) {
TimeZone zeroTimeZone = TimeZone.getTimeZone("ETC/GMT-0");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Expand Down

0 comments on commit 25ca781

Please sign in to comment.