Skip to content

Commit

Permalink
Merge branch 'main' into update-label-needs-author-feedback-to-curren…
Browse files Browse the repository at this point in the history
…t-label-in-use
  • Loading branch information
fey101 authored May 20, 2024
2 parents a3980fc + 62a6aee commit ada76c3
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for multipart form data request body in PHP. [#3029](https://github.com/microsoft/kiota/issues/3029)
- Added uri-form encoded serialization for PHP. [#2074](https://github.com/microsoft/kiota/issues/2074)
- Added information message with base URL in the CLI experience. [#4635](https://github.com/microsoft/kiota/issues/4635)
- Added optional parameter --disable-ssl-validation for generate, show, and download commands. [#4176](https://github.com/microsoft/kiota/issues/4176)

### Changed

Expand Down
8 changes: 4 additions & 4 deletions it/python/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-i https://pypi.org/simple

astroid==3.2.1 ; python_full_version >= '3.7.2'
astroid==3.2.2 ; python_full_version >= '3.7.2'

certifi==2024.2.2 ; python_version >= '3.6'

Expand Down Expand Up @@ -40,11 +40,11 @@ platformdirs==4.2.2 ; python_version >= '3.7'

pluggy==1.5.0 ; python_version >= '3.7'

pylint==3.2.0
pylint==3.2.2

pytest==8.2.0
pytest==8.2.1

pytest-asyncio==0.23.6
pytest-asyncio==0.23.7

requests==2.31.0 ; python_version >= '3.7'

Expand Down
7 changes: 6 additions & 1 deletion src/Kiota.Builder/Configuration/DownloadConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ public bool CleanOutput
{
get; set;
}
public bool DisableSSLValidation
{
get; set;
}

public object Clone()
{
return new DownloadConfiguration
{
OutputPath = OutputPath,
CleanOutput = CleanOutput,
ClearCache = ClearCache
ClearCache = ClearCache,
DisableSSLValidation = DisableSSLValidation,
};
}
}
6 changes: 6 additions & 0 deletions src/Kiota.Builder/Configuration/GenerationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public object Clone()
Operation = Operation,
PatternsOverride = new(PatternsOverride ?? Enumerable.Empty<string>(), StringComparer.OrdinalIgnoreCase),
PluginTypes = new(PluginTypes ?? Enumerable.Empty<PluginType>()),
DisableSSLValidation = DisableSSLValidation,
};
}
private static readonly StringIEnumerableDeepComparer comparer = new();
Expand Down Expand Up @@ -200,6 +201,11 @@ private string NormalizeDescriptionLocation(string targetDirectory)
return OpenAPIFilePath;
}
public bool IsPluginConfiguration => PluginTypes.Count != 0;

public bool DisableSSLValidation
{
get; set;
}
}
#pragma warning restore CA1056
#pragma warning restore CA2227
9 changes: 9 additions & 0 deletions src/Kiota.Builder/Lock/KiotaLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ public bool IncludeAdditionalData
{
get; set;
}
/// <summary>
/// Whether SSL Validation was disabled for this client.
/// </summary>
public bool DisableSSLValidation
{
get; set;
}
#pragma warning disable CA2227
/// <summary>
/// The serializers used for this client.
Expand Down Expand Up @@ -108,6 +115,7 @@ public void UpdateGenerationConfigurationFromLock(GenerationConfiguration config
config.ExcludePatterns = ExcludePatterns;
config.OpenAPIFilePath = DescriptionLocation;
config.DisabledValidationRules = DisabledValidationRules;
config.DisableSSLValidation = DisableSSLValidation;
}
/// <summary>
/// Initializes a new instance of the <see cref="KiotaLock"/> class.
Expand Down Expand Up @@ -135,5 +143,6 @@ public KiotaLock(GenerationConfiguration config)
ExcludePatterns = config.ExcludePatterns;
DescriptionLocation = config.OpenAPIFilePath;
DisabledValidationRules = config.DisabledValidationRules;
DisableSSLValidation = config.DisableSSLValidation;
}
}
1 change: 1 addition & 0 deletions src/Kiota.Builder/Lock/KiotaLockComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public int GetHashCode([DisallowNull] KiotaLock obj)
{
if (obj == null) return 0;
return
obj.DisableSSLValidation.GetHashCode() * 59 +
_stringIEnumerableDeepComparer.GetHashCode(obj.DisabledValidationRules?.Order(StringComparer.OrdinalIgnoreCase) ?? Enumerable.Empty<string>()) * 53 +
obj.KiotaVersion.GetHashCode(StringComparison.OrdinalIgnoreCase) * 47 +
obj.LockFileVersion.GetHashCode(StringComparison.OrdinalIgnoreCase) * 43 +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"**/generate",
"**/repos/**/topics"
],
"disabledValidationRules": []
}
"disabledValidationRules": [],
"disableSSLValidation": false
}
26 changes: 25 additions & 1 deletion src/kiota/Handlers/BaseKiotaCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ protected static void DefaultSerializersAndDeserializers(GenerationConfiguration
Logger = logger,
FileName = "pat-api.github.com"
};
internal static readonly HttpClient httpClient = new();

private HttpClient? _httpClient;
protected HttpClient httpClient
{
get
{
_httpClient ??= GetHttpClient();
return _httpClient;
}
}
public required Option<LogLevel> LogLevelOption
{
get; init;
Expand All @@ -52,6 +61,21 @@ protected KiotaConfiguration Configuration
configObject.BindConfiguration(configuration);
return configObject;
});

protected HttpClient GetHttpClient()
{
var httpClientHandler = new HttpClientHandler();
if (Configuration.Generation.DisableSSLValidation)
httpClientHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

var httpClient = new HttpClient(httpClientHandler);

disposables.Add(httpClientHandler);
disposables.Add(httpClient);

return httpClient;
}

private const string GitHubScope = "repo";
private Func<CancellationToken, Task<bool>> GetIsGitHubDeviceSignedInCallback(ILogger logger) => (cancellationToken) =>
{
Expand Down
6 changes: 6 additions & 0 deletions src/kiota/Handlers/KiotaDownloadCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,22 @@ public required Option<bool> CleanOutputOption
{
get; init;
}
public required Option<bool> DisableSSLValidationOption
{
get; init;
}
public override async Task<int> InvokeAsync(InvocationContext context)
{
string searchTerm = context.ParseResult.GetValueForArgument(SearchTermArgument);
string version = context.ParseResult.GetValueForOption(VersionOption) ?? string.Empty;
string outputPath = context.ParseResult.GetValueForOption(OutputPathOption) ?? string.Empty;
bool cleanOutput = context.ParseResult.GetValueForOption(CleanOutputOption);
bool clearCache = context.ParseResult.GetValueForOption(ClearCacheOption);
bool disableSSLValidation = context.ParseResult.GetValueForOption(DisableSSLValidationOption);
CancellationToken cancellationToken = context.BindingContext.GetService(typeof(CancellationToken)) is CancellationToken token ? token : CancellationToken.None;

Configuration.Download.ClearCache = clearCache;
Configuration.Download.DisableSSLValidation = disableSSLValidation;
Configuration.Download.CleanOutput = cleanOutput;
Configuration.Download.OutputPath = NormalizeSlashesInPath(outputPath);

Expand Down
6 changes: 6 additions & 0 deletions src/kiota/Handlers/KiotaGenerateCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public override async Task<int> InvokeAsync(InvocationContext context)
bool backingStore = context.ParseResult.GetValueForOption(BackingStoreOption);
bool excludeBackwardCompatible = context.ParseResult.GetValueForOption(ExcludeBackwardCompatibleOption);
bool clearCache = context.ParseResult.GetValueForOption(ClearCacheOption);
bool disableSSLValidation = context.ParseResult.GetValueForOption(DisableSSLValidationOption);
bool includeAdditionalData = context.ParseResult.GetValueForOption(AdditionalDataOption);
string className = context.ParseResult.GetValueForOption(ClassOption) ?? string.Empty;
string namespaceName = context.ParseResult.GetValueForOption(NamespaceOption) ?? string.Empty;
Expand Down Expand Up @@ -112,6 +113,7 @@ public override async Task<int> InvokeAsync(InvocationContext context)
Configuration.Generation.ApiManifestPath = NormalizeSlashesInPath(GetAbsolutePath(Configuration.Generation.ApiManifestPath));
Configuration.Generation.CleanOutput = cleanOutput;
Configuration.Generation.ClearCache = clearCache;
Configuration.Generation.DisableSSLValidation = disableSSLValidation;

var (loggerFactory, logger) = GetLoggerAndFactory<KiotaBuilder>(context, Configuration.Generation.OutputPath);
using (loggerFactory)
Expand Down Expand Up @@ -173,4 +175,8 @@ public required Option<bool> ExcludeBackwardCompatibleOption
get;
set;
}
public required Option<bool> DisableSSLValidationOption
{
get; init;
}
}
6 changes: 6 additions & 0 deletions src/kiota/Handlers/KiotaShowCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public required Option<string> ManifestOption
{
get; init;
}
public required Option<bool> DisableSSLValidationOption
{
get; init;
}

public override async Task<int> InvokeAsync(InvocationContext context)
{
Expand All @@ -52,11 +56,13 @@ public override async Task<int> InvokeAsync(InvocationContext context)
List<string> includePatterns = context.ParseResult.GetValueForOption(IncludePatternsOption) ?? new List<string>();
List<string> excludePatterns = context.ParseResult.GetValueForOption(ExcludePatternsOption) ?? new List<string>();
bool clearCache = context.ParseResult.GetValueForOption(ClearCacheOption);
bool disableSSLValidation = context.ParseResult.GetValueForOption(DisableSSLValidationOption);
CancellationToken cancellationToken = context.BindingContext.GetService(typeof(CancellationToken)) is CancellationToken token ? token : CancellationToken.None;

var (loggerFactory, logger) = GetLoggerAndFactory<KiotaBuilder>(context);

Configuration.Search.ClearCache = clearCache;
Configuration.Generation.DisableSSLValidation = disableSSLValidation;
using (loggerFactory)
{
await CheckForNewVersionAsync(logger, cancellationToken).ConfigureAwait(false);
Expand Down
19 changes: 19 additions & 0 deletions src/kiota/KiotaHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private static Command GetShowCommand()
var searchTermOption = GetSearchKeyOption();
var maxDepthOption = new Option<uint>("--max-depth", () => 5, "The maximum depth of the tree to display");
maxDepthOption.AddAlias("--m-d");
var disableSSLValidationOption = GetDisableSSLValidationOption(defaultGenerationConfiguration.DisableSSLValidation);
var displayCommand = new Command("show", "Displays the API tree in a given description."){
searchTermOption,
logLevelOption,
Expand All @@ -163,6 +164,7 @@ private static Command GetShowCommand()
includePatterns,
excludePatterns,
clearCacheOption,
disableSSLValidationOption,
};
displayCommand.Handler = new KiotaShowCommandHandler
{
Expand All @@ -175,6 +177,7 @@ private static Command GetShowCommand()
IncludePatternsOption = includePatterns,
ExcludePatternsOption = excludePatterns,
ClearCacheOption = clearCacheOption,
DisableSSLValidationOption = disableSSLValidationOption,
};
return displayCommand;
}
Expand Down Expand Up @@ -213,13 +216,16 @@ private static Command GetDownloadCommand()

var outputOption = GetOutputPathOption(defaultConfiguration.OutputPath);

var disableSSLValidationOption = GetDisableSSLValidationOption(defaultConfiguration.DisableSSLValidation);

var searchCommand = new Command("download", "Downloads an OpenAPI description from multiple registries."){
keyArgument,
logLevelOption,
clearCacheOption,
versionOption,
cleanOutputOption,
outputOption,
disableSSLValidationOption,
};
searchCommand.Handler = new KiotaDownloadCommandHandler
{
Expand All @@ -229,6 +235,7 @@ private static Command GetDownloadCommand()
VersionOption = versionOption,
CleanOutputOption = cleanOutputOption,
OutputPathOption = outputOption,
DisableSSLValidationOption = disableSSLValidationOption,
};
return searchCommand;
}
Expand Down Expand Up @@ -444,6 +451,8 @@ private static Command GetGenerateCommand()

var clearCacheOption = GetClearCacheOption(defaultConfiguration.ClearCache);

var disableSSLValidationOption = GetDisableSSLValidationOption(defaultConfiguration.DisableSSLValidation);

var command = new Command("generate", "Generates a REST HTTP API client from an OpenAPI description file.") {
descriptionOption,
manifestOption,
Expand All @@ -463,6 +472,7 @@ private static Command GetGenerateCommand()
excludePatterns,
dvrOption,
clearCacheOption,
disableSSLValidationOption,
};
command.Handler = new KiotaGenerateCommandHandler
{
Expand All @@ -484,6 +494,7 @@ private static Command GetGenerateCommand()
ExcludePatternsOption = excludePatterns,
DisabledValidationRulesOption = dvrOption,
ClearCacheOption = clearCacheOption,
DisableSSLValidationOption = disableSSLValidationOption,
};
return command;
}
Expand Down Expand Up @@ -541,6 +552,14 @@ private static Option<bool> GetClearCacheOption(bool defaultValue)
clearCacheOption.AddAlias("--cc");
return clearCacheOption;
}

private static Option<bool> GetDisableSSLValidationOption(bool defaultValue)
{
var disableSSLValidationOption = new Option<bool>("--disable-ssl-validation", () => defaultValue, "Disables SSL certificate validation.");
disableSSLValidationOption.AddAlias("--dsv");
return disableSSLValidationOption;
}

private static void AddStringRegexValidator(Option<string> option, Regex validator, string parameterName, bool allowEmpty = false)
{
option.AddValidator(input =>
Expand Down
2 changes: 1 addition & 1 deletion src/kiota/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"kiota": {
"commandName": "Project",
"commandLineArgs": "--openapi C:\\src\\msgraph-sdk-powershell\\openApiDocs\\v1.0\\mail.yml -o C:\\Users\\darrmi\\source\\github\\darrelmiller\\OpenApiClient\\Generated -c GraphClient --loglevel Information"
"commandLineArgs": "generate --openapi https://localhost:3000/swagger.json -o E:\\OSS\\kiota\\Output\\local_3 -c GraphClient --log-level Information -l CSharp --dsv"
}
}
}

0 comments on commit ada76c3

Please sign in to comment.