Skip to content

Commit

Permalink
PR cleanup: removed testmode, removed unneeded mixins and deps
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed May 8, 2024
1 parent 7cf5ad8 commit 89f3127
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 399 deletions.
11 changes: 0 additions & 11 deletions ui/app/adapters/sentinel-policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,4 @@ export default class SentinelPolicyAdapter extends ApplicationAdapter {
urlForDeleteRecord(id) {
return '/v1/sentinel/policy/' + id;
}

testAgainstJob(sentinelPolicy, job) {
const url = '/v1/sentinel/test-policy';

return this.ajax(url, 'POST', {
data: {
Job: job.get('_newDefinitionJSON'),
Policy: sentinelPolicy.policy,
},
});
}
}
274 changes: 60 additions & 214 deletions ui/app/components/sentinel-policy-editor.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,17 @@
SPDX-License-Identifier: BUSL-1.1
~}}

{{#if this.devMode}}
{{#if selectedJobspec}}
<div class="section">
<button
class="button is-light is-compact"
type="button"
{{on "click" (perform this.testIt)}}
data-test-edit-job
>
Run Policy
</button>
<button
class="button is-light is-compact"
type="button"
{{on "click" this.exitDevMode}}
data-test-edit-job
>
Finished Developing
</button>
</div>

{{#if (eq testResult "Passed")}}
<div>
<Hds::Alert @type="inline" @color="success" @icon="info" class="related-entities notification" as |A|>
<A.Title>Policy Check Passed</A.Title>
<A.Description>
This policy check successfully passed.
</A.Description>
</Hds::Alert>
</div>
{{/if}}

{{#if (eq testResult "Failed")}}
<div>
<Hds::Alert @type="inline" @color="critical" @icon="info" class="related-entities notification" as |A|>
<A.Title>Policy Check failed</A.Title>
<A.Description>
This Policy check failed.
</A.Description>
</Hds::Alert>
</div>
{{/if}}

<div class="boxed-section">
<div class="boxed-section-head">
Job to test against
</div>
<div class="boxed-section-body is-full-bleed">
<div
class="policy-dev"
data-test-jobspec-editor
{{code-mirror
id="jobby"
screenReaderLabel="Jobspec Definition"
theme="hashi"
mode="ruby"
content=this.selectedJobspec
onUpdate=this.updateSelectedJobspec
autofocus=false
extraKeys=(hash Cmd-Enter=this.save)
}} />
</div>
</div>
{{else}}
<h2>
Select a Job Spec
</h2>

<Hds::ButtonSet class="button-group">
{{#each this.jobs as |job|}}
<Hds::Button
@text={{job.name}}
@color="primary"
@size="medium"
{{on "click" (perform this.selectJob job.name)}}
/>
{{/each}}
</Hds::ButtonSet>
<form class="acl-form" autocomplete="off" {{on "submit" this.save}}>
{{#if @policy.isNew }}
<Hds::Form::TextInput::Field
@isRequired={{true}}
data-test-policy-name-input
@value={{@policy.name}}
{{on "input" this.updatePolicyName}}
{{autofocus}}
as |F|>
<F.Label>Policy Name</F.Label>
</Hds::Form::TextInput::Field>
{{/if}}

<div class="boxed-section">
Expand All @@ -89,10 +22,9 @@
</div>
<div class="boxed-section-body is-full-bleed">
<div
class="policy-dev"
class="policy-editor"
data-test-policy-editor
{{code-mirror
id="polly"
screenReaderLabel="Policy definition"
theme="hashi"
mode="ruby"
Expand All @@ -104,141 +36,55 @@
</div>
</div>

<div class="section">
<button
class="button is-light is-compact"
type="button"
{{on "click" (perform this.testIt)}}
data-test-edit-job
>
Run Policy
</button>

<button
class="button is-light is-compact"
type="button"
{{on "click" this.exitDevMode}}
data-test-edit-job
>
Finished Developing
</button>
<div>
<label>
<span>
Description (optional)
</span>
<Input
data-test-policy-description
@value={{@policy.description}}
class="input"
/>
</label>
</div>

{{#if (eq testResult "Passed")}}
<div>
<Hds::Alert @type="inline" @color="success" @icon="info" class="related-entities notification" as |A|>
<A.Title>Policy Check Passed</A.Title>
<A.Description>
This policy check successfully passed.
</A.Description>
</Hds::Alert>
</div>
{{/if}}
<div>
<Hds::Form::Radio::Group @layout="horizontal" @name="method-demo1" {{on "change" this.updatePolicyEnforcementLevel}} as |G|>
<G.Legend>Enforcement Level</G.Legend>
<G.HelperText>See <Hds::Link::Inline @href="https://developer.hashicorp.com/nomad/tutorials/access-control/access-control-tokens#token-types">Sentinel Policy documentation</Hds::Link::Inline> for more information.</G.HelperText>
<G.Radio::Field
@id="advisory"
checked={{eq @policy.enforcementLevel "advisory"}}
data-test-token-type="client"
as |F|>
<F.Label>Advisory</F.Label>
</G.Radio::Field>
<G.Radio::Field
@id="soft-mandatory"
checked={{eq @policy.enforcementLevel "soft-mandatory"}}
data-test-token-type="soft-mandatory"
as |F|>
<F.Label>Soft Mandatory</F.Label>
</G.Radio::Field>
<G.Radio::Field
@id="hard-mandatory"
checked={{eq @policy.enforcementLevel "hard-mandatory"}}
data-test-token-type="hard-mandatory"
as |F|>
<F.Label>Hard Mandatory</F.Label>
</G.Radio::Field>
</Hds::Form::Radio::Group>
</div>

{{#if (eq testResult "Failed")}}
<div>
<Hds::Alert @type="inline" @color="critical" @icon="info" class="related-entities notification" as |A|>
<A.Title>Policy Check failed</A.Title>
<A.Description>
This Policy check failed.
</A.Description>
</Hds::Alert>
</div>
{{/if}}
{{else}}
<form class="acl-form" autocomplete="off" {{on "submit" this.save}}>
{{#if @policy.isNew }}
<Hds::Form::TextInput::Field
@isRequired={{true}}
data-test-policy-name-input
@value={{@policy.name}}
{{on "input" this.updatePolicyName}}
{{autofocus}}
as |F|>
<F.Label>Policy Name</F.Label>
</Hds::Form::TextInput::Field>
<footer>
{{#if (can "update sentinel-policy")}}
<Hds::Button
@text="Save Policy"
@type="submit"
data-test-save-policy
{{on "click" this.save}}
/>
{{/if}}

<div class="boxed-section">
<div class="boxed-section-head">
Policy Definition
<div class="pull-right" style="display: flex">
<button
class="button is-light is-compact"
type="button"
{{on "click" this.enterDevMode}}
data-test-edit-job
>
Develop with a job spec
</button>
</div>
</div>
<div class="boxed-section-body is-full-bleed">
<div
class="policy-editor"
data-test-policy-editor
{{code-mirror
screenReaderLabel="Policy definition"
theme="hashi"
mode="ruby"
content=@policy.policy
onUpdate=this.updatePolicy
autofocus=false
extraKeys=(hash Cmd-Enter=this.save)
}} />
</div>
</div>

<div>
<label>
<span>
Description (optional)
</span>
<Input
data-test-policy-description
@value={{@policy.description}}
class="input"
/>
</label>
</div>

<div>
<Hds::Form::Radio::Group @layout="horizontal" @name="method-demo1" {{on "change" this.updatePolicyEnforcementLevel}} as |G|>
<G.Legend>Enforcement Level</G.Legend>
<G.HelperText>See <Hds::Link::Inline @href="https://developer.hashicorp.com/nomad/tutorials/access-control/access-control-tokens#token-types">Sentinel Policy documentation</Hds::Link::Inline> for more information.</G.HelperText>
<G.Radio::Field
@id="advisory"
checked={{eq @policy.enforcementLevel "advisory"}}
data-test-token-type="client"
as |F|>
<F.Label>Advisory</F.Label>
</G.Radio::Field>
<G.Radio::Field
@id="soft-mandatory"
checked={{eq @policy.enforcementLevel "soft-mandatory"}}
data-test-token-type="soft-mandatory"
as |F|>
<F.Label>Soft Mandatory</F.Label>
</G.Radio::Field>
<G.Radio::Field
@id="hard-mandatory"
checked={{eq @policy.enforcementLevel "hard-mandatory"}}
data-test-token-type="hard-mandatory"
as |F|>
<F.Label>Hard Mandatory</F.Label>
</G.Radio::Field>
</Hds::Form::Radio::Group>
</div>

<footer>
{{#if (can "update sentinel-policy")}}
<Hds::Button
@text="Save Policy"
@type="submit"
data-test-save-policy
{{on "click" this.save}}
/>
{{/if}}
</footer>
</form>
{{/if}}
</footer>
</form>
Loading

0 comments on commit 89f3127

Please sign in to comment.