From 25a9a402ce9b6f35cfe2498355a163a9899c94be Mon Sep 17 00:00:00 2001 From: thewahome Date: Tue, 7 Jan 2025 14:09:03 +0300 Subject: [PATCH] pass auth as primitive type instead of complex type --- src/kiota/Rpc/IServer.cs | 2 +- src/kiota/Rpc/Server.cs | 10 ++++++++-- .../src/commands/generate/generatePlugin.ts | 8 +++++--- .../src/commands/regenerate/regenerate.service.ts | 7 ++----- vscode/microsoft-kiota/src/kiotaInterop/index.ts | 10 +++------- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/kiota/Rpc/IServer.cs b/src/kiota/Rpc/IServer.cs index c8daa66ab4..32f1749c81 100644 --- a/src/kiota/Rpc/IServer.cs +++ b/src/kiota/Rpc/IServer.cs @@ -12,7 +12,7 @@ internal interface IServer Task GetManifestDetailsAsync(string manifestPath, string apiIdentifier, bool clearCache, CancellationToken cancellationToken); Task> GenerateAsync(string openAPIFilePath, string outputPath, GenerationLanguage language, string[] includePatterns, string[] excludePatterns, string clientClassName, string clientNamespaceName, bool usesBackingStore, bool cleanOutput, bool clearCache, bool excludeBackwardCompatible, string[] disabledValidationRules, string[] serializers, string[] deserializers, string[] structuredMimeTypes, bool includeAdditionalData, ConsumerOperation operation, CancellationToken cancellationToken); Task InfoForDescriptionAsync(string descriptionPath, bool clearCache, CancellationToken cancellationToken); - Task> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, PluginAuthConfiguration? pluginAuthConfiguration, ConsumerOperation operation, CancellationToken cancellationToken); + Task> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, PluginAuthType? pluginAuthType, string pluginAuthRefid, ConsumerOperation operation, CancellationToken cancellationToken); Task> MigrateFromLockFileAsync(string lockDirectoryPath, CancellationToken cancellationToken); Task> RemoveClientAsync(string clientName, bool cleanOutput, CancellationToken cancellationToken); Task> RemovePluginAsync(string pluginName, bool cleanOutput, CancellationToken cancellationToken); diff --git a/src/kiota/Rpc/Server.cs b/src/kiota/Rpc/Server.cs index 4997c744fb..ca0af15d8d 100644 --- a/src/kiota/Rpc/Server.cs +++ b/src/kiota/Rpc/Server.cs @@ -186,7 +186,7 @@ public async Task> GenerateAsync(string openAPIFilePath, string o } public async Task> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, - PluginAuthConfiguration? pluginAuthInformation, ConsumerOperation operation, CancellationToken cancellationToken) + PluginAuthType? pluginAuthType, string? pluginAuthRefid, ConsumerOperation operation, CancellationToken cancellationToken) { var globalLogger = new ForwardedLogger(); var configuration = Configuration.Generation; @@ -208,7 +208,13 @@ public async Task> GeneratePluginAsync(string openAPIFilePath, st configuration.ExcludePatterns = excludePatterns.Select(static x => x.TrimQuotes()).ToHashSet(StringComparer.OrdinalIgnoreCase); configuration.OpenAPIFilePath = GetAbsolutePath(configuration.OpenAPIFilePath); configuration.OutputPath = NormalizeSlashesInPath(GetAbsolutePath(configuration.OutputPath)); - configuration.PluginAuthInformation ??= pluginAuthInformation; + if (!string.IsNullOrEmpty(pluginAuthRefid) && pluginAuthType != null) + { + var pluginAuthConfig = new PluginAuthConfiguration(pluginAuthRefid); + pluginAuthConfig.AuthType = pluginAuthType.Value; + configuration.PluginAuthInformation = pluginAuthConfig; + } + try { using var fileLogger = new FileLogLogger(configuration.OutputPath, LogLevel.Warning); diff --git a/vscode/microsoft-kiota/src/commands/generate/generatePlugin.ts b/vscode/microsoft-kiota/src/commands/generate/generatePlugin.ts index b42b3bbded..0cd6ef47b6 100644 --- a/vscode/microsoft-kiota/src/commands/generate/generatePlugin.ts +++ b/vscode/microsoft-kiota/src/commands/generate/generatePlugin.ts @@ -1,7 +1,7 @@ import * as vscode from "vscode"; import * as rpc from "vscode-jsonrpc/node"; -import { connectToKiota, ConsumerOperation, GenerationConfiguration, KiotaLogEntry, PluginAuthConfiguration } from "../../kiotaInterop"; +import { connectToKiota, ConsumerOperation, GenerationConfiguration, KiotaLogEntry, PluginAuthType } from "../../kiotaInterop"; import { KiotaPluginType } from "../../types/enums"; import { getWorkspaceJsonDirectory } from "../../util"; @@ -16,7 +16,8 @@ export function generatePlugin(context: vscode.ExtensionContext, cleanOutput: boolean, disableValidationRules: string[], operation: ConsumerOperation, - pluginAuthConfiguration?: PluginAuthConfiguration, + pluginAuthType?: PluginAuthType | null, + pluginAuthRefid?: string, workingDirectory: string = getWorkspaceJsonDirectory(), ): Promise { return connectToKiota(context, async (connection) => { @@ -35,8 +36,9 @@ export function generatePlugin(context: vscode.ExtensionContext, includePatterns: includeFilters, openAPIFilePath: descriptionPath, outputPath: output, + pluginAuthType, + pluginAuthRefid, operation, - pluginAuthConfiguration } as GenerationConfiguration, ); }, workingDirectory); diff --git a/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts b/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts index c84fe9d106..b9ca84c3ed 100644 --- a/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts @@ -66,10 +66,6 @@ export class RegenerateService { async regeneratePlugin(settings: ExtensionSettings, selectedPaths?: string[]) { const pluginObjectItem = this._clientObject as PluginObjectProperties; const pluginTypes = Array.isArray(pluginObjectItem.types) ? parsePluginType(pluginObjectItem.types) : [KiotaPluginType.ApiPlugin]; - const pluginAuthConfiguration = pluginObjectItem.authReferenceId && pluginObjectItem.authType ? { - referenceId: pluginObjectItem.authReferenceId, - authType: pluginObjectItem.authType - } : undefined; await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification, cancellable: false, @@ -88,7 +84,8 @@ export class RegenerateService { false, settings.disableValidationRules, ConsumerOperation.Edit, - pluginAuthConfiguration + pluginObjectItem.authType ? pluginObjectItem.authType : null, + pluginObjectItem.authReferenceId ? pluginObjectItem.authReferenceId : '', ); const duration = performance.now() - start; const errorsCount = result ? getLogEntriesForLevel(result, LogLevel.critical, LogLevel.error).length : 0; diff --git a/vscode/microsoft-kiota/src/kiotaInterop/index.ts b/vscode/microsoft-kiota/src/kiotaInterop/index.ts index 803829ab93..490780d03b 100644 --- a/vscode/microsoft-kiota/src/kiotaInterop/index.ts +++ b/vscode/microsoft-kiota/src/kiotaInterop/index.ts @@ -249,15 +249,11 @@ export interface GenerationConfiguration { usesBackingStore: boolean; pluginTypes: KiotaPluginType[]; operation: ConsumerOperation; - pluginAuthConfiguration?: PluginAuthConfiguration; + pluginAuthRefid?: string; + pluginAuthType?: PluginAuthType | null; } -export interface PluginAuthConfiguration { - referenceId: string; - authType: PluginAuthType; -} - -enum PluginAuthType { +export enum PluginAuthType { oAuthPluginVault = "OAuthPluginVault", apiKeyPluginVault = "ApiKeyPluginVault" }