diff --git a/client2/src/main/java/com/walmartlabs/concord/client2/ConcordApiClient.java b/client2/src/main/java/com/walmartlabs/concord/client2/ConcordApiClient.java index 44c8445440..d2e3b1aaad 100644 --- a/client2/src/main/java/com/walmartlabs/concord/client2/ConcordApiClient.java +++ b/client2/src/main/java/com/walmartlabs/concord/client2/ConcordApiClient.java @@ -22,9 +22,57 @@ import com.walmartlabs.concord.ApiClient; +import javax.net.ssl.*; +import java.net.http.HttpClient; +import java.security.GeneralSecurityException; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + public class ConcordApiClient extends ApiClient { + private boolean verifyingSsl = true; + private SSLContext sslContext; + public ConcordApiClient(String baseUrl) { updateBaseUri(baseUrl); } + + public ApiClient setVerifyingSsl(boolean verifyingSsl) { + this.verifyingSsl = verifyingSsl; + applySslSettings(); + return this; + } + + @Override + protected HttpClient.Builder createDefaultHttpClientBuilder() { + HttpClient.Builder result = super.createDefaultHttpClientBuilder(); + if (sslContext != null) { + result.sslContext(sslContext); + } + return result; + } + + private void applySslSettings() { + try { + TrustManager[] trustManagers; + if (!verifyingSsl) { + TrustManager trustAll = new X509TrustManager() { + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType) {} + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType) {} + @Override + public X509Certificate[] getAcceptedIssuers() { return null; } + }; + SSLContext sslContext = SSLContext.getInstance("TLS"); + trustManagers = new TrustManager[]{ trustAll }; + System.getProperties().setProperty("jdk.internal.httpclient.disableHostnameVerification", Boolean.TRUE.toString()); + + sslContext.init(null, trustManagers, new SecureRandom()); + } + } catch (GeneralSecurityException e) { + throw new RuntimeException(e); + } + } } diff --git a/client2/src/main/java/com/walmartlabs/concord/client2/ProcessDataInclude.java b/client2/src/main/java/com/walmartlabs/concord/client2/ProcessDataInclude.java index cbbc0ebb2f..e896b5bbcb 100644 --- a/client2/src/main/java/com/walmartlabs/concord/client2/ProcessDataInclude.java +++ b/client2/src/main/java/com/walmartlabs/concord/client2/ProcessDataInclude.java @@ -1,2 +1,39 @@ -package com.walmartlabs.concord.client2;public class ProcessDataInclude { +package com.walmartlabs.concord.client2; + +/*- + * ***** + * Concord + * ----- + * Copyright (C) 2017 - 2023 Walmart Inc. + * ----- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ===== + */ + +public enum ProcessDataInclude { + + CHECKPOINTS ("checkpoints"), + CHECKPOINTS_HISTORY ("checkpointsHistory"), + CHILDREN_IDS ("childrenIds"), + STATUS_HISTORY ("history"); + + private final String value; + + ProcessDataInclude(String value) { + this.value = value; + } + + public String getValue() { + return value; + } } diff --git a/client2/src/main/java/com/walmartlabs/concord/client2/ProcessListFilter.java b/client2/src/main/java/com/walmartlabs/concord/client2/ProcessListFilter.java index e259a25b52..73385ddd9a 100644 --- a/client2/src/main/java/com/walmartlabs/concord/client2/ProcessListFilter.java +++ b/client2/src/main/java/com/walmartlabs/concord/client2/ProcessListFilter.java @@ -20,51 +20,90 @@ * ===== */ -import com.walmartlabs.concord.server.OffsetDateTimeParam; -import com.walmartlabs.concord.server.process.ProcessDataInclude; -import com.walmartlabs.concord.server.sdk.ProcessStatus; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.enums.ParameterIn; -import io.swagger.v3.oas.annotations.extensions.Extension; -import io.swagger.v3.oas.annotations.extensions.ExtensionProperty; import org.immutables.value.Value; +import javax.annotation.Nullable; +import java.time.OffsetDateTime; import java.util.Map; import java.util.Set; import java.util.UUID; @Value.Immutable -public interface ListProcessFilter { +@Value.Style(jdkOnly = true) +public interface ProcessListFilter { + @Nullable UUID orgId(); + @Nullable String orgName(); + @Nullable UUID projectId(); + @Nullable String projectName(); + @Nullable UUID repoId(); + @Nullable String repoName(); + @Nullable OffsetDateTimeParam afterCreatedAt(); + @Nullable OffsetDateTimeParam beforeCreatedAt(); + @Nullable Set tags(); - ProcessStatus status(); + @Nullable + String status(); + @Nullable String initiator(); + @Nullable UUID parentInstanceId(); - Set include(); + @Nullable + Set include(); + @Nullable Integer limit(); + @Nullable Integer offset(); - Map meta(); + @Nullable + Map meta(); + + class Builder extends ImmutableProcessListFilter.Builder { + + public Builder status(ProcessEntry.StatusEnum status) { + return status(status.getValue()); + } + + public Builder addInclude(ProcessDataInclude... elements) { + for (ProcessDataInclude e : elements) { + addInclude(e.getValue()); + } + return this; + } + + public Builder afterCreatedAt(OffsetDateTime afterCreatedAt) { + if (afterCreatedAt == null) { + return this; + } + + afterCreatedAt(new OffsetDateTimeParam().value(afterCreatedAt)); + return this; + } + } + + static ImmutableProcessListFilter.Builder builder() { + return new Builder(); + } } diff --git a/client2/src/main/template/libraries/native/api.mustache b/client2/src/main/template/libraries/native/api.mustache index 156d9db9a4..88209330aa 100644 --- a/client2/src/main/template/libraries/native/api.mustache +++ b/client2/src/main/template/libraries/native/api.mustache @@ -197,6 +197,13 @@ public class {{classname}} { {{#isDeprecated}} @Deprecated {{/isDeprecated}} + + {{#vendorExtensions.x-concord.groupParams}} + public {{#returnType}}{{#asyncNative}}CompletableFuture<{{{returnType}}}>{{/asyncNative}}{{^asyncNative}}{{{returnType}}}{{/asyncNative}}{{/returnType}}{{^returnType}}{{#asyncNative}}CompletableFuture{{/asyncNative}}{{^asyncNative}}void{{/asyncNative}}{{/returnType}} {{operationId}}({{vendorExtensions.x-concord.groupName}} in) throws ApiException { + return {{operationId}}({{#isMultipart}}{{#allParams}}{{^isFormParam}}in.{{paramName}}(),{{/isFormParam}}{{/allParams}} multipartInput{{/isMultipart}}{{^isMultipart}}{{#allParams}}in.{{paramName}}(){{^-last}}, {{/-last}} {{/allParams}}{{/isMultipart}}); + } + {{/vendorExtensions.x-concord.groupParams}} + public {{#returnType}}{{#asyncNative}}CompletableFuture<{{{returnType}}}>{{/asyncNative}}{{^asyncNative}}{{{returnType}}}{{/asyncNative}}{{/returnType}}{{^returnType}}{{#asyncNative}}CompletableFuture{{/asyncNative}}{{^asyncNative}}void{{/asyncNative}}{{/returnType}} {{operationId}}({{#isMultipart}}{{#allParams}}{{^isFormParam}}{{{dataType}}} {{paramName}},{{/isFormParam}}{{/allParams}} Map multipartInput{{/isMultipart}}{{^isMultipart}}{{#allParams}} {{{dataType}}} {{paramName}}{{^-last}}, {{/-last}} {{/allParams}}{{/isMultipart}}) throws ApiException { {{^asyncNative}} {{#returnType}}ApiResponse<{{{.}}}> localVarResponse = {{/returnType}}{{operationId}}WithHttpInfo({{#isMultipart}}{{#allParams}}{{^isFormParam}}{{paramName}},{{/isFormParam}}{{/allParams}} multipartInput{{/isMultipart}}{{^isMultipart}}{{#allParams}}{{paramName}}{{^-last}}, {{/-last}} {{/allParams}}{{/isMultipart}}); @@ -371,6 +378,13 @@ public class {{classname}} { {{javaUtilPrefix}}List localVarQueryParams = new {{javaUtilPrefix}}ArrayList<>(); {{javaUtilPrefix}}StringJoiner localVarQueryStringJoiner = new {{javaUtilPrefix}}StringJoiner("&"); {{#queryParams}} + {{#vendorExtensions.x-concord.customQueryParams}} + if ({{paramName}} != null) { + for (Map.Entry e : {{paramName}}.entrySet()) { + localVarQueryParams.addAll(ApiClient.parameterToPairs(e.getKey(), e.getValue())); + } + } + {{/vendorExtensions.x-concord.customQueryParams}} {{#collectionFormat}} localVarQueryParams.addAll(ApiClient.parameterToPairs("{{{collectionFormat}}}", "{{baseName}}", {{paramName}})); {{/collectionFormat}} @@ -406,7 +420,9 @@ public class {{classname}} { localVarQueryStringJoiner.add({{paramName}}.toUrlQueryString()); {{/isModel}} {{^isModel}} + {{^vendorExtensions.x-concord.customQueryParams}} localVarQueryParams.addAll(ApiClient.parameterToPairs("{{baseName}}", {{paramName}})); + {{/vendorExtensions.x-concord.customQueryParams}} {{/isModel}} {{/hasVars}} {{/isExplode}} diff --git a/client2/src/test/java/com/walmartlabs/concord/client2/ApiClientJsonTest.java b/client2/src/test/java/com/walmartlabs/concord/client2/ApiClientJsonTest.java index fa9b74a7dd..df866392a3 100644 --- a/client2/src/test/java/com/walmartlabs/concord/client2/ApiClientJsonTest.java +++ b/client2/src/test/java/com/walmartlabs/concord/client2/ApiClientJsonTest.java @@ -22,7 +22,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.walmartlabs.concord.ApiClient; -import com.walmartlabs.concord.client2.ProjectEntry; import org.junit.jupiter.api.Test; import java.text.SimpleDateFormat;