blueprints: internal storage (#4397)

* rework oci client

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>

* add blueprint content

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* add UI

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* make path optional

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* add validation

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* add tests

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* fix

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L
2023-01-10 22:00:34 +01:00
committed by GitHub
parent f2961cb536
commit 1ed24a5eef
10 changed files with 249 additions and 80 deletions

View File

@ -20,26 +20,27 @@ import PFToggleGroup from "@patternfly/patternfly/components/ToggleGroup/toggle-
import { BlueprintFile, BlueprintInstance, ManagedApi } from "@goauthentik/api";
enum blueprintSource {
local,
file,
oci,
internal,
}
@customElement("ak-blueprint-form")
export class BlueprintForm extends ModelForm<BlueprintInstance, string> {
@state()
source: blueprintSource = blueprintSource.local;
source: blueprintSource = blueprintSource.file;
loadInstance(pk: string): Promise<BlueprintInstance> {
return new ManagedApi(DEFAULT_CONFIG)
.managedBlueprintsRetrieve({
instanceUuid: pk,
})
.then((inst) => {
if (inst.path.startsWith("oci://")) {
this.source = blueprintSource.oci;
}
return inst;
});
async loadInstance(pk: string): Promise<BlueprintInstance> {
const inst = await new ManagedApi(DEFAULT_CONFIG).managedBlueprintsRetrieve({
instanceUuid: pk,
});
if (inst.path?.startsWith("oci://")) {
this.source = blueprintSource.oci;
}
if (inst.content !== "") {
this.source = blueprintSource.internal;
}
return inst;
}
getSuccessMessage(): string {
@ -102,12 +103,12 @@ export class BlueprintForm extends ModelForm<BlueprintInstance, string> {
<div class="pf-c-toggle-group__item">
<button
class="pf-c-toggle-group__button ${this.source ===
blueprintSource.local
blueprintSource.file
? "pf-m-selected"
: ""}"
type="button"
@click=${() => {
this.source = blueprintSource.local;
this.source = blueprintSource.file;
}}
>
<span class="pf-c-toggle-group__text">${t`Local path`}</span>
@ -128,10 +129,25 @@ export class BlueprintForm extends ModelForm<BlueprintInstance, string> {
<span class="pf-c-toggle-group__text">${t`OCI Registry`}</span>
</button>
</div>
<div class="pf-c-divider pf-m-vertical" role="separator"></div>
<div class="pf-c-toggle-group__item">
<button
class="pf-c-toggle-group__button ${this.source ===
blueprintSource.internal
? "pf-m-selected"
: ""}"
type="button"
@click=${() => {
this.source = blueprintSource.internal;
}}
>
<span class="pf-c-toggle-group__text">${t`Internal`}</span>
</button>
</div>
</div>
</div>
<div class="pf-c-card__footer">
${this.source === blueprintSource.local
${this.source === blueprintSource.file
? html`<ak-form-element-horizontal label=${t`Path`} name="path">
<ak-search-select
.fetchObjects=${async (
@ -187,6 +203,15 @@ export class BlueprintForm extends ModelForm<BlueprintInstance, string> {
</p>
</ak-form-element-horizontal>`
: html``}
${this.source === blueprintSource.internal
? html`<ak-form-element-horizontal label=${t`Blueprint`} name="content">
<ak-codemirror
mode="yaml"
.parseValue=${false}
value="${ifDefined(this.instance?.content)}"
></ak-codemirror>
</ak-form-element-horizontal>`
: html``}
</div>
</div>

View File

@ -28,6 +28,9 @@ export class CodeMirrorTextarea<T> extends AKElement {
@property()
name?: string;
@property({ type: Boolean })
parseValue = true;
editor?: EditorView;
_value?: string;
@ -67,6 +70,9 @@ export class CodeMirrorTextarea<T> extends AKElement {
}
get value(): T | string {
if (!this.parseValue) {
return this.getInnerValue();
}
try {
switch (this.mode.toLowerCase()) {
case "yaml":