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

Implement channel name regex configuration #1458

Merged
merged 1 commit into from
Apr 7, 2021
Merged
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: 2 additions & 0 deletions distro/docker-compose/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ APICURIO_UI_FEATURE_MICROCKS=true

APICURIO_SHARE_FOR_EVERYONE=false
APICURIO_UI_FEATURE_SHARE_WITH_EVERYONE=false

APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP='([^{}\/]*(\{[a-zA-Z_][0-9a-zA-Z_]*\})?)+'
1 change: 1 addition & 0 deletions distro/docker-compose/docker-compose.apicurio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ services:
APICURIO_UI_FEATURE_MICROCKS: ${APICURIO_UI_FEATURE_MICROCKS}
APICURIO_UI_FEATURE_SHARE_WITH_EVERYONE: ${APICURIO_UI_FEATURE_SHARE_WITH_EVERYONE}
APICURIO_UI_LOGOUT_REDIRECT_URI: /
APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP: ${APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP}
2 changes: 2 additions & 0 deletions distro/helm/templates/apicurio-studio-ui-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
value: {{ .Values.ui.hub.api.url | default (print "https://" .Values.ui.hostname "/studio-api") }}
- name: APICURIO_UI_EDITING_URL
value: {{ .Values.ui.editing.url | default (print "wss://" .Values.ui.hostname "/ws") }}
- name: APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP
value: { { .values.ui.channelNameRegex } }
- name: JAVA_TOOL_OPTIONS
value: {{ .Values.ui.jvmArgs }}
- name: APICURIO_MICROCKS_API_URL
Expand Down
1 change: 1 addition & 0 deletions distro/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ui:
jvmArgs: -Djava.net.preferIPv4Stack=true
port: 8093
imagePullPolicy: IfNotPresent
channelNameRegex: ([^{}\/]*(\{[a-zA-Z_][0-9a-zA-Z_]*\})?)+
hostname: APICURIO_URL
extraVolumes: []
logout:
Expand Down
2 changes: 2 additions & 0 deletions distro/kubernetes/apicurio-studio-ui-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ spec:
key: apicurio-ui-editing-url
- name: JAVA_TOOL_OPTIONS
value: -Djava.net.preferIPv4Stack=true
- name: APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP
value: '{([^{}\/]*(\{[a-zA-Z_][0-9a-zA-Z_]*\})?)+'
- name: APICURIO_MICROCKS_API_URL
valueFrom:
configMapKeyRef:
Expand Down
2 changes: 2 additions & 0 deletions distro/quarkus/docker-compose/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ APICURIO_UI_KC_CLIENT_ID=apicurio-studio
APICURIO_UI_HUB_API_URL=http://$HOST:8091
APICURIO_UI_EDITING_URL=ws://$HOST:8092
APICURIO_UI_FEATURE_MICROCKS=true
APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP='([^{}\/]*(\{[a-zA-Z_][0-9a-zA-Z_]*\})?)+'


APICURIO_SHARE_FOR_EVERYONE=false
APICURIO_UI_FEATURE_SHARE_WITH_EVERYONE=false
1 change: 1 addition & 0 deletions distro/quarkus/docker-compose/docker-compose.apicurio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ services:
APICURIO_UI_FEATURE_MICROCKS: ${APICURIO_UI_FEATURE_MICROCKS}
APICURIO_UI_FEATURE_SHARE_WITH_EVERYONE: ${APICURIO_UI_FEATURE_SHARE_WITH_EVERYONE}
APICURIO_UI_LOGOUT_REDIRECT_URI: /
APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP: ${APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class StudioUiConfiguration extends Configuration {
private static final String FEATURE_SHARE_WITH_EVERYONE_ENV = "APICURIO_UI_FEATURE_SHARE_WITH_EVERYONE";
private static final String FEATURE_SHARE_WITH_EVERYONE_SYSPROP = "apicurio-ui.feature.shareWithEveryone";

private static final String VALIDATION_CHANNELNAME_REGEXP_ENV= "APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP";
private static final String VALIDATION_CHANNELNAME_REGEXP_SYSPROP = "apicurio-ui.validation.channelName.regexp";

/**
* Returns the URL of the Apicurio Hub API.
*/
Expand Down Expand Up @@ -119,4 +122,10 @@ public String getUiUrl() {
return getConfigurationProperty(HUB_UI_URL_ENV, HUB_UI_URL_SYSPROP, null);
}

/**
* @return the configured REGEXP CHANNEL
*/
public String getAddChannelValidation() {
return getConfigurationProperty(VALIDATION_CHANNELNAME_REGEXP_ENV, VALIDATION_CHANNELNAME_REGEXP_SYSPROP, "([^{}\\/]*(\\{[a-zA-Z_][0-9a-zA-Z_]*\\})?)+");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)

config.setUi(new StudioConfigUi());
config.getUi().setUrl(this.uiConfig.getUiUrl());
config.getUi().setChannelNameValidation(this.uiConfig.getAddChannelValidation());

config.setFeatures(new StudioConfigFeatures());
config.getFeatures().setMicrocks(uiConfig.isMicrocksEnabled());
config.getFeatures().setGraphql(uiConfig.isGraphQLEnabled());
config.getFeatures().setAsyncapi(uiConfig.isAsyncAPIEnabled());
config.getFeatures().setShareWithEveryone(uiConfig.isShareWithEveryoneEnabled());


g.writeObject(config);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h4 class="modal-title" id="addChannelModalLabel">Add Channel</h4>
<div class="form-group">
<label class="col-sm-2 control-label required" for="channel">Channel</label>
<div class="col-sm-10">
<input #addChannelInput name="channel" type="text" id="channel" class="form-control" placeholder="Enter a Channel" pattern="([^{}\/]*(\{[a-zA-Z_][0-9a-zA-Z_]*\})?)+" required [(ngModel)]="channel" (ngModelChange)="validateChannel($event)" #thechannel="ngModel">
<input #addChannelInput name="channel" type="text" id="channel" class="form-control" placeholder="Enter a Channel" pattern="{{channelValidation()}}" required [(ngModel)]="channel" (ngModelChange)="validateChannel($event)" #thechannel="ngModel">
<div class="form-error-message error" *ngIf="channelExists">Channel already exists.</div>
<form-error-message [inputModel]="thechannel" [type]="'pattern'" [alwaysOn]="true">Enter a valid channel.</form-error-message>
<form-error-message [inputModel]="thechannel" [type]="'required'">Channel is required.</form-error-message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import {Component, ElementRef, EventEmitter, Output, QueryList, ViewChildren} from "@angular/core";
import {ModalDirective} from "ngx-bootstrap";
import {AaiDocument} from "apicurio-data-models";
import {ConfigService} from "../../../../../../services/config.service";


@Component({
moduleId: module.id,
Expand All @@ -33,11 +35,16 @@ export class AddChannelDialogComponent {

private _isOpen: boolean = false;

channel: string = "";

channelRegex: string = "";
channel: string = "";
channels: string[] = [];
channelExists: boolean = false;

constructor(configService: ConfigService){
this.channelRegex = configService.channelNameValidation();
}

/**
* Called to open the dialog.
* @param document
Expand Down Expand Up @@ -111,4 +118,8 @@ export class AddChannelDialogComponent {
validateChannel(newChannel: string) {
this.channelExists = this.channels.indexOf(newChannel) != -1;
}

channelValidation(): string{
return this.channelRegex;
}
}
10 changes: 9 additions & 1 deletion front-end/studio/src/app/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ let DEFAULT_CONFIG: any = {
editingUrl: "http://localhost:8080/api-editing",
},
ui: {
uiUrl: "http://localhost:8080/studio/"
uiUrl: "http://localhost:8080/studio/",
channelNameValidation: '([^{}\\/]*(\\{[a-zA-Z_][0-9a-zA-Z_]*\\})?)+',
},
features: {
"microcks": true,
Expand Down Expand Up @@ -153,4 +154,11 @@ export class ConfigService {
}
return this.config.features.shareWithEveryone;
}

public channelNameValidation() :string {
if (!this.config.ui.channelNameValidation || !this.config.ui.channelNameValidation) {
return "";
}
return this.config.ui.channelNameValidation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
#apicurio
%dev.apicurio-ui.editing.url=${APICURIO_UI_EDITING_URL:http://localhost:8091/api}
%dev.apicurio-ui.hub-api.url=${APICURIO_UI_HUB_API_URL:https://localhost:8092/ws}
%dev.apicurio-ui.validation.channelName.regexp=${APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP:}

# === Prod profile

%prod.quarkus.oidc.auth-server-url=${APICURIO_KC_AUTH_URL}
%prod.quarkus.oidc.client-id=${APICURIO_KC_CLIENT_ID}
%prod.apicurio-ui.editing.url=${APICURIO_UI_EDITING_URL:}
%prod.apicurio-ui.hub-api.url=${APICURIO_UI_HUB_API_URL:}
%prod.apicurio-ui.validation.channelName.regexp=${APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP:}

quarkus.oidc.application-type=web-app
quarkus.http.cors=true
1 change: 1 addition & 0 deletions platforms/thorntail/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ENV APICURIO_MAX_HEAP=2048m
ENV APICURIO_GITHUB_API_URL=
ENV APICURIO_GITLAB_API_URL=
ENV APICURIO_BITBUCKET_API_URL=
ENV APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP='([^{}\/]*(\{[a-zA-Z_][0-9a-zA-Z_]*\})?)+'


CMD java -jar /opt/apicurio/apicurio-studio-api-thorntail.jar \
Expand Down
2 changes: 2 additions & 0 deletions platforms/thorntail/ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ENV APICURIO_UI_HUB_API_URL=https://localhost:8443/api
ENV APICURIO_UI_EDITING_URL=https://localhost:8443/ws
ENV APICURIO_MIN_HEAP=512m
ENV APICURIO_MAX_HEAP=2048m
ENV APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP='([^{}\/]*(\{[a-zA-Z_][0-9a-zA-Z_]*\})?)+'



CMD java -jar /opt/apicurio/apicurio-studio-ui-thorntail.jar \
Expand Down
1 change: 1 addition & 0 deletions platforms/thorntail/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The following environment variables control configuration of the app:
APICURIO_LOGGING_LEVEL=INFO
APICURIO_UI_LOGOUT_REDIRECT_URI=/logout
APICURIO_UI_HUB_UI_URL=http://localhost:8080
APICURIO_UI_VALIDATION_CHANNELNAME_REGEXP='([^{}\/]*(\{[a-zA-Z_][0-9a-zA-Z_]*\})?)+'
APICURIO_UI_HUB_API_URL=http://localhost:8090/
APICURIO_UI_EDITING_URL=http://localhost:8091/
APICURIO_UI_FEATURE_MICROCKS=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
public class StudioConfigUi {

private String url;

private String channelNameValidation;

/**
* Constructor.
Expand All @@ -49,4 +51,20 @@ public void setUrl(String url) {
this.url = url;
}

/**
* @return the channel Name Regex
*/
public String getChannelNameValidation() {
return channelNameValidation;
}

/**
* @param channelNameRegex the channel Name Regex to set
*/
public void setChannelNameValidation(String channelNameValidation) {
this.channelNameValidation = channelNameValidation;
}



}