Fix deleteDatabase and deleteCollection with ARM (#143)
This commit is contained in:
parent
5886db81e9
commit
455722c316
|
@ -6,6 +6,7 @@ import { AuthType } from "../../AuthType";
|
||||||
import { updateUserContext } from "../../UserContext";
|
import { updateUserContext } from "../../UserContext";
|
||||||
import { DatabaseAccount } from "../../Contracts/DataModels";
|
import { DatabaseAccount } from "../../Contracts/DataModels";
|
||||||
import { sendCachedDataMessage } from "../MessageHandler";
|
import { sendCachedDataMessage } from "../MessageHandler";
|
||||||
|
import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType";
|
||||||
|
|
||||||
describe("deleteCollection", () => {
|
describe("deleteCollection", () => {
|
||||||
it("should call ARM if logged in with AAD", async () => {
|
it("should call ARM if logged in with AAD", async () => {
|
||||||
|
@ -13,7 +14,8 @@ describe("deleteCollection", () => {
|
||||||
updateUserContext({
|
updateUserContext({
|
||||||
databaseAccount: {
|
databaseAccount: {
|
||||||
name: "test"
|
name: "test"
|
||||||
} as DatabaseAccount
|
} as DatabaseAccount,
|
||||||
|
defaultExperience: DefaultAccountExperienceType.DocumentDB
|
||||||
});
|
});
|
||||||
(sendCachedDataMessage as jest.Mock).mockResolvedValue(undefined);
|
(sendCachedDataMessage as jest.Mock).mockResolvedValue(undefined);
|
||||||
await deleteCollection("database", "collection");
|
await deleteCollection("database", "collection");
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
import { AuthType } from "../../AuthType";
|
import { AuthType } from "../../AuthType";
|
||||||
|
import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType";
|
||||||
import { deleteSqlContainer } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources";
|
import { deleteSqlContainer } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources";
|
||||||
|
import { deleteCassandraTable } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources";
|
||||||
|
import { deleteMongoDBCollection } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources";
|
||||||
|
import { deleteGremlinGraph } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources";
|
||||||
|
import { deleteTable } from "../../Utils/arm/generatedClients/2020-04-01/tableResources";
|
||||||
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
||||||
import { userContext } from "../../UserContext";
|
import { userContext } from "../../UserContext";
|
||||||
import { client } from "../CosmosClient";
|
import { client } from "../CosmosClient";
|
||||||
|
@ -9,13 +14,7 @@ export async function deleteCollection(databaseId: string, collectionId: string)
|
||||||
const clearMessage = logConsoleProgress(`Deleting container ${collectionId}`);
|
const clearMessage = logConsoleProgress(`Deleting container ${collectionId}`);
|
||||||
try {
|
try {
|
||||||
if (window.authType === AuthType.AAD) {
|
if (window.authType === AuthType.AAD) {
|
||||||
await deleteSqlContainer(
|
await deleteCollectionWithARM(databaseId, collectionId);
|
||||||
userContext.subscriptionId,
|
|
||||||
userContext.resourceGroup,
|
|
||||||
userContext.databaseAccount.name,
|
|
||||||
databaseId,
|
|
||||||
collectionId
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
await client()
|
await client()
|
||||||
.database(databaseId)
|
.database(databaseId)
|
||||||
|
@ -30,3 +29,25 @@ export async function deleteCollection(databaseId: string, collectionId: string)
|
||||||
clearMessage();
|
clearMessage();
|
||||||
await refreshCachedResources();
|
await refreshCachedResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteCollectionWithARM(databaseId: string, collectionId: string): Promise<void> {
|
||||||
|
const subscriptionId = userContext.subscriptionId;
|
||||||
|
const resourceGroup = userContext.resourceGroup;
|
||||||
|
const accountName = userContext.databaseAccount.name;
|
||||||
|
const defaultExperience = userContext.defaultExperience;
|
||||||
|
|
||||||
|
switch (defaultExperience) {
|
||||||
|
case DefaultAccountExperienceType.DocumentDB:
|
||||||
|
return deleteSqlContainer(subscriptionId, resourceGroup, accountName, databaseId, collectionId);
|
||||||
|
case DefaultAccountExperienceType.MongoDB:
|
||||||
|
return deleteMongoDBCollection(subscriptionId, resourceGroup, accountName, databaseId, collectionId);
|
||||||
|
case DefaultAccountExperienceType.Cassandra:
|
||||||
|
return deleteCassandraTable(subscriptionId, resourceGroup, accountName, databaseId, collectionId);
|
||||||
|
case DefaultAccountExperienceType.Graph:
|
||||||
|
return deleteGremlinGraph(subscriptionId, resourceGroup, accountName, databaseId, collectionId);
|
||||||
|
case DefaultAccountExperienceType.Table:
|
||||||
|
return deleteTable(subscriptionId, resourceGroup, accountName, collectionId);
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported default experience type: ${defaultExperience}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { AuthType } from "../../AuthType";
|
||||||
import { updateUserContext } from "../../UserContext";
|
import { updateUserContext } from "../../UserContext";
|
||||||
import { DatabaseAccount } from "../../Contracts/DataModels";
|
import { DatabaseAccount } from "../../Contracts/DataModels";
|
||||||
import { sendCachedDataMessage } from "../MessageHandler";
|
import { sendCachedDataMessage } from "../MessageHandler";
|
||||||
|
import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType";
|
||||||
|
|
||||||
describe("deleteDatabase", () => {
|
describe("deleteDatabase", () => {
|
||||||
it("should call ARM if logged in with AAD", async () => {
|
it("should call ARM if logged in with AAD", async () => {
|
||||||
|
@ -13,7 +14,8 @@ describe("deleteDatabase", () => {
|
||||||
updateUserContext({
|
updateUserContext({
|
||||||
databaseAccount: {
|
databaseAccount: {
|
||||||
name: "test"
|
name: "test"
|
||||||
} as DatabaseAccount
|
} as DatabaseAccount,
|
||||||
|
defaultExperience: DefaultAccountExperienceType.DocumentDB
|
||||||
});
|
});
|
||||||
(sendCachedDataMessage as jest.Mock).mockResolvedValue(undefined);
|
(sendCachedDataMessage as jest.Mock).mockResolvedValue(undefined);
|
||||||
await deleteDatabase("database");
|
await deleteDatabase("database");
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import { AuthType } from "../../AuthType";
|
import { AuthType } from "../../AuthType";
|
||||||
|
import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType";
|
||||||
import { deleteSqlDatabase } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources";
|
import { deleteSqlDatabase } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources";
|
||||||
|
import { deleteCassandraKeyspace } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources";
|
||||||
|
import { deleteMongoDBDatabase } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources";
|
||||||
|
import { deleteGremlinDatabase } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources";
|
||||||
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
|
||||||
import { userContext } from "../../UserContext";
|
import { userContext } from "../../UserContext";
|
||||||
import { client } from "../CosmosClient";
|
import { client } from "../CosmosClient";
|
||||||
|
@ -12,12 +16,7 @@ export async function deleteDatabase(databaseId: string): Promise<void> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (window.authType === AuthType.AAD) {
|
if (window.authType === AuthType.AAD) {
|
||||||
await deleteSqlDatabase(
|
await deleteDatabaseWithARM(databaseId);
|
||||||
userContext.subscriptionId,
|
|
||||||
userContext.resourceGroup,
|
|
||||||
userContext.databaseAccount.name,
|
|
||||||
databaseId
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
await client()
|
await client()
|
||||||
.database(databaseId)
|
.database(databaseId)
|
||||||
|
@ -33,3 +32,23 @@ export async function deleteDatabase(databaseId: string): Promise<void> {
|
||||||
clearMessage();
|
clearMessage();
|
||||||
await refreshCachedResources();
|
await refreshCachedResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteDatabaseWithARM(databaseId: string): Promise<void> {
|
||||||
|
const subscriptionId = userContext.subscriptionId;
|
||||||
|
const resourceGroup = userContext.resourceGroup;
|
||||||
|
const accountName = userContext.databaseAccount.name;
|
||||||
|
const defaultExperience = userContext.defaultExperience;
|
||||||
|
|
||||||
|
switch (defaultExperience) {
|
||||||
|
case DefaultAccountExperienceType.DocumentDB:
|
||||||
|
return deleteSqlDatabase(subscriptionId, resourceGroup, accountName, databaseId);
|
||||||
|
case DefaultAccountExperienceType.MongoDB:
|
||||||
|
return deleteMongoDBDatabase(subscriptionId, resourceGroup, accountName, databaseId);
|
||||||
|
case DefaultAccountExperienceType.Cassandra:
|
||||||
|
return deleteCassandraKeyspace(subscriptionId, resourceGroup, accountName, databaseId);
|
||||||
|
case DefaultAccountExperienceType.Graph:
|
||||||
|
return deleteGremlinDatabase(subscriptionId, resourceGroup, accountName, databaseId);
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported default experience type: ${defaultExperience}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
export enum DefaultAccountExperienceType {
|
||||||
|
DocumentDB = "DocumentDB",
|
||||||
|
Graph = "Graph",
|
||||||
|
MongoDB = "MongoDB",
|
||||||
|
Table = "Table",
|
||||||
|
Cassandra = "Cassandra",
|
||||||
|
ApiForMongoDB = "Azure Cosmos DB for MongoDB API"
|
||||||
|
}
|
|
@ -482,7 +482,13 @@ export default class Explorer {
|
||||||
this.notificationConsoleData = ko.observableArray<ConsoleData>([]);
|
this.notificationConsoleData = ko.observableArray<ConsoleData>([]);
|
||||||
this.defaultExperience = ko.observable<string>();
|
this.defaultExperience = ko.observable<string>();
|
||||||
this.databaseAccount.subscribe(databaseAccount => {
|
this.databaseAccount.subscribe(databaseAccount => {
|
||||||
this.defaultExperience(DefaultExperienceUtility.getDefaultExperienceFromDatabaseAccount(databaseAccount));
|
const defaultExperience: string = DefaultExperienceUtility.getDefaultExperienceFromDatabaseAccount(
|
||||||
|
databaseAccount
|
||||||
|
);
|
||||||
|
this.defaultExperience(defaultExperience);
|
||||||
|
updateUserContext({
|
||||||
|
defaultExperience: DefaultExperienceUtility.mapDefaultExperienceStringToEnum(defaultExperience)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.isPreferredApiDocumentDB = ko.computed(() => {
|
this.isPreferredApiDocumentDB = ko.computed(() => {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as _ from "underscore";
|
import * as _ from "underscore";
|
||||||
import * as Constants from "../Common/Constants";
|
import * as Constants from "../Common/Constants";
|
||||||
import * as DataModels from "../Contracts/DataModels";
|
import * as DataModels from "../Contracts/DataModels";
|
||||||
|
import { DefaultAccountExperienceType } from "../DefaultAccountExperienceType";
|
||||||
|
|
||||||
export class DefaultExperienceUtility {
|
export class DefaultExperienceUtility {
|
||||||
public static getDefaultExperienceFromDatabaseAccount(databaseAccount: DataModels.DatabaseAccount): string {
|
public static getDefaultExperienceFromDatabaseAccount(databaseAccount: DataModels.DatabaseAccount): string {
|
||||||
|
@ -59,6 +60,25 @@ export class DefaultExperienceUtility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static mapDefaultExperienceStringToEnum(defaultExperience: string): DefaultAccountExperienceType {
|
||||||
|
switch (defaultExperience) {
|
||||||
|
case Constants.DefaultAccountExperience.DocumentDB:
|
||||||
|
return DefaultAccountExperienceType.DocumentDB;
|
||||||
|
case Constants.DefaultAccountExperience.Graph:
|
||||||
|
return DefaultAccountExperienceType.Graph;
|
||||||
|
case Constants.DefaultAccountExperience.MongoDB:
|
||||||
|
return DefaultAccountExperienceType.MongoDB;
|
||||||
|
case Constants.DefaultAccountExperience.Table:
|
||||||
|
return DefaultAccountExperienceType.Table;
|
||||||
|
case Constants.DefaultAccountExperience.Cassandra:
|
||||||
|
return DefaultAccountExperienceType.Cassandra;
|
||||||
|
case Constants.DefaultAccountExperience.ApiForMongoDB:
|
||||||
|
return DefaultAccountExperienceType.ApiForMongoDB;
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported default experience type: ${defaultExperience}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static _getDefaultExperience(kind: string, capabilities: DataModels.Capability[]): string {
|
private static _getDefaultExperience(kind: string, capabilities: DataModels.Capability[]): string {
|
||||||
const defaultDefaultExperience: string = Constants.DefaultAccountExperience.DocumentDB;
|
const defaultDefaultExperience: string = Constants.DefaultAccountExperience.DocumentDB;
|
||||||
const defaultExperienceFromKind: string = DefaultExperienceUtility._getDefaultExperienceFromAccountKind(kind);
|
const defaultExperienceFromKind: string = DefaultExperienceUtility._getDefaultExperienceFromAccountKind(kind);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { DatabaseAccount } from "./Contracts/DataModels";
|
import { DatabaseAccount } from "./Contracts/DataModels";
|
||||||
|
import { DefaultAccountExperienceType } from "./DefaultAccountExperienceType";
|
||||||
|
|
||||||
interface UserContext {
|
interface UserContext {
|
||||||
masterKey?: string;
|
masterKey?: string;
|
||||||
|
@ -9,6 +10,7 @@ interface UserContext {
|
||||||
accessToken?: string;
|
accessToken?: string;
|
||||||
authorizationToken?: string;
|
authorizationToken?: string;
|
||||||
resourceToken?: string;
|
resourceToken?: string;
|
||||||
|
defaultExperience?: DefaultAccountExperienceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
const userContext: Readonly<UserContext> = {} as const;
|
const userContext: Readonly<UserContext> = {} as const;
|
||||||
|
|
Loading…
Reference in New Issue