From 4c01b5780839aa7d1cdb5b6d3535aa9d240efb94 Mon Sep 17 00:00:00 2001 From: thewahome Date: Fri, 13 Dec 2024 13:11:02 +0300 Subject: [PATCH 1/4] send auth information from workspace file --- .../src/commands/generate/generatePlugin.ts | 17 ++++++++++------- .../commands/regenerate/regenerate.service.ts | 7 ++++++- .../microsoft-kiota/src/kiotaInterop/index.ts | 16 +++++++++++++++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/vscode/microsoft-kiota/src/commands/generate/generatePlugin.ts b/vscode/microsoft-kiota/src/commands/generate/generatePlugin.ts index e4cb2b7b79..b42b3bbded 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 } from "../../kiotaInterop"; +import { connectToKiota, ConsumerOperation, GenerationConfiguration, KiotaLogEntry, PluginAuthConfiguration } from "../../kiotaInterop"; import { KiotaPluginType } from "../../types/enums"; import { getWorkspaceJsonDirectory } from "../../util"; @@ -16,7 +16,9 @@ export function generatePlugin(context: vscode.ExtensionContext, cleanOutput: boolean, disableValidationRules: string[], operation: ConsumerOperation, - workingDirectory: string = getWorkspaceJsonDirectory()): Promise { + pluginAuthConfiguration?: PluginAuthConfiguration, + workingDirectory: string = getWorkspaceJsonDirectory(), +): Promise { return connectToKiota(context, async (connection) => { const request = new rpc.RequestType1( "GeneratePlugin" @@ -24,16 +26,17 @@ export function generatePlugin(context: vscode.ExtensionContext, return await connection.sendRequest( request, { - pluginTypes: pluginTypes, - cleanOutput: cleanOutput, - clearCache: clearCache, - clientClassName: clientClassName, + pluginTypes, + cleanOutput, + clearCache, + clientClassName, disabledValidationRules: disableValidationRules, excludePatterns: excludeFilters, includePatterns: includeFilters, openAPIFilePath: descriptionPath, outputPath: output, - operation: operation + 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 ba72a5b966..c84fe9d106 100644 --- a/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts +++ b/vscode/microsoft-kiota/src/commands/regenerate/regenerate.service.ts @@ -66,6 +66,10 @@ 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, @@ -83,7 +87,8 @@ export class RegenerateService { settings.clearCache, false, settings.disableValidationRules, - ConsumerOperation.Edit + ConsumerOperation.Edit, + pluginAuthConfiguration ); 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 3eb5adcda2..803829ab93 100644 --- a/vscode/microsoft-kiota/src/kiotaInterop/index.ts +++ b/vscode/microsoft-kiota/src/kiotaInterop/index.ts @@ -24,6 +24,7 @@ export async function connectToKiota(context: vscode.ExtensionContext, callba try { return await callback(connection); } catch (error) { + console.warn(error); const errorMessage = (error as { data?: { message: string } })?.data?.message || 'An unknown error occurred'; vscode.window.showErrorMessage(errorMessage); @@ -248,6 +249,17 @@ export interface GenerationConfiguration { usesBackingStore: boolean; pluginTypes: KiotaPluginType[]; operation: ConsumerOperation; + pluginAuthConfiguration?: PluginAuthConfiguration; +} + +export interface PluginAuthConfiguration { + referenceId: string; + authType: PluginAuthType; +} + +enum PluginAuthType { + oAuthPluginVault = "OAuthPluginVault", + apiKeyPluginVault = "ApiKeyPluginVault" } interface WorkspaceObjectProperties { @@ -269,6 +281,8 @@ export interface ClientObjectProperties extends WorkspaceObjectProperties { export interface PluginObjectProperties extends WorkspaceObjectProperties { types: string[]; + authType?: PluginAuthType, + authReferenceId?: string; } -export type ClientOrPluginProperties = ClientObjectProperties | PluginObjectProperties; +export type ClientOrPluginProperties = ClientObjectProperties | PluginObjectProperties; \ No newline at end of file From 3dac9fb84303f7bbc3031974fa06c8a4dedaa8a6 Mon Sep 17 00:00:00 2001 From: thewahome Date: Mon, 16 Dec 2024 13:47:43 +0300 Subject: [PATCH 2/4] add plugin auth information to the rpc server function --- src/kiota/Rpc/IServer.cs | 2 +- src/kiota/Rpc/Server.cs | 5 ++++- vscode/microsoft-kiota/package.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/kiota/Rpc/IServer.cs b/src/kiota/Rpc/IServer.cs index 2ec90beb7a..c8daa66ab4 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, ConsumerOperation operation, 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> 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 b60155710b..4997c744fb 100644 --- a/src/kiota/Rpc/Server.cs +++ b/src/kiota/Rpc/Server.cs @@ -184,7 +184,9 @@ public async Task> GenerateAsync(string openAPIFilePath, string o } return logger.LogEntries; } - public async Task> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, ConsumerOperation operation, CancellationToken cancellationToken) + 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) { var globalLogger = new ForwardedLogger(); var configuration = Configuration.Generation; @@ -206,6 +208,7 @@ 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; try { using var fileLogger = new FileLogLogger(configuration.OutputPath, LogLevel.Warning); diff --git a/vscode/microsoft-kiota/package.json b/vscode/microsoft-kiota/package.json index 89f7a78892..c0e1c65d7e 100644 --- a/vscode/microsoft-kiota/package.json +++ b/vscode/microsoft-kiota/package.json @@ -4,7 +4,7 @@ "publisher": "ms-graph", "description": "Client generator for HTTP REST APIs described by OpenAPI which helps eliminate the need to take a dependency on a different API client for every API that you need to call, as well as limiting the generation to the exact API surface area you're interested in, thanks to a filtering capability.", "version": "1.21.100000001", - "kiotaVersion": "1.21.0", + "kiotaVersion": "1.22.0", "telemetryInstrumentationKey": "4c6357e0-daf9-42b5-bdfb-67878f8957b5", "icon": "images/logo.png", "engines": { From 25a9a402ce9b6f35cfe2498355a163a9899c94be Mon Sep 17 00:00:00 2001 From: thewahome Date: Tue, 7 Jan 2025 14:09:03 +0300 Subject: [PATCH 3/4] 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" } From e0d18906d6f6ed2b8995c2b614ea3af282687cb0 Mon Sep 17 00:00:00 2001 From: thewahome Date: Tue, 7 Jan 2025 14:14:16 +0300 Subject: [PATCH 4/4] pass empty auth parameters when generating clients --- .../src/commands/generate/generateClientCommand.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts index c7e21c47f0..e65cebaf85 100644 --- a/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts +++ b/vscode/microsoft-kiota/src/commands/generate/generateClientCommand.ts @@ -201,6 +201,8 @@ export class GenerateClientCommand extends Command { settings.cleanOutput, settings.disableValidationRules, ConsumerOperation.Add, + undefined, + '', config.workingDirectory ); const duration = performance.now() - start; @@ -245,6 +247,8 @@ export class GenerateClientCommand extends Command { settings.cleanOutput, settings.disableValidationRules, ConsumerOperation.Add, + undefined, + '', config.workingDirectory ); const duration = performance.now() - start;