@devkong/cli 0.0.67-2 → 0.0.67-3
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
CHANGED
|
@@ -86932,9 +86932,7 @@ var KONG_CONFIG_PATH = import_path3.default.join(KONG_CONFIG_DIR, "config");
|
|
|
86932
86932
|
function createEmptyProfile() {
|
|
86933
86933
|
return {
|
|
86934
86934
|
kongBaseUrl: urlText(""),
|
|
86935
|
-
userName: ""
|
|
86936
|
-
authType: "local",
|
|
86937
|
-
idpHint: "azure"
|
|
86935
|
+
userName: ""
|
|
86938
86936
|
};
|
|
86939
86937
|
}
|
|
86940
86938
|
function loadProfiles() {
|
|
@@ -86955,14 +86953,12 @@ function getProfile(name) {
|
|
|
86955
86953
|
const availableProfiles = loadProfiles();
|
|
86956
86954
|
const profile = availableProfiles[name] || createEmptyProfile();
|
|
86957
86955
|
profile.kongBaseUrl = profile.kongBaseUrl || urlText(optionalEnv("KONG_BASE_URL") || "");
|
|
86958
|
-
profile.authType = profile.authType || "local";
|
|
86959
|
-
profile.idpHint = profile.idpHint || "azure";
|
|
86960
86956
|
return profile;
|
|
86961
86957
|
}
|
|
86962
86958
|
function printProfile(name) {
|
|
86963
86959
|
const profileData = getProfile(name);
|
|
86964
86960
|
console.info(
|
|
86965
|
-
`Current profile=${name}, baseUrl=${profileData.kongBaseUrl}, username=${profileData.userName}
|
|
86961
|
+
`Current profile=${name}, baseUrl=${profileData.kongBaseUrl}, username=${profileData.userName}`
|
|
86966
86962
|
);
|
|
86967
86963
|
}
|
|
86968
86964
|
|
|
@@ -87029,7 +87025,7 @@ function jwtDecode(token, options) {
|
|
|
87029
87025
|
// packages/kong-cli/src/services/browserLogin.ts
|
|
87030
87026
|
var import_node_http = __toESM(require("node:http"));
|
|
87031
87027
|
var import_url3 = require("url");
|
|
87032
|
-
async function loginWithBrowser(kongBaseUrl
|
|
87028
|
+
async function loginWithBrowser(kongBaseUrl) {
|
|
87033
87029
|
const state = import_crypto2.default.randomUUID();
|
|
87034
87030
|
const baseUrl = normalizeBaseUrl(kongBaseUrl);
|
|
87035
87031
|
return new Promise((resolve2, reject) => {
|
|
@@ -87045,9 +87041,6 @@ async function loginWithBrowser(kongBaseUrl, verbose = false) {
|
|
|
87045
87041
|
authUrl.searchParams.set("scope", "openid profile email offline_access");
|
|
87046
87042
|
authUrl.searchParams.set("state", state);
|
|
87047
87043
|
const authUrlString = authUrl.toString();
|
|
87048
|
-
if (verbose) {
|
|
87049
|
-
console.log(`Redirect URI: ${redirectUri}`);
|
|
87050
|
-
}
|
|
87051
87044
|
console.log("Signing in with the browser...");
|
|
87052
87045
|
await openBrowser(authUrlString);
|
|
87053
87046
|
console.log("If your browser didn't open, click this link to log in:\n");
|
|
@@ -87131,9 +87124,6 @@ async function openBrowser(url2) {
|
|
|
87131
87124
|
|
|
87132
87125
|
// packages/kong-cli/src/commands/configureCommand.ts
|
|
87133
87126
|
var ConfigureCommand = class {
|
|
87134
|
-
constructor(verbose = false) {
|
|
87135
|
-
this.verbose = verbose;
|
|
87136
|
-
}
|
|
87137
87127
|
async execute() {
|
|
87138
87128
|
const availableProfiles = loadProfiles();
|
|
87139
87129
|
const [name, profile] = await this.selectProfile(availableProfiles);
|
|
@@ -87166,7 +87156,7 @@ var ConfigureCommand = class {
|
|
|
87166
87156
|
message: `Enter URL for profile "${name}":`,
|
|
87167
87157
|
default: profile.kongBaseUrl
|
|
87168
87158
|
});
|
|
87169
|
-
const tokens = await loginWithBrowser(urlText(answerUrl.kongUrl)
|
|
87159
|
+
const tokens = await loginWithBrowser(urlText(answerUrl.kongUrl));
|
|
87170
87160
|
const tokenUserName = tokens.preferredUsername || tokens.email || profile.userName;
|
|
87171
87161
|
if (isEmpty(tokenUserName)) {
|
|
87172
87162
|
throw new Error("Unable to determine domain user name from the token");
|
|
@@ -87174,8 +87164,7 @@ var ConfigureCommand = class {
|
|
|
87174
87164
|
const updated = {
|
|
87175
87165
|
...profile,
|
|
87176
87166
|
kongBaseUrl: urlText(answerUrl.kongUrl),
|
|
87177
|
-
userName: tokenUserName
|
|
87178
|
-
authType: "domain"
|
|
87167
|
+
userName: tokenUserName
|
|
87179
87168
|
};
|
|
87180
87169
|
const keyringEntry = new import_keyring.Entry(updated.kongBaseUrl, updated.userName);
|
|
87181
87170
|
keyringEntry.setPassword(
|
|
@@ -89279,51 +89268,24 @@ function requestConfigProvider(profile) {
|
|
|
89279
89268
|
"api/keycloak/realms/kong/protocol/openid-connect/token"
|
|
89280
89269
|
);
|
|
89281
89270
|
const entry = new import_keyring2.Entry(profile.kongBaseUrl, profile.userName);
|
|
89282
|
-
const
|
|
89283
|
-
if (!
|
|
89284
|
-
throw new Error("No
|
|
89285
|
-
}
|
|
89286
|
-
const params =
|
|
89271
|
+
const refreshToken = entry.getPassword();
|
|
89272
|
+
if (!refreshToken) {
|
|
89273
|
+
throw new Error("No refreshToken found in keyring for user: " + profile.userName);
|
|
89274
|
+
}
|
|
89275
|
+
const params = new URLSearchParams({
|
|
89276
|
+
grant_type: "refresh_token",
|
|
89277
|
+
client_id: "kong-web",
|
|
89278
|
+
refresh_token: refreshToken
|
|
89279
|
+
});
|
|
89287
89280
|
const response = await axios_default.post(url2, params, {
|
|
89288
89281
|
headers: {
|
|
89289
89282
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
89290
89283
|
}
|
|
89291
89284
|
});
|
|
89292
89285
|
cached.headers["Authorization"] = `Bearer ${response.data.access_token}`;
|
|
89293
|
-
if (profile.authType === "domain" && response.data.refresh_token) {
|
|
89294
|
-
entry.setPassword(
|
|
89295
|
-
JSON.stringify({
|
|
89296
|
-
mode: "domain",
|
|
89297
|
-
refreshToken: response.data.refresh_token
|
|
89298
|
-
})
|
|
89299
|
-
);
|
|
89300
|
-
}
|
|
89301
89286
|
return cached;
|
|
89302
89287
|
};
|
|
89303
89288
|
}
|
|
89304
|
-
function buildTokenParams(profile, secret) {
|
|
89305
|
-
if (profile.authType === "domain") {
|
|
89306
|
-
try {
|
|
89307
|
-
const saved = JSON.parse(secret);
|
|
89308
|
-
if (saved.mode === "domain" && saved.refreshToken) {
|
|
89309
|
-
return new URLSearchParams({
|
|
89310
|
-
grant_type: "refresh_token",
|
|
89311
|
-
client_id: "kong-web",
|
|
89312
|
-
refresh_token: saved.refreshToken
|
|
89313
|
-
});
|
|
89314
|
-
}
|
|
89315
|
-
} catch {
|
|
89316
|
-
throw new Error("Domain login requires refresh token in keyring. Re-run `kong configure`.");
|
|
89317
|
-
}
|
|
89318
|
-
throw new Error("Domain login requires refresh token in keyring. Re-run `kong configure`.");
|
|
89319
|
-
}
|
|
89320
|
-
return new URLSearchParams({
|
|
89321
|
-
grant_type: "password",
|
|
89322
|
-
client_id: "kong-web",
|
|
89323
|
-
username: profile.userName,
|
|
89324
|
-
password: secret
|
|
89325
|
-
});
|
|
89326
|
-
}
|
|
89327
89289
|
|
|
89328
89290
|
// packages/kong-cli/src/services/managementClient.ts
|
|
89329
89291
|
var ManagementClient = class {
|
|
@@ -89806,8 +89768,8 @@ async function main() {
|
|
|
89806
89768
|
printError("generate command failed", ex);
|
|
89807
89769
|
}
|
|
89808
89770
|
});
|
|
89809
|
-
const configureCommand = new Command("configure").description("Configure access to kong environments").
|
|
89810
|
-
await new ConfigureCommand(
|
|
89771
|
+
const configureCommand = new Command("configure").description("Configure access to kong environments").action(async () => {
|
|
89772
|
+
await new ConfigureCommand().execute();
|
|
89811
89773
|
});
|
|
89812
89774
|
const installCommand = new Command("install").description("Setup virtual environment and install dependencies").addOption(new Option("--verbose", "Show full logs during command execution")).action(async (options) => {
|
|
89813
89775
|
try {
|
package/package.json
CHANGED
|
@@ -2,8 +2,6 @@ import { UrlText } from "@kong/ts";
|
|
|
2
2
|
export interface Profile {
|
|
3
3
|
kongBaseUrl: UrlText;
|
|
4
4
|
userName: string;
|
|
5
|
-
authType?: "local" | "domain";
|
|
6
|
-
idpHint?: string;
|
|
7
5
|
}
|
|
8
6
|
export type ProfileName = "default" | string;
|
|
9
7
|
export type ProfileMap = Record<ProfileName, Profile>;
|
|
@@ -5,4 +5,4 @@ export interface DomainLoginTokens {
|
|
|
5
5
|
preferredUsername?: string;
|
|
6
6
|
email?: string;
|
|
7
7
|
}
|
|
8
|
-
export declare function loginWithBrowser(kongBaseUrl: string
|
|
8
|
+
export declare function loginWithBrowser(kongBaseUrl: string): Promise<DomainLoginTokens>;
|