Skip to content

Commit

Permalink
Introduce ssh pretty urls (#2850) - Launch form, "friendly url" forma…
Browse files Browse the repository at this point in the history
…t for SSH-only tools (without endpoints)
  • Loading branch information
rodichenko committed Oct 4, 2022
1 parent 315beba commit c72df07
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
24 changes: 17 additions & 7 deletions client/src/components/pipelines/launch/form/LaunchPipelineForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3415,10 +3415,14 @@ class LaunchPipelineForm extends localization.LocalizedReactComponent {
!this.props.editConfigurationMode;
}

@computed
get prettyUrlEnabled () {
if (this.state.fireCloudMethodName || this.props.detached) {
return undefined;
return !this.state.fireCloudMethodName && !this.props.detached;
}

@computed
get prettyUrlSSHMode () {
if (!this.prettyUrlEnabled) {
return false;
}
const dockerImage = this.getSectionFieldValue(EXEC_ENVIRONMENT)('dockerImage') ||
this.getDefaultValue('docker_image');
Expand All @@ -3433,15 +3437,15 @@ class LaunchPipelineForm extends localization.LocalizedReactComponent {
const [image] = toolAndVersion.split(':');
const [im] = (imageGroup.tools || [])
.filter(i => i.image.toLowerCase() === `${group}/${image}`);
return im && im.endpoints && (im.endpoints || []).length > 0;
return !(im && im.endpoints && (im.endpoints || []).length > 0);
}
}
}
return false;
return true;
}

checkFriendlyURL = (rule, value, callback) => {
const error = prettyUrlGenerator.validate(value);
const error = prettyUrlGenerator.validate(value, this.prettyUrlSSHMode);
if (error) {
callback(error);
}
Expand All @@ -3450,6 +3454,7 @@ class LaunchPipelineForm extends localization.LocalizedReactComponent {

renderPrettyUrlFormItem = () => {
if (this.prettyUrlEnabled && this.friendlyUrlAvailable()) {
const sshMode = this.prettyUrlSSHMode;
return (
<FormItem
className={getFormItemClassName(styles.formItemRow, 'prettyUrl')}
Expand Down Expand Up @@ -3477,7 +3482,12 @@ class LaunchPipelineForm extends localization.LocalizedReactComponent {
</FormItem>
</Col>
<Col span={1} style={{marginLeft: 7, marginTop: 3}}>
{hints.renderHint(this.localizedStringWithSpotDictionaryFn, hints.prettyUrlHint)}
{
hints.renderHint(
this.localizedStringWithSpotDictionaryFn,
sshMode ? hints.prettySSHUrlHint : hints.prettyUrlHint
)
}
</Col>
</FormItem>
);
Expand Down
10 changes: 10 additions & 0 deletions client/src/components/pipelines/launch/form/hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ const prettyUrlHint = (localizedStringFn) => (
</Row>
);

const prettySSHUrlHint = (localizedStringFn) => (
<Row style={{maxWidth: 300}}>
This value will be used in the <b>SSH URL</b> instead of the general
"/ssh/pipeline/run_id" string.
This value shall be unique across all runs. <br />
You can not use domain name for the SSH URL. Only alphanumeric string is allowed.
</Row>
);

const endpointNameHint = (localizedStringFn) => (
<Row style={{maxWidth: 300}}>
This value specifies which <b>tool endpoint</b> will be used to process <b>serverless API</b> calls
Expand Down Expand Up @@ -203,6 +212,7 @@ const hints = {
limitMountsHint,
doNotMountStoragesHint,
prettyUrlHint,
prettySSHUrlHint,
executionEnvironmentSummaryHint,
endpointNameHint,
stopAfterHint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint-disable max-len */
const endpointURIMask = /^[a-zA-Z\d_]+$/;
const domainMask = /^[-a-zA-Z0-9_\.]+(:\d+)?$/i;

Expand All @@ -34,11 +34,19 @@ function parse (value) {
return value;
}

function validate (url) {
function validate (url, sshMode = false) {
if (!url) {
return undefined;
}
const {domain, path} = build(url, false);
if (sshMode) {
if (domain) {
return 'You can not use domain name for the SSH URL';
}
if (path && !endpointURIMask.test(path)) {
return 'Please enter valid endpoint name (only characters, numbers and \'_\' symbols are allowed)';
}
}
if (
domain &&
(
Expand Down

0 comments on commit c72df07

Please sign in to comment.