Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task: regenerate with auth info #5914

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/kiota/Rpc/IServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal interface IServer
Task<ManifestResult> GetManifestDetailsAsync(string manifestPath, string apiIdentifier, bool clearCache, CancellationToken cancellationToken);
Task<List<LogEntry>> 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<LanguagesInformation> InfoForDescriptionAsync(string descriptionPath, bool clearCache, CancellationToken cancellationToken);
Task<List<LogEntry>> GeneratePluginAsync(string openAPIFilePath, string outputPath, PluginType[] pluginTypes, string[] includePatterns, string[] excludePatterns, string clientClassName, bool cleanOutput, bool clearCache, string[] disabledValidationRules, ConsumerOperation operation, CancellationToken cancellationToken);
Task<List<LogEntry>> 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<List<LogEntry>> MigrateFromLockFileAsync(string lockDirectoryPath, CancellationToken cancellationToken);
Task<List<LogEntry>> RemoveClientAsync(string clientName, bool cleanOutput, CancellationToken cancellationToken);
Task<List<LogEntry>> RemovePluginAsync(string pluginName, bool cleanOutput, CancellationToken cancellationToken);
Expand Down
5 changes: 4 additions & 1 deletion src/kiota/Rpc/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ public async Task<List<LogEntry>> GenerateAsync(string openAPIFilePath, string o
}
return logger.LogEntries;
}
public async Task<List<LogEntry>> 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<List<LogEntry>> 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<KiotaBuilder>();
var configuration = Configuration.Generation;
Expand All @@ -206,6 +208,7 @@ public async Task<List<LogEntry>> 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<KiotaBuilder>(configuration.OutputPath, LogLevel.Warning);
Expand Down
2 changes: 1 addition & 1 deletion vscode/microsoft-kiota/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
17 changes: 10 additions & 7 deletions vscode/microsoft-kiota/src/commands/generate/generatePlugin.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -16,24 +16,27 @@ export function generatePlugin(context: vscode.ExtensionContext,
cleanOutput: boolean,
disableValidationRules: string[],
operation: ConsumerOperation,
workingDirectory: string = getWorkspaceJsonDirectory()): Promise<KiotaLogEntry[] | undefined> {
pluginAuthConfiguration?: PluginAuthConfiguration,
workingDirectory: string = getWorkspaceJsonDirectory(),
): Promise<KiotaLogEntry[] | undefined> {
return connectToKiota<KiotaLogEntry[]>(context, async (connection) => {
const request = new rpc.RequestType1<GenerationConfiguration, KiotaLogEntry[], void>(
"GeneratePlugin"
);
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
16 changes: 15 additions & 1 deletion vscode/microsoft-kiota/src/kiotaInterop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function connectToKiota<T>(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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Loading