mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-21 01:41:31 +00:00
Prettier 2.0 (#393)
This commit is contained in:
@@ -7,12 +7,12 @@ export const emulatorAccount = {
|
||||
type: "",
|
||||
kind: AccountKind.DocumentDB,
|
||||
tags: {
|
||||
[TagNames.defaultExperience]: DefaultAccountExperience.DocumentDB
|
||||
[TagNames.defaultExperience]: DefaultAccountExperience.DocumentDB,
|
||||
},
|
||||
properties: {
|
||||
documentEndpoint: "",
|
||||
tableEndpoint: "",
|
||||
gremlinEndpoint: "",
|
||||
cassandraEndpoint: ""
|
||||
}
|
||||
cassandraEndpoint: "",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ export default class AuthHeadersUtil {
|
||||
type: "POST",
|
||||
headers: headers,
|
||||
contentType: "application/json",
|
||||
cache: false
|
||||
cache: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ export default class AuthHeadersUtil {
|
||||
type: "POST",
|
||||
headers: headers,
|
||||
contentType: "application/json",
|
||||
cache: false
|
||||
cache: false,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ it("calls setAccount from parent component", () => {
|
||||
const setDatabaseAccount = jest.fn();
|
||||
const subscriptions = [
|
||||
{ subscriptionId: "testSub1", displayName: "Test Sub 1" },
|
||||
{ subscriptionId: "testSub2", displayName: "Test Sub 2" }
|
||||
{ subscriptionId: "testSub2", displayName: "Test Sub 2" },
|
||||
] as Subscription[];
|
||||
(useSubscriptions as jest.Mock).mockReturnValue(subscriptions);
|
||||
const accounts = [{ name: "testAccount1" }, { name: "testAccount2" }] as DatabaseAccount[];
|
||||
|
||||
@@ -20,27 +20,27 @@ const buttonStyles: IButtonStyles = {
|
||||
paddingLeft: 10,
|
||||
marginRight: 5,
|
||||
backgroundColor: StyleConstants.BaseDark,
|
||||
color: StyleConstants.BaseLight
|
||||
color: StyleConstants.BaseLight,
|
||||
},
|
||||
rootHovered: {
|
||||
backgroundColor: StyleConstants.BaseHigh,
|
||||
color: StyleConstants.BaseLight
|
||||
color: StyleConstants.BaseLight,
|
||||
},
|
||||
rootFocused: {
|
||||
backgroundColor: StyleConstants.BaseHigh,
|
||||
color: StyleConstants.BaseLight
|
||||
color: StyleConstants.BaseLight,
|
||||
},
|
||||
rootPressed: {
|
||||
backgroundColor: StyleConstants.BaseHigh,
|
||||
color: StyleConstants.BaseLight
|
||||
color: StyleConstants.BaseLight,
|
||||
},
|
||||
rootExpanded: {
|
||||
backgroundColor: StyleConstants.BaseHigh,
|
||||
color: StyleConstants.BaseLight
|
||||
color: StyleConstants.BaseLight,
|
||||
},
|
||||
textContainer: {
|
||||
flexGrow: "initial"
|
||||
}
|
||||
flexGrow: "initial",
|
||||
},
|
||||
};
|
||||
|
||||
interface Props {
|
||||
@@ -53,12 +53,12 @@ export const AccountSwitcher: FunctionComponent<Props> = ({ armToken, setDatabas
|
||||
const [selectedSubscriptionId, setSelectedSubscriptionId] = useState<string>(() =>
|
||||
localStorage.getItem("cachedSubscriptionId")
|
||||
);
|
||||
const selectedSubscription = subscriptions?.find(sub => sub.subscriptionId === selectedSubscriptionId);
|
||||
const selectedSubscription = subscriptions?.find((sub) => sub.subscriptionId === selectedSubscriptionId);
|
||||
const accounts = useDatabaseAccounts(selectedSubscription?.subscriptionId, armToken);
|
||||
const [selectedAccountName, setSelectedAccountName] = useState<string>(() =>
|
||||
localStorage.getItem("cachedDatabaseAccountName")
|
||||
);
|
||||
const selectedAccount = accounts?.find(account => account.name === selectedAccountName);
|
||||
const selectedAccount = accounts?.find((account) => account.name === selectedAccountName);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedAccountName) {
|
||||
@@ -83,14 +83,14 @@ export const AccountSwitcher: FunctionComponent<Props> = ({ armToken, setDatabas
|
||||
const items: IContextualMenuItem[] = [
|
||||
{
|
||||
key: "switchSubscription",
|
||||
onRender: () => <SwitchSubscription {...{ subscriptions, setSelectedSubscriptionId, selectedSubscription }} />
|
||||
onRender: () => <SwitchSubscription {...{ subscriptions, setSelectedSubscriptionId, selectedSubscription }} />,
|
||||
},
|
||||
{
|
||||
key: "switchAccount",
|
||||
onRender: (_, dismissMenu) => (
|
||||
<SwitchAccount {...{ accounts, dismissMenu, selectedAccount, setSelectedAccountName }} />
|
||||
)
|
||||
}
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
@@ -99,7 +99,7 @@ export const AccountSwitcher: FunctionComponent<Props> = ({ armToken, setDatabas
|
||||
menuProps={{
|
||||
directionalHintFixed: true,
|
||||
className: "accountSwitchContextualMenu",
|
||||
items
|
||||
items,
|
||||
}}
|
||||
styles={buttonStyles}
|
||||
className="accountSwitchButton"
|
||||
|
||||
@@ -19,7 +19,7 @@ export const ConnectExplorer: React.FunctionComponent<Props> = ({
|
||||
login,
|
||||
setAuthType,
|
||||
connectionString,
|
||||
setConnectionString
|
||||
setConnectionString,
|
||||
}: Props) => {
|
||||
const [isFormVisible, { setTrue: showForm }] = useBoolean(false);
|
||||
|
||||
@@ -34,7 +34,7 @@ export const ConnectExplorer: React.FunctionComponent<Props> = ({
|
||||
{isFormVisible ? (
|
||||
<form
|
||||
id="connectWithConnectionString"
|
||||
onSubmit={async event => {
|
||||
onSubmit={async (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
if (isResourceTokenConnectionString(connectionString)) {
|
||||
@@ -63,7 +63,7 @@ export const ConnectExplorer: React.FunctionComponent<Props> = ({
|
||||
required
|
||||
placeholder="Please enter a connection string"
|
||||
value={connectionString}
|
||||
onChange={event => {
|
||||
onChange={(event) => {
|
||||
setConnectionString(event.target.value);
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -12,7 +12,7 @@ it("switches tenant for user", () => {
|
||||
const dismissPanel = jest.fn();
|
||||
const directories = [
|
||||
{ displayName: "test1", tenantId: "test1-id" },
|
||||
{ displayName: "test2", tenantId: "test2-id" }
|
||||
{ displayName: "test2", tenantId: "test2-id" },
|
||||
] as Tenant[];
|
||||
(useDirectories as jest.Mock).mockReturnValue(directories);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export const DirectoryPickerPanel: React.FunctionComponent<Props> = ({
|
||||
dismissPanel,
|
||||
armToken,
|
||||
tenantId,
|
||||
switchTenant
|
||||
switchTenant,
|
||||
}: Props) => {
|
||||
const directories = useDirectories(armToken);
|
||||
return (
|
||||
@@ -27,7 +27,7 @@ export const DirectoryPickerPanel: React.FunctionComponent<Props> = ({
|
||||
closeButtonAriaLabel="Close"
|
||||
>
|
||||
<ChoiceGroup
|
||||
options={directories.map(dir => ({ key: dir.tenantId, text: `${dir.displayName} (${dir.tenantId})` }))}
|
||||
options={directories.map((dir) => ({ key: dir.tenantId, text: `${dir.displayName} (${dir.tenantId})` }))}
|
||||
selectedKey={tenantId}
|
||||
onChange={(event, option) => {
|
||||
switchTenant(option.key);
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
DirectionalHint,
|
||||
Persona,
|
||||
PersonaInitialsColor,
|
||||
PersonaSize
|
||||
PersonaSize,
|
||||
} from "office-ui-fabric-react";
|
||||
import * as React from "react";
|
||||
import { Account } from "msal";
|
||||
@@ -30,26 +30,26 @@ export const MeControl: React.FunctionComponent<Props> = ({ openPanel, logout, a
|
||||
directionalHintFixed: true,
|
||||
directionalHint: DirectionalHint.bottomRightEdge,
|
||||
calloutProps: {
|
||||
minPagePadding: 0
|
||||
minPagePadding: 0,
|
||||
},
|
||||
items: [
|
||||
{
|
||||
key: "SwitchDirectory",
|
||||
text: "Switch Directory",
|
||||
onClick: openPanel
|
||||
onClick: openPanel,
|
||||
},
|
||||
{
|
||||
key: "SignOut",
|
||||
text: "Sign Out",
|
||||
onClick: logout
|
||||
}
|
||||
]
|
||||
onClick: logout,
|
||||
},
|
||||
],
|
||||
}}
|
||||
styles={{
|
||||
rootHovered: { backgroundColor: "#393939" },
|
||||
rootFocused: { backgroundColor: "#393939" },
|
||||
rootPressed: { backgroundColor: "#393939" },
|
||||
rootExpanded: { backgroundColor: "#393939" }
|
||||
rootExpanded: { backgroundColor: "#393939" },
|
||||
}}
|
||||
>
|
||||
<Persona
|
||||
|
||||
@@ -14,7 +14,7 @@ export const SignInButton: React.FunctionComponent<Props> = ({ login }: Props) =
|
||||
styles={{
|
||||
rootHovered: { backgroundColor: "#393939", color: "#fff" },
|
||||
rootFocused: { backgroundColor: "#393939", color: "#fff" },
|
||||
rootPressed: { backgroundColor: "#393939", color: "#fff" }
|
||||
rootPressed: { backgroundColor: "#393939", color: "#fff" },
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -14,16 +14,16 @@ export const SwitchAccount: FunctionComponent<Props> = ({
|
||||
accounts,
|
||||
setSelectedAccountName,
|
||||
selectedAccount,
|
||||
dismissMenu
|
||||
dismissMenu,
|
||||
}: Props) => {
|
||||
return (
|
||||
<Dropdown
|
||||
label="Cosmos DB Account Name"
|
||||
className="accountSwitchAccountDropdown"
|
||||
options={accounts?.map(account => ({
|
||||
options={accounts?.map((account) => ({
|
||||
key: account.name,
|
||||
text: account.name,
|
||||
data: account
|
||||
data: account,
|
||||
}))}
|
||||
onChange={(_, option) => {
|
||||
setSelectedAccountName(String(option.key));
|
||||
@@ -32,7 +32,7 @@ export const SwitchAccount: FunctionComponent<Props> = ({
|
||||
defaultSelectedKey={selectedAccount?.name}
|
||||
placeholder={accounts && accounts.length === 0 ? "No Accounts Found" : "Select an Account"}
|
||||
styles={{
|
||||
callout: "accountSwitchAccountDropdownMenu"
|
||||
callout: "accountSwitchAccountDropdownMenu",
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -12,17 +12,17 @@ interface Props {
|
||||
export const SwitchSubscription: FunctionComponent<Props> = ({
|
||||
subscriptions,
|
||||
setSelectedSubscriptionId,
|
||||
selectedSubscription
|
||||
selectedSubscription,
|
||||
}: Props) => {
|
||||
return (
|
||||
<Dropdown
|
||||
label="Subscription"
|
||||
className="accountSwitchSubscriptionDropdown"
|
||||
options={subscriptions?.map(sub => {
|
||||
options={subscriptions?.map((sub) => {
|
||||
return {
|
||||
key: sub.subscriptionId,
|
||||
text: sub.displayName,
|
||||
data: sub
|
||||
data: sub,
|
||||
};
|
||||
})}
|
||||
onChange={(_, option) => {
|
||||
@@ -31,7 +31,7 @@ export const SwitchSubscription: FunctionComponent<Props> = ({
|
||||
defaultSelectedKey={selectedSubscription?.subscriptionId}
|
||||
placeholder={subscriptions && subscriptions.length === 0 ? "No Subscriptions Found" : "Select a Subscription"}
|
||||
styles={{
|
||||
callout: "accountSwitchSubscriptionDropdownMenu"
|
||||
callout: "accountSwitchSubscriptionDropdownMenu",
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
import * as DataModels from "../../../Contracts/DataModels";
|
||||
import { parseConnectionString } from "./ConnectionStringParser";
|
||||
|
||||
describe("ConnectionStringParser", () => {
|
||||
const mockAccountName: string = "Test";
|
||||
const mockMasterKey: string = "some-key";
|
||||
|
||||
it("should parse a valid sql account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`AccountEndpoint=https://${mockAccountName}.documents.azure.com:443/;AccountKey=${mockMasterKey};`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.SQL);
|
||||
});
|
||||
|
||||
it("should parse a valid mongo account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`mongodb://${mockAccountName}:${mockMasterKey}@${mockAccountName}.documents.azure.com:10255`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.MongoDB);
|
||||
});
|
||||
|
||||
it("should parse a valid compute mongo account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`mongodb://${mockAccountName}:${mockMasterKey}@${mockAccountName}.mongo.cosmos.azure.com:10255`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.MongoDBCompute);
|
||||
});
|
||||
|
||||
it("should parse a valid graph account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`AccountEndpoint=https://${mockAccountName}.documents.azure.com:443/;AccountKey=${mockMasterKey};ApiKind=Gremlin;`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.Graph);
|
||||
});
|
||||
|
||||
it("should parse a valid table account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`DefaultEndpointsProtocol=https;AccountName=${mockAccountName};AccountKey=${mockMasterKey};TableEndpoint=https://${mockAccountName}.table.cosmosdb.azure.com:443/;`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.Table);
|
||||
});
|
||||
|
||||
it("should parse a valid cassandra account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`AccountEndpoint=${mockAccountName}.cassandra.cosmosdb.azure.com;AccountKey=${mockMasterKey};`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.Cassandra);
|
||||
});
|
||||
|
||||
it("should fail to parse an invalid connection string", () => {
|
||||
const metadata = parseConnectionString("some-rogue-connection-string");
|
||||
|
||||
expect(metadata).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should fail to parse an empty connection string", () => {
|
||||
const metadata = parseConnectionString("");
|
||||
|
||||
expect(metadata).toBe(undefined);
|
||||
});
|
||||
});
|
||||
import * as DataModels from "../../../Contracts/DataModels";
|
||||
import { parseConnectionString } from "./ConnectionStringParser";
|
||||
|
||||
describe("ConnectionStringParser", () => {
|
||||
const mockAccountName: string = "Test";
|
||||
const mockMasterKey: string = "some-key";
|
||||
|
||||
it("should parse a valid sql account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`AccountEndpoint=https://${mockAccountName}.documents.azure.com:443/;AccountKey=${mockMasterKey};`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.SQL);
|
||||
});
|
||||
|
||||
it("should parse a valid mongo account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`mongodb://${mockAccountName}:${mockMasterKey}@${mockAccountName}.documents.azure.com:10255`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.MongoDB);
|
||||
});
|
||||
|
||||
it("should parse a valid compute mongo account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`mongodb://${mockAccountName}:${mockMasterKey}@${mockAccountName}.mongo.cosmos.azure.com:10255`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.MongoDBCompute);
|
||||
});
|
||||
|
||||
it("should parse a valid graph account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`AccountEndpoint=https://${mockAccountName}.documents.azure.com:443/;AccountKey=${mockMasterKey};ApiKind=Gremlin;`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.Graph);
|
||||
});
|
||||
|
||||
it("should parse a valid table account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`DefaultEndpointsProtocol=https;AccountName=${mockAccountName};AccountKey=${mockMasterKey};TableEndpoint=https://${mockAccountName}.table.cosmosdb.azure.com:443/;`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.Table);
|
||||
});
|
||||
|
||||
it("should parse a valid cassandra account connection string", () => {
|
||||
const metadata = parseConnectionString(
|
||||
`AccountEndpoint=${mockAccountName}.cassandra.cosmosdb.azure.com;AccountKey=${mockMasterKey};`
|
||||
);
|
||||
|
||||
expect(metadata.accountName).toBe(mockAccountName);
|
||||
expect(metadata.apiKind).toBe(DataModels.ApiKind.Cassandra);
|
||||
});
|
||||
|
||||
it("should fail to parse an invalid connection string", () => {
|
||||
const metadata = parseConnectionString("some-rogue-connection-string");
|
||||
|
||||
expect(metadata).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should fail to parse an empty connection string", () => {
|
||||
const metadata = parseConnectionString("");
|
||||
|
||||
expect(metadata).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
import * as Constants from "../../../Common/Constants";
|
||||
import { AccessInputMetadata, ApiKind } from "../../../Contracts/DataModels";
|
||||
|
||||
export function parseConnectionString(connectionString: string): AccessInputMetadata {
|
||||
if (connectionString) {
|
||||
try {
|
||||
const accessInput = {} as AccessInputMetadata;
|
||||
const connectionStringParts = connectionString.split(";");
|
||||
|
||||
connectionStringParts.forEach((connectionStringPart: string) => {
|
||||
if (RegExp(Constants.EndpointsRegex.sql).test(connectionStringPart)) {
|
||||
accessInput.accountName = connectionStringPart.match(Constants.EndpointsRegex.sql)[1];
|
||||
accessInput.apiKind = ApiKind.SQL;
|
||||
} else if (RegExp(Constants.EndpointsRegex.mongo).test(connectionStringPart)) {
|
||||
const matches: string[] = connectionStringPart.match(Constants.EndpointsRegex.mongo);
|
||||
accessInput.accountName = matches && matches.length > 1 && matches[2];
|
||||
accessInput.apiKind = ApiKind.MongoDB;
|
||||
} else if (RegExp(Constants.EndpointsRegex.mongoCompute).test(connectionStringPart)) {
|
||||
const matches: string[] = connectionStringPart.match(Constants.EndpointsRegex.mongoCompute);
|
||||
accessInput.accountName = matches && matches.length > 1 && matches[2];
|
||||
accessInput.apiKind = ApiKind.MongoDBCompute;
|
||||
} else if (Constants.EndpointsRegex.cassandra.some(regex => RegExp(regex).test(connectionStringPart))) {
|
||||
Constants.EndpointsRegex.cassandra.forEach(regex => {
|
||||
if (RegExp(regex).test(connectionStringPart)) {
|
||||
accessInput.accountName = connectionStringPart.match(regex)[1];
|
||||
accessInput.apiKind = ApiKind.Cassandra;
|
||||
}
|
||||
});
|
||||
} else if (RegExp(Constants.EndpointsRegex.table).test(connectionStringPart)) {
|
||||
accessInput.accountName = connectionStringPart.match(Constants.EndpointsRegex.table)[1];
|
||||
accessInput.apiKind = ApiKind.Table;
|
||||
} else if (connectionStringPart.indexOf("ApiKind=Gremlin") >= 0) {
|
||||
accessInput.apiKind = ApiKind.Graph;
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(accessInput).length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return accessInput;
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
import * as Constants from "../../../Common/Constants";
|
||||
import { AccessInputMetadata, ApiKind } from "../../../Contracts/DataModels";
|
||||
|
||||
export function parseConnectionString(connectionString: string): AccessInputMetadata {
|
||||
if (connectionString) {
|
||||
try {
|
||||
const accessInput = {} as AccessInputMetadata;
|
||||
const connectionStringParts = connectionString.split(";");
|
||||
|
||||
connectionStringParts.forEach((connectionStringPart: string) => {
|
||||
if (RegExp(Constants.EndpointsRegex.sql).test(connectionStringPart)) {
|
||||
accessInput.accountName = connectionStringPart.match(Constants.EndpointsRegex.sql)[1];
|
||||
accessInput.apiKind = ApiKind.SQL;
|
||||
} else if (RegExp(Constants.EndpointsRegex.mongo).test(connectionStringPart)) {
|
||||
const matches: string[] = connectionStringPart.match(Constants.EndpointsRegex.mongo);
|
||||
accessInput.accountName = matches && matches.length > 1 && matches[2];
|
||||
accessInput.apiKind = ApiKind.MongoDB;
|
||||
} else if (RegExp(Constants.EndpointsRegex.mongoCompute).test(connectionStringPart)) {
|
||||
const matches: string[] = connectionStringPart.match(Constants.EndpointsRegex.mongoCompute);
|
||||
accessInput.accountName = matches && matches.length > 1 && matches[2];
|
||||
accessInput.apiKind = ApiKind.MongoDBCompute;
|
||||
} else if (Constants.EndpointsRegex.cassandra.some((regex) => RegExp(regex).test(connectionStringPart))) {
|
||||
Constants.EndpointsRegex.cassandra.forEach((regex) => {
|
||||
if (RegExp(regex).test(connectionStringPart)) {
|
||||
accessInput.accountName = connectionStringPart.match(regex)[1];
|
||||
accessInput.apiKind = ApiKind.Cassandra;
|
||||
}
|
||||
});
|
||||
} else if (RegExp(Constants.EndpointsRegex.table).test(connectionStringPart)) {
|
||||
accessInput.accountName = connectionStringPart.match(Constants.EndpointsRegex.table)[1];
|
||||
accessInput.apiKind = ApiKind.Table;
|
||||
} else if (connectionStringPart.indexOf("ApiKind=Gremlin") >= 0) {
|
||||
accessInput.apiKind = ApiKind.Graph;
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(accessInput).length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return accessInput;
|
||||
} catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ describe("parseResourceTokenConnectionString", () => {
|
||||
collectionId: "fakeCollectionId",
|
||||
databaseId: "fakeDatabaseId",
|
||||
partitionKey: undefined,
|
||||
resourceToken: "type=resource&ver=1&sig=2dIP+CdIfT1ScwHWdv5GGw==;fakeToken;"
|
||||
resourceToken: "type=resource&ver=1&sig=2dIP+CdIfT1ScwHWdv5GGw==;fakeToken;",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -25,7 +25,7 @@ describe("parseResourceTokenConnectionString", () => {
|
||||
collectionId: "fakeCollectionId",
|
||||
databaseId: "fakeDatabaseId",
|
||||
partitionKey: "fakePartitionKey",
|
||||
resourceToken: "type=resource&ver=1&sig=2dIP+CdIfT1ScwHWdv5GGw==;fakeToken;"
|
||||
resourceToken: "type=resource&ver=1&sig=2dIP+CdIfT1ScwHWdv5GGw==;fakeToken;",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ export function parseResourceTokenConnectionString(connectionString: string): Pa
|
||||
collectionId,
|
||||
databaseId,
|
||||
partitionKey,
|
||||
resourceToken
|
||||
resourceToken,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ describe("getDatabaseAccountPropertiesFromMetadata", () => {
|
||||
apiKind: 5,
|
||||
documentEndpoint: "https://compute-batch2.documents.azure.com:443/",
|
||||
expiryTimestamp: "1234",
|
||||
mongoEndpoint: "https://compute-batch2.mongo.cosmos.azure.com:443/"
|
||||
mongoEndpoint: "https://compute-batch2.mongo.cosmos.azure.com:443/",
|
||||
};
|
||||
expect(getDatabaseAccountPropertiesFromMetadata(mongoComputeAccount)).toEqual({
|
||||
mongoEndpoint: mongoComputeAccount.mongoEndpoint,
|
||||
documentEndpoint: mongoComputeAccount.documentEndpoint
|
||||
documentEndpoint: mongoComputeAccount.documentEndpoint,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,10 +23,10 @@ describe("getDatabaseAccountPropertiesFromMetadata", () => {
|
||||
apiEndpoint: "compute-batch2.mongo.cosmos.azure.com:10255",
|
||||
apiKind: 1,
|
||||
documentEndpoint: "https://compute-batch2.documents.azure.com:443/",
|
||||
expiryTimestamp: "1234"
|
||||
expiryTimestamp: "1234",
|
||||
};
|
||||
expect(getDatabaseAccountPropertiesFromMetadata(mongoAccount)).toEqual({
|
||||
documentEndpoint: mongoAccount.documentEndpoint
|
||||
documentEndpoint: mongoAccount.documentEndpoint,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,22 +9,22 @@ export function getDatabaseAccountPropertiesFromMetadata(metadata: AccessInputMe
|
||||
if (apiExperience === DefaultAccountExperience.Cassandra) {
|
||||
properties = Object.assign(properties, {
|
||||
cassandraEndpoint: metadata.apiEndpoint,
|
||||
capabilities: [{ name: CapabilityNames.EnableCassandra }]
|
||||
capabilities: [{ name: CapabilityNames.EnableCassandra }],
|
||||
});
|
||||
} else if (apiExperience === DefaultAccountExperience.Table) {
|
||||
properties = Object.assign(properties, {
|
||||
tableEndpoint: metadata.apiEndpoint,
|
||||
capabilities: [{ name: CapabilityNames.EnableTable }]
|
||||
capabilities: [{ name: CapabilityNames.EnableTable }],
|
||||
});
|
||||
} else if (apiExperience === DefaultAccountExperience.Graph) {
|
||||
properties = Object.assign(properties, {
|
||||
gremlinEndpoint: metadata.apiEndpoint,
|
||||
capabilities: [{ name: CapabilityNames.EnableGremlin }]
|
||||
capabilities: [{ name: CapabilityNames.EnableGremlin }],
|
||||
});
|
||||
} else if (apiExperience === DefaultAccountExperience.MongoDB) {
|
||||
if (metadata.apiKind === ApiKind.MongoDBCompute) {
|
||||
properties = Object.assign(properties, {
|
||||
mongoEndpoint: metadata.mongoEndpoint
|
||||
mongoEndpoint: metadata.mongoEndpoint,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ describe("extractFeatures", () => {
|
||||
expect(features).toEqual({
|
||||
notebookserverurl: "https://localhost:10001/12345/notebook",
|
||||
notebookservertoken: "token",
|
||||
enablenotebooks: "true"
|
||||
enablenotebooks: "true",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user