Skip to content

Commit

Permalink
client2 up
Browse files Browse the repository at this point in the history
  • Loading branch information
brig committed Sep 20, 2023
1 parent 75b3492 commit c7e649e
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> tags();

ProcessStatus status();
@Nullable
String status();

@Nullable
String initiator();

@Nullable
UUID parentInstanceId();

Set<ProcessDataInclude> include();
@Nullable
Set<String> include();

@Nullable
Integer limit();

@Nullable
Integer offset();

Map<String, String> meta();
@Nullable
Map<String, Object> 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();
}
}
16 changes: 16 additions & 0 deletions client2/src/main/template/libraries/native/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>{{/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<Void>{{/asyncNative}}{{^asyncNative}}void{{/asyncNative}}{{/returnType}} {{operationId}}({{#isMultipart}}{{#allParams}}{{^isFormParam}}{{{dataType}}} {{paramName}},{{/isFormParam}}{{/allParams}} Map<String, Object> 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}});
Expand Down Expand Up @@ -371,6 +378,13 @@ public class {{classname}} {
{{javaUtilPrefix}}List<Pair> localVarQueryParams = new {{javaUtilPrefix}}ArrayList<>();
{{javaUtilPrefix}}StringJoiner localVarQueryStringJoiner = new {{javaUtilPrefix}}StringJoiner("&");
{{#queryParams}}
{{#vendorExtensions.x-concord.customQueryParams}}
if ({{paramName}} != null) {
for (Map.Entry<String, Object> e : {{paramName}}.entrySet()) {
localVarQueryParams.addAll(ApiClient.parameterToPairs(e.getKey(), e.getValue()));
}
}
{{/vendorExtensions.x-concord.customQueryParams}}
{{#collectionFormat}}
localVarQueryParams.addAll(ApiClient.parameterToPairs("{{{collectionFormat}}}", "{{baseName}}", {{paramName}}));
{{/collectionFormat}}
Expand Down Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c7e649e

Please sign in to comment.