mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 17:30:46 +00:00
WIP
This commit is contained in:
@@ -18,6 +18,7 @@ import { SignInButton } from "./Platform/Hosted/Components/SignInButton";
|
|||||||
import { useAADAuth } from "./hooks/useAADAuth";
|
import { useAADAuth } from "./hooks/useAADAuth";
|
||||||
import { FeedbackCommandButton } from "./Platform/Hosted/Components/FeedbackCommandButton";
|
import { FeedbackCommandButton } from "./Platform/Hosted/Components/FeedbackCommandButton";
|
||||||
import { HostedExplorerChildFrame } from "./HostedExplorerChildFrame";
|
import { HostedExplorerChildFrame } from "./HostedExplorerChildFrame";
|
||||||
|
import { extractMasterKeyfromConnectionString } from "./Platform/Hosted/HostedUtils";
|
||||||
|
|
||||||
initializeIcons();
|
initializeIcons();
|
||||||
|
|
||||||
@@ -60,7 +61,8 @@ const App: React.FunctionComponent = () => {
|
|||||||
frameWindow.hostedConfig = {
|
frameWindow.hostedConfig = {
|
||||||
authType: AuthType.ConnectionString,
|
authType: AuthType.ConnectionString,
|
||||||
encryptedToken,
|
encryptedToken,
|
||||||
encryptedTokenMetadata
|
encryptedTokenMetadata,
|
||||||
|
masterKey: extractMasterKeyfromConnectionString(connectionString)
|
||||||
};
|
};
|
||||||
} else if (authType === AuthType.ResourceToken) {
|
} else if (authType === AuthType.ResourceToken) {
|
||||||
frameWindow.hostedConfig = {
|
frameWindow.hostedConfig = {
|
||||||
|
|||||||
30
src/Main.tsx
30
src/Main.tsx
@@ -80,9 +80,7 @@ import {
|
|||||||
getDatabaseAccountKindFromExperience,
|
getDatabaseAccountKindFromExperience,
|
||||||
getDatabaseAccountPropertiesFromMetadata
|
getDatabaseAccountPropertiesFromMetadata
|
||||||
} from "./Platform/Hosted/HostedUtils";
|
} from "./Platform/Hosted/HostedUtils";
|
||||||
|
import { DefaultExperienceUtility } from "./Shared/DefaultExperienceUtility";
|
||||||
// TODO: Encapsulate and reuse all global variables as environment variables
|
|
||||||
window.authType = AuthType.AAD;
|
|
||||||
|
|
||||||
// const accountResourceId =
|
// const accountResourceId =
|
||||||
// authType === AuthType.EncryptedToken
|
// authType === AuthType.EncryptedToken
|
||||||
@@ -111,16 +109,15 @@ const App: React.FunctionComponent = () => {
|
|||||||
accessToken: encodeURIComponent(win.hostedConfig.encryptedToken)
|
accessToken: encodeURIComponent(win.hostedConfig.encryptedToken)
|
||||||
});
|
});
|
||||||
|
|
||||||
// const apiExperience: string = DefaultExperienceUtility.getDefaultExperienceFromApiKind(
|
const apiExperience: string = DefaultExperienceUtility.getDefaultExperienceFromApiKind(
|
||||||
// Main._accessInputMetadata.apiKind
|
win.hostedConfig.encryptedTokenMetadata.apiKind
|
||||||
// );
|
);
|
||||||
explorer.initDataExplorerWithFrameInputs({
|
explorer.initDataExplorerWithFrameInputs({
|
||||||
databaseAccount: {
|
databaseAccount: {
|
||||||
id: "",
|
id: "",
|
||||||
// id: Main._databaseAccountId,
|
// id: Main._databaseAccountId,
|
||||||
name: win.hostedConfig.encryptedTokenMetadata.accountName,
|
name: win.hostedConfig.encryptedTokenMetadata.accountName,
|
||||||
kind: "",
|
kind: getDatabaseAccountKindFromExperience(apiExperience),
|
||||||
kind: getDatabaseAccountKindFromExperience(win.hostedConfig.encryptedTokenMetadata.apiKind),
|
|
||||||
properties: getDatabaseAccountPropertiesFromMetadata(win.hostedConfig.encryptedTokenMetadata),
|
properties: getDatabaseAccountPropertiesFromMetadata(win.hostedConfig.encryptedTokenMetadata),
|
||||||
tags: []
|
tags: []
|
||||||
},
|
},
|
||||||
@@ -140,11 +137,14 @@ const App: React.FunctionComponent = () => {
|
|||||||
isTryCosmosDBSubscription: explorer.isTryCosmosDBSubscription()
|
isTryCosmosDBSubscription: explorer.isTryCosmosDBSubscription()
|
||||||
});
|
});
|
||||||
explorer.isAccountReady(true);
|
explorer.isAccountReady(true);
|
||||||
} else if (window.authType === AuthType.ResourceToken) {
|
} else if (win.hostedConfig.authType === AuthType.ResourceToken) {
|
||||||
} else if (window.authType === AuthType.ConnectionString) {
|
window.authType = AuthType.EncryptedToken;
|
||||||
} else if (window.authType === AuthType.AAD) {
|
} else if (win.hostedConfig.authType === AuthType.ConnectionString) {
|
||||||
const account = window.databaseAccount;
|
// This might seem weird, but for legacy reasons lots of code expects a connection string login to look and act like an encrypted token login
|
||||||
const serverId = AuthHeadersUtil.serverId;
|
window.authType = AuthType.EncryptedToken;
|
||||||
|
} else if (win.hostedConfig.authType === AuthType.AAD) {
|
||||||
|
window.authType = AuthType.AAD;
|
||||||
|
const account = win.hostedConfig.databaseAccount;
|
||||||
const accountResourceId = account.id;
|
const accountResourceId = account.id;
|
||||||
const subscriptionId = accountResourceId && accountResourceId.split("subscriptions/")[1].split("/")[0];
|
const subscriptionId = accountResourceId && accountResourceId.split("subscriptions/")[1].split("/")[0];
|
||||||
const resourceGroup = accountResourceId && accountResourceId.split("resourceGroups/")[1].split("/")[0];
|
const resourceGroup = accountResourceId && accountResourceId.split("resourceGroups/")[1].split("/")[0];
|
||||||
@@ -154,11 +154,11 @@ const App: React.FunctionComponent = () => {
|
|||||||
resourceGroup,
|
resourceGroup,
|
||||||
masterKey: "",
|
masterKey: "",
|
||||||
hasWriteAccess: true, //TODO: 425017 - support read access
|
hasWriteAccess: true, //TODO: 425017 - support read access
|
||||||
authorizationToken: `Bearer ${window.authorizationToken}`,
|
authorizationToken: `Bearer ${win.hostedConfig.authorizationToken}`,
|
||||||
features: extractFeatures(),
|
features: extractFeatures(),
|
||||||
csmEndpoint: undefined,
|
csmEndpoint: undefined,
|
||||||
dnsSuffix: undefined,
|
dnsSuffix: undefined,
|
||||||
serverId: serverId,
|
serverId: AuthHeadersUtil.serverId,
|
||||||
extensionEndpoint: configContext.BACKEND_ENDPOINT,
|
extensionEndpoint: configContext.BACKEND_ENDPOINT,
|
||||||
subscriptionType: CollectionCreation.DefaultSubscriptionType,
|
subscriptionType: CollectionCreation.DefaultSubscriptionType,
|
||||||
quotaId: undefined,
|
quotaId: undefined,
|
||||||
|
|||||||
@@ -43,3 +43,9 @@ export function getDatabaseAccountKindFromExperience(apiExperience: string): str
|
|||||||
|
|
||||||
return Constants.AccountKind.GlobalDocumentDB;
|
return Constants.AccountKind.GlobalDocumentDB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function extractMasterKeyfromConnectionString(connectionString: string): string {
|
||||||
|
// Only Gremlin uses the actual master key for connection to cosmos
|
||||||
|
const matchedParts: string[] = connectionString.match("AccountKey=(.*);ApiKind=Gremlin;$");
|
||||||
|
return (matchedParts.length > 1 && matchedParts[1]) || undefined;
|
||||||
|
}
|
||||||
|
|||||||
@@ -119,9 +119,4 @@ export default class Main {
|
|||||||
|
|
||||||
throw new Error(`Unsupported AuthType ${authType}`);
|
throw new Error(`Unsupported AuthType ${authType}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static _getMasterKeyFromConnectionString(connectionString: string): string {
|
|
||||||
const matchedParts: string[] = connectionString.match("AccountKey=(.*);ApiKind=Gremlin;$");
|
|
||||||
return (matchedParts.length > 1 && matchedParts[1]) || undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user