|
9 | 9 | import com.skyflow.logs.ErrorLogs; |
10 | 10 | import com.skyflow.logs.InfoLogs; |
11 | 11 | import com.skyflow.serviceaccount.util.BearerToken; |
| 12 | +import com.skyflow.serviceaccount.util.Token; |
12 | 13 | import com.skyflow.utils.logger.LogUtil; |
13 | 14 | import org.apache.commons.codec.binary.Base64; |
14 | 15 |
|
@@ -43,23 +44,31 @@ public static String getVaultURL(String clusterId, Env env, String vaultDomain) |
43 | 44 | } |
44 | 45 |
|
45 | 46 | public static String generateBearerToken(Credentials credentials) throws SkyflowException { |
| 47 | + String bearerToken; |
46 | 48 | if (credentials.getPath() != null) { |
47 | | - return BearerToken.builder() |
| 49 | + bearerToken = BearerToken.builder() |
48 | 50 | .setCredentials(new File(credentials.getPath())) |
49 | 51 | .setRoles(credentials.getRoles()) |
50 | 52 | .setCtx(credentials.getContext()) |
51 | 53 | .build() |
52 | 54 | .getBearerToken(); |
53 | 55 | } else if (credentials.getCredentialsString() != null) { |
54 | | - return BearerToken.builder() |
| 56 | + bearerToken = BearerToken.builder() |
55 | 57 | .setCredentials(credentials.getCredentialsString()) |
56 | 58 | .setRoles(credentials.getRoles()) |
57 | 59 | .setCtx(credentials.getContext()) |
58 | 60 | .build() |
59 | 61 | .getBearerToken(); |
60 | 62 | } else { |
61 | | - return credentials.getToken(); |
| 63 | + LogUtil.printInfoLog(InfoLogs.USE_CLIENT_PROVIDED_BEARER_TOKEN.getLog()); |
| 64 | + bearerToken = credentials.getToken(); |
62 | 65 | } |
| 66 | + // check expiry for generated token |
| 67 | + if (Token.isExpired(bearerToken)) { |
| 68 | + LogUtil.printErrorLog(ErrorLogs.INVALID_BEARER_TOKEN.getLog()); |
| 69 | + throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.BearerTokenExpired.getMessage()); |
| 70 | + } |
| 71 | + return bearerToken; |
63 | 72 | } |
64 | 73 |
|
65 | 74 | public static PrivateKey getPrivateKeyFromPem(String pemKey) throws SkyflowException { |
|
0 commit comments