Skip to content

Commit

Permalink
pass auth as primitive type instead of complex type
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome committed Jan 7, 2025
1 parent c56b619 commit 25a9a40
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
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, PluginAuthConfiguration? pluginAuthConfiguration, 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, PluginAuthType? pluginAuthType, string pluginAuthRefid, 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
10 changes: 8 additions & 2 deletions src/kiota/Rpc/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public async Task<List<LogEntry>> GenerateAsync(string openAPIFilePath, string o
}
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)
PluginAuthType? pluginAuthType, string? pluginAuthRefid, ConsumerOperation operation, CancellationToken cancellationToken)
{
var globalLogger = new ForwardedLogger<KiotaBuilder>();
var configuration = Configuration.Generation;
Expand All @@ -208,7 +208,13 @@ 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;
if (!string.IsNullOrEmpty(pluginAuthRefid) && pluginAuthType != null)
{
var pluginAuthConfig = new PluginAuthConfiguration(pluginAuthRefid);
pluginAuthConfig.AuthType = pluginAuthType.Value;
configuration.PluginAuthInformation = pluginAuthConfig;
}

try
{
using var fileLogger = new FileLogLogger<KiotaBuilder>(configuration.OutputPath, LogLevel.Warning);
Expand Down
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, PluginAuthConfiguration } from "../../kiotaInterop";
import { connectToKiota, ConsumerOperation, GenerationConfiguration, KiotaLogEntry, PluginAuthType } from "../../kiotaInterop";
import { KiotaPluginType } from "../../types/enums";
import { getWorkspaceJsonDirectory } from "../../util";

Expand All @@ -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<KiotaLogEntry[] | undefined> {
return connectToKiota<KiotaLogEntry[]>(context, async (connection) => {
Expand All @@ -35,8 +36,9 @@ export function generatePlugin(context: vscode.ExtensionContext,
includePatterns: includeFilters,
openAPIFilePath: descriptionPath,
outputPath: output,
pluginAuthType,
pluginAuthRefid,
operation,
pluginAuthConfiguration
} as GenerationConfiguration,
);
}, workingDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
10 changes: 3 additions & 7 deletions vscode/microsoft-kiota/src/kiotaInterop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down

0 comments on commit 25a9a40

Please sign in to comment.