From 1e19f02fd72d3100ceba749814d726da8a3324a3 Mon Sep 17 00:00:00 2001 From: victor-meng <56978073+victor-meng@users.noreply.github.com> Date: Wed, 21 Oct 2020 14:58:28 -0700 Subject: [PATCH] Use SDK calls for stored procedure, trigger, and UDF operations for Gemlin API (#295) RP doesn't support stored procedure, trigger, and UDF operations for Gremlin API so we have to use SDK for now. --- src/Common/dataAccess/createStoredProcedure.ts | 7 ++++++- src/Common/dataAccess/createTrigger.ts | 7 ++++++- src/Common/dataAccess/createUserDefinedFunction.ts | 7 ++++++- src/Common/dataAccess/deleteStoredProcedure.ts | 7 ++++++- src/Common/dataAccess/deleteTrigger.ts | 7 ++++++- src/Common/dataAccess/deleteUserDefinedFunction.ts | 7 ++++++- src/Common/dataAccess/readStoredProcedures.ts | 7 ++++++- src/Common/dataAccess/readTriggers.ts | 7 ++++++- src/Common/dataAccess/readUserDefinedFunctions.ts | 7 ++++++- src/Common/dataAccess/updateStoredProcedure.ts | 7 ++++++- src/Common/dataAccess/updateTrigger.ts | 7 ++++++- src/Common/dataAccess/updateUserDefinedFunction.ts | 7 ++++++- 12 files changed, 72 insertions(+), 12 deletions(-) diff --git a/src/Common/dataAccess/createStoredProcedure.ts b/src/Common/dataAccess/createStoredProcedure.ts index 5c7b2f748..a2281c213 100644 --- a/src/Common/dataAccess/createStoredProcedure.ts +++ b/src/Common/dataAccess/createStoredProcedure.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, StoredProcedureDefinition } from "@azure/cosmos"; import { SqlStoredProcedureCreateUpdateParameters, @@ -20,7 +21,11 @@ export async function createStoredProcedure( ): Promise { const clearMessage = logConsoleProgress(`Creating stored procedure ${storedProcedure.id}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { try { const getResponse = await getSqlStoredProcedure( userContext.subscriptionId, diff --git a/src/Common/dataAccess/createTrigger.ts b/src/Common/dataAccess/createTrigger.ts index daf970582..341dd46e7 100644 --- a/src/Common/dataAccess/createTrigger.ts +++ b/src/Common/dataAccess/createTrigger.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, TriggerDefinition } from "@azure/cosmos"; import { SqlTriggerCreateUpdateParameters, @@ -18,7 +19,11 @@ export async function createTrigger( ): Promise { const clearMessage = logConsoleProgress(`Creating trigger ${trigger.id}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { try { const getResponse = await getSqlTrigger( userContext.subscriptionId, diff --git a/src/Common/dataAccess/createUserDefinedFunction.ts b/src/Common/dataAccess/createUserDefinedFunction.ts index 350270177..30ff8be3a 100644 --- a/src/Common/dataAccess/createUserDefinedFunction.ts +++ b/src/Common/dataAccess/createUserDefinedFunction.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, UserDefinedFunctionDefinition } from "@azure/cosmos"; import { SqlUserDefinedFunctionCreateUpdateParameters, @@ -20,7 +21,11 @@ export async function createUserDefinedFunction( ): Promise { const clearMessage = logConsoleProgress(`Creating user defined function ${userDefinedFunction.id}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { try { const getResponse = await getSqlUserDefinedFunction( userContext.subscriptionId, diff --git a/src/Common/dataAccess/deleteStoredProcedure.ts b/src/Common/dataAccess/deleteStoredProcedure.ts index 2da1a409f..317fb3167 100644 --- a/src/Common/dataAccess/deleteStoredProcedure.ts +++ b/src/Common/dataAccess/deleteStoredProcedure.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { client } from "../CosmosClient"; import { deleteSqlStoredProcedure } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { handleError } from "../ErrorHandlingUtils"; @@ -12,7 +13,11 @@ export async function deleteStoredProcedure( ): Promise { const clearMessage = logConsoleProgress(`Deleting stored procedure ${storedProcedureId}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { await deleteSqlStoredProcedure( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/deleteTrigger.ts b/src/Common/dataAccess/deleteTrigger.ts index e4d6d7840..0ec6ef4e1 100644 --- a/src/Common/dataAccess/deleteTrigger.ts +++ b/src/Common/dataAccess/deleteTrigger.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { client } from "../CosmosClient"; import { deleteSqlTrigger } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { handleError } from "../ErrorHandlingUtils"; @@ -8,7 +9,11 @@ import { userContext } from "../../UserContext"; export async function deleteTrigger(databaseId: string, collectionId: string, triggerId: string): Promise { const clearMessage = logConsoleProgress(`Deleting trigger ${triggerId}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { await deleteSqlTrigger( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/deleteUserDefinedFunction.ts b/src/Common/dataAccess/deleteUserDefinedFunction.ts index 5d195baa9..83630169e 100644 --- a/src/Common/dataAccess/deleteUserDefinedFunction.ts +++ b/src/Common/dataAccess/deleteUserDefinedFunction.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { client } from "../CosmosClient"; import { deleteSqlUserDefinedFunction } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { handleError } from "../ErrorHandlingUtils"; @@ -8,7 +9,11 @@ import { userContext } from "../../UserContext"; export async function deleteUserDefinedFunction(databaseId: string, collectionId: string, id: string): Promise { const clearMessage = logConsoleProgress(`Deleting user defined function ${id}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { await deleteSqlUserDefinedFunction( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/readStoredProcedures.ts b/src/Common/dataAccess/readStoredProcedures.ts index 4f7c4b01b..cb64654e6 100644 --- a/src/Common/dataAccess/readStoredProcedures.ts +++ b/src/Common/dataAccess/readStoredProcedures.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, StoredProcedureDefinition } from "@azure/cosmos"; import { client } from "../CosmosClient"; import { handleError } from "../ErrorHandlingUtils"; @@ -12,7 +13,11 @@ export async function readStoredProcedures( ): Promise<(StoredProcedureDefinition & Resource)[]> { const clearMessage = logConsoleProgress(`Querying stored procedures for container ${collectionId}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { const rpResponse = await listSqlStoredProcedures( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/readTriggers.ts b/src/Common/dataAccess/readTriggers.ts index 5216371c6..d8b6f6469 100644 --- a/src/Common/dataAccess/readTriggers.ts +++ b/src/Common/dataAccess/readTriggers.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, TriggerDefinition } from "@azure/cosmos"; import { client } from "../CosmosClient"; import { listSqlTriggers } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; @@ -12,7 +13,11 @@ export async function readTriggers( ): Promise<(TriggerDefinition & Resource)[]> { const clearMessage = logConsoleProgress(`Querying triggers for container ${collectionId}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { const rpResponse = await listSqlTriggers( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/readUserDefinedFunctions.ts b/src/Common/dataAccess/readUserDefinedFunctions.ts index 09b70d73e..93d26f73a 100644 --- a/src/Common/dataAccess/readUserDefinedFunctions.ts +++ b/src/Common/dataAccess/readUserDefinedFunctions.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, UserDefinedFunctionDefinition } from "@azure/cosmos"; import { client } from "../CosmosClient"; import { handleError } from "../ErrorHandlingUtils"; @@ -12,7 +13,11 @@ export async function readUserDefinedFunctions( ): Promise<(UserDefinedFunctionDefinition & Resource)[]> { const clearMessage = logConsoleProgress(`Querying user defined functions for container ${collectionId}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { const rpResponse = await listSqlUserDefinedFunctions( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/updateStoredProcedure.ts b/src/Common/dataAccess/updateStoredProcedure.ts index eddd72187..17c498d66 100644 --- a/src/Common/dataAccess/updateStoredProcedure.ts +++ b/src/Common/dataAccess/updateStoredProcedure.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, StoredProcedureDefinition } from "@azure/cosmos"; import { SqlStoredProcedureCreateUpdateParameters, @@ -20,7 +21,11 @@ export async function updateStoredProcedure( ): Promise { const clearMessage = logConsoleProgress(`Updating stored procedure ${storedProcedure.id}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { const getResponse = await getSqlStoredProcedure( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/updateTrigger.ts b/src/Common/dataAccess/updateTrigger.ts index 38f2dcebb..845e19274 100644 --- a/src/Common/dataAccess/updateTrigger.ts +++ b/src/Common/dataAccess/updateTrigger.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { SqlTriggerCreateUpdateParameters, SqlTriggerResource @@ -17,7 +18,11 @@ export async function updateTrigger( ): Promise { const clearMessage = logConsoleProgress(`Updating trigger ${trigger.id}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { const getResponse = await getSqlTrigger( userContext.subscriptionId, userContext.resourceGroup, diff --git a/src/Common/dataAccess/updateUserDefinedFunction.ts b/src/Common/dataAccess/updateUserDefinedFunction.ts index d81e95d85..373cb1dcd 100644 --- a/src/Common/dataAccess/updateUserDefinedFunction.ts +++ b/src/Common/dataAccess/updateUserDefinedFunction.ts @@ -1,4 +1,5 @@ import { AuthType } from "../../AuthType"; +import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; import { Resource, UserDefinedFunctionDefinition } from "@azure/cosmos"; import { SqlUserDefinedFunctionCreateUpdateParameters, @@ -20,7 +21,11 @@ export async function updateUserDefinedFunction( ): Promise { const clearMessage = logConsoleProgress(`Updating user defined function ${userDefinedFunction.id}`); try { - if (window.authType === AuthType.AAD && !userContext.useSDKOperations) { + if ( + window.authType === AuthType.AAD && + !userContext.useSDKOperations && + userContext.defaultExperience === DefaultAccountExperienceType.DocumentDB + ) { const getResponse = await getSqlUserDefinedFunction( userContext.subscriptionId, userContext.resourceGroup,