@devkong/cli 0.0.57 → 0.0.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +45 -36
- package/package.json +1 -1
- package/packages/kong-cli/src/services/api.d.ts +1 -2
package/index.js
CHANGED
|
@@ -50234,7 +50234,7 @@ var require_axios = __commonJS({
|
|
|
50234
50234
|
clarifyTimeoutError: false,
|
|
50235
50235
|
legacyInterceptorReqResOrdering: true
|
|
50236
50236
|
};
|
|
50237
|
-
var
|
|
50237
|
+
var URLSearchParams2 = url__default["default"].URLSearchParams;
|
|
50238
50238
|
var ALPHA2 = "abcdefghijklmnopqrstuvwxyz";
|
|
50239
50239
|
var DIGIT2 = "0123456789";
|
|
50240
50240
|
var ALPHABET2 = {
|
|
@@ -50255,7 +50255,7 @@ var require_axios = __commonJS({
|
|
|
50255
50255
|
var platform$1 = {
|
|
50256
50256
|
isNode: true,
|
|
50257
50257
|
classes: {
|
|
50258
|
-
URLSearchParams,
|
|
50258
|
+
URLSearchParams: URLSearchParams2,
|
|
50259
50259
|
FormData: FormData__default["default"],
|
|
50260
50260
|
Blob: typeof Blob !== "undefined" && Blob || null
|
|
50261
50261
|
},
|
|
@@ -87505,45 +87505,54 @@ function jwtDecode(token, options) {
|
|
|
87505
87505
|
}
|
|
87506
87506
|
|
|
87507
87507
|
// packages/kong-cli/src/services/api.ts
|
|
87508
|
-
async function provideRequestConfig(profile, cachedConfig) {
|
|
87509
|
-
if ("Authorization" in cachedConfig.headers) {
|
|
87510
|
-
const auth = cachedConfig.headers.Authorization;
|
|
87511
|
-
const accessToken = auth.split("Bearer ")[1].trim();
|
|
87512
|
-
const decoded = jwtDecode(accessToken);
|
|
87513
|
-
if (decoded.exp !== void 0) {
|
|
87514
|
-
const nowSeconds = Date.now() / 1e3;
|
|
87515
|
-
if (decoded.exp < nowSeconds - 30) {
|
|
87516
|
-
return cachedConfig;
|
|
87517
|
-
}
|
|
87518
|
-
}
|
|
87519
|
-
}
|
|
87520
|
-
const url2 = joinUrlAndPath(
|
|
87521
|
-
profile.kongBaseUrl,
|
|
87522
|
-
"api/keycloak/realms/kong/protocol/openid-connect/token"
|
|
87523
|
-
);
|
|
87524
|
-
const entry = new import_keyring2.Entry(profile.kongBaseUrl, profile.userName);
|
|
87525
|
-
const params = {
|
|
87526
|
-
grant_type: "password",
|
|
87527
|
-
client_id: "kong-web",
|
|
87528
|
-
username: profile.userName,
|
|
87529
|
-
password: entry.getPassword()
|
|
87530
|
-
};
|
|
87531
|
-
const token = (await axios_default.post(url2, params, {
|
|
87532
|
-
headers: {
|
|
87533
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
87534
|
-
}
|
|
87535
|
-
})).data;
|
|
87536
|
-
cachedConfig.headers["Authorization"] = `Bearer ${token.access_token}`;
|
|
87537
|
-
cachedConfig.headers["X-App-Tenant"] = parseTenant(profile.kongBaseUrl);
|
|
87538
|
-
return cachedConfig;
|
|
87539
|
-
}
|
|
87540
87508
|
function requestConfigProvider(profile) {
|
|
87541
87509
|
const cached = {
|
|
87542
87510
|
headers: {
|
|
87543
|
-
"Content-Type": "application/json"
|
|
87511
|
+
"Content-Type": "application/json",
|
|
87512
|
+
"X-App-Tenant": parseTenant(profile.kongBaseUrl)
|
|
87513
|
+
}
|
|
87514
|
+
};
|
|
87515
|
+
return async () => {
|
|
87516
|
+
if (cached.headers.Authorization) {
|
|
87517
|
+
try {
|
|
87518
|
+
const auth = cached.headers.Authorization;
|
|
87519
|
+
const accessToken = auth.split("Bearer ")[1]?.trim();
|
|
87520
|
+
if (accessToken) {
|
|
87521
|
+
const decoded = jwtDecode(accessToken);
|
|
87522
|
+
if (decoded.exp !== void 0) {
|
|
87523
|
+
const nowSeconds = Date.now() / 1e3;
|
|
87524
|
+
if (decoded.exp > nowSeconds + 60) {
|
|
87525
|
+
return cached;
|
|
87526
|
+
}
|
|
87527
|
+
}
|
|
87528
|
+
}
|
|
87529
|
+
} catch (ex) {
|
|
87530
|
+
console.warn("failed to use cached token, fetching new one", ex);
|
|
87531
|
+
}
|
|
87544
87532
|
}
|
|
87533
|
+
const url2 = joinUrlAndPath(
|
|
87534
|
+
profile.kongBaseUrl,
|
|
87535
|
+
"api/keycloak/realms/kong/protocol/openid-connect/token"
|
|
87536
|
+
);
|
|
87537
|
+
const entry = new import_keyring2.Entry(profile.kongBaseUrl, profile.userName);
|
|
87538
|
+
const password = entry.getPassword();
|
|
87539
|
+
if (!password) {
|
|
87540
|
+
throw new Error("No password found in keyring for user: " + profile.userName);
|
|
87541
|
+
}
|
|
87542
|
+
const params = new URLSearchParams({
|
|
87543
|
+
grant_type: "password",
|
|
87544
|
+
client_id: "kong-web",
|
|
87545
|
+
username: profile.userName,
|
|
87546
|
+
password
|
|
87547
|
+
});
|
|
87548
|
+
const response = await axios_default.post(url2, params, {
|
|
87549
|
+
headers: {
|
|
87550
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
87551
|
+
}
|
|
87552
|
+
});
|
|
87553
|
+
cached.headers["Authorization"] = `Bearer ${response.data.access_token}`;
|
|
87554
|
+
return cached;
|
|
87545
87555
|
};
|
|
87546
|
-
return async () => await provideRequestConfig(profile, cached);
|
|
87547
87556
|
}
|
|
87548
87557
|
|
|
87549
87558
|
// packages/kong-cli/src/services/managementClient.ts
|
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from "axios";
|
|
2
2
|
import { Profile } from "../common/profile";
|
|
3
3
|
export type RequestConfigProvider = () => Promise<AxiosRequestConfig>;
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function requestConfigProvider(profile: Profile): () => Promise<AxiosRequestConfig>;
|
|
4
|
+
export declare function requestConfigProvider(profile: Profile): RequestConfigProvider;
|