feat: 🎸 Add create worker page (#1244)

* feat: 🎸 Add create worker page

✅ Closes: ICU-5246
This commit is contained in:
Zhihe Li authored and GitHub committed 2022-08-26 11:50:53 -04:00
1 parent dd0d37241c
commit 3130831ae0
20 files changed
+507 -66

No files matched your search

@@ -0,0 +1,127 @@
<Rose::Form
@onSubmit={{fn @submit this.generatedWorkerAuthToken}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@showEditToggle={{false}}
as |form|
>
<form.input
@name='cluster_id'
@value={{this.clusterId}}
@label={{t 'resources.worker.form.cluster_id.label'}}
@helperText={{t 'resources.worker.form.cluster_id.help'}}
@linkText={{t 'actions.learn-more'}}
@link={{doc-url 'worker.manage-workers'}}
placeholder='69b6ddb3-ffec-42ab-a994-f43a6519470a'
/>
<form.input
@name='ip_address'
@value={{this.ipAddress}}
@label={{t 'resources.worker.form.ip_address.label'}}
@helperText={{t 'resources.worker.form.ip_address.help'}}
placeholder='127.0.0.1:9202'
/>
<form.input
@name='config_file_path'
@value={{this.configFilePath}}
@label={{t 'resources.worker.form.config_file_path.label'}}
@helperText={{t 'resources.worker.form.config_file_path.help'}}
placeholder='/home/ubuntu/boundary'
/>
<form.input
@name='worker_tags'
@value={{this.workerTags}}
@label={{t 'resources.worker.form.worker_tags.label'}}
@helperText={{t 'resources.worker.form.worker_tags.help'}}
placeholder='dev-worker, ubuntu'
/>
<h3>{{t 'resources.worker.form.steps.1.title'}}</h3>
<div class='worker-create-section'>
<Rose::CodeEditor @codeValue={{this.createConfigText}} as |c|>
<c.toolbar>
<:action>
<span>{{t 'resources.worker.form.steps.1.create_directory'}}</span>
</:action>
</c.toolbar>
<c.fieldEditor class='rose-autosize' @options={{this.shellCodeEditor}} />
</Rose::CodeEditor>
<Rose::CodeEditor @codeValue={{this.workerConfigText}} as |c|>
<c.toolbar>
<:action>
<span>{{t 'resources.worker.form.steps.1.create_config'}}</span>
</:action>
</c.toolbar>
<c.fieldEditor class='rose-autosize' @options={{this.hclCodeEditor}} />
</Rose::CodeEditor>
<p>{{t 'resources.worker.form.steps.1.save_config'}}</p>
</div>
<h3>{{t 'resources.worker.form.steps.2.title'}}</h3>
<div class='worker-create-section'>
<Rose::CodeEditor @codeValue={{this.installBoundaryText}} as |c|>
<c.toolbar>
<:action>
<span>{{t 'resources.worker.form.steps.2.run_command'}}</span>
</:action>
</c.toolbar>
<c.fieldEditor class='rose-autosize' @options={{this.shellCodeEditor}} />
</Rose::CodeEditor>
<span>{{t 'resources.worker.form.steps.2.copy_registration_request'}}</span>
<code>{{t
'resources.worker.form.steps.3.worker_auth_registration_request.label'
}}
</code>
</div>
<h3>{{t 'resources.worker.form.steps.3.title'}}</h3>
<div class='worker-create-section'>
<div class='worker-auth-token'>
<form.input
@name='worker_auth_registration_request'
@value={{this.generatedWorkerAuthToken}}
@disabled={{@model.cannotSave}}
@label={{t
'resources.worker.form.steps.3.worker_auth_registration_request.label'
}}
@helperText={{t
'resources.worker.form.steps.3.worker_auth_registration_request.help'
}}
/>
{{#if (can 'save worker' @model)}}
<Rose::Button
@submit={{true}}
@style='primary'
class='nowrap'
@disabled={{@model.cannotSave}}
>
{{t 'resources.worker.actions.register'}}
</Rose::Button>
{{/if}}
</div>
{{#if @model.cannotSave}}
<div class='worker-success'>
<div>
<Rose::Icon @name='flight-icons/svg/cpu-16' @size='medium' />
<p>{{this.generatedWorkerAuthToken}}</p>
</div>
<div>
<Rose::Icon
@name='flight-icons/svg/check-circle-fill-16'
@size='medium'
/>
<p>{{t 'resources.worker.form.steps.3.registered'}}</p>
</div>
</div>
{{/if}}
</div>
<Rose::LinkButton @route='scopes.scope.workers' @style='secondary'>
{{t 'actions.done'}}
</Rose::LinkButton>
</Rose::Form>
@@ -0,0 +1,68 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
export default class FormWorkerCreateWorkerLedComponent extends Component {
// =attributes
@tracked generatedWorkerAuthToken;
@tracked clusterId;
@tracked ipAddress;
@tracked configFilePath;
@tracked workerTags;
get createConfigText() {
return `mkdir ${this.configFilePath || '<path>'}/ ;\\
touch ${this.configFilePath || '<path>'}/pki-worker.hcl`;
}
get workerConfigText() {
return `hcp_boundary_cluster_id = "${this.clusterId || '<config_id>'}"
listener "tcp" {
address = "0.0.0.0:9202"
purpose = "proxy"
}
worker {
public_addr = "${this.ipAddress || '<public_ip_address>'}"
auth_storage_path = "${this.configFilePath || '<path>'}/worker1"
tags {
type = [${
this.workerTags
? this.workerTags
.split(',')
.filter((tag) => tag.trim())
.map((tag) => `"${tag?.trim()}"`)
.join(', ')
: '"<tag1>", "<tag2>"'
}]
}
}`;
}
get installBoundaryText() {
return `curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - ;\\
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" ;\\
sudo apt-get update && sudo apt-get install boundary ;\\
boundary server -config="${this.configFilePath || '<path>'}/pki-worker.hcl"`;
}
get shellCodeEditor() {
return {
mode: 'shell',
readOnly: true,
lineNumbers: false,
cursorBlinkRate: -1,
styleActiveLine: false,
};
}
get hclCodeEditor() {
return {
mode: 'hcl',
readOnly: true,
cursorBlinkRate: -1,
styleActiveLine: false,
};
}
}