2021-03-31 20:40:48 +00:00
import { CryptoApi , DockerServiceConnection , OutpostsApi } from "authentik-api" ;
2021-04-03 17:26:43 +00:00
import { t } from "@lingui/macro" ;
2021-05-11 10:05:30 +00:00
import { customElement } from "lit-element" ;
2021-03-31 20:40:48 +00:00
import { html , TemplateResult } from "lit-html" ;
import { DEFAULT_CONFIG } from "../../api/Config" ;
import { until } from "lit-html/directives/until" ;
import { ifDefined } from "lit-html/directives/if-defined" ;
import "../../elements/forms/HorizontalFormElement" ;
2021-04-03 22:36:53 +00:00
import { first } from "../../utils" ;
2021-05-11 10:05:30 +00:00
import { ModelForm } from "../../elements/forms/ModelForm" ;
2021-03-31 20:40:48 +00:00
@customElement ( "ak-service-connection-docker-form" )
2021-05-11 10:05:30 +00:00
export class ServiceConnectionDockerForm extends ModelForm < DockerServiceConnection , string > {
2021-03-31 20:40:48 +00:00
2021-05-11 10:05:30 +00:00
loadInstance ( pk : string ) : Promise < DockerServiceConnection > {
2021-05-16 12:43:42 +00:00
return new OutpostsApi ( DEFAULT_CONFIG ) . outpostsServiceConnectionsDockerRetrieve ( {
2021-05-11 10:05:30 +00:00
uuid : pk ,
2021-03-31 20:40:48 +00:00
} ) ;
}
getSuccessMessage ( ) : string {
2021-05-11 10:05:30 +00:00
if ( this . instance ) {
2021-04-03 17:26:43 +00:00
return t ` Successfully updated service-connection. ` ;
2021-03-31 20:40:48 +00:00
} else {
2021-04-03 17:26:43 +00:00
return t ` Successfully created service-connection. ` ;
2021-03-31 20:40:48 +00:00
}
}
send = ( data : DockerServiceConnection ) : Promise < DockerServiceConnection > = > {
2021-05-11 10:05:30 +00:00
if ( this . instance ) {
2021-03-31 20:40:48 +00:00
return new OutpostsApi ( DEFAULT_CONFIG ) . outpostsServiceConnectionsDockerUpdate ( {
2021-05-11 10:05:30 +00:00
uuid : this.instance.pk || "" ,
2021-05-16 16:24:15 +00:00
dockerServiceConnectionRequest : data
2021-03-31 20:40:48 +00:00
} ) ;
} else {
return new OutpostsApi ( DEFAULT_CONFIG ) . outpostsServiceConnectionsDockerCreate ( {
2021-05-16 16:24:15 +00:00
dockerServiceConnectionRequest : data
2021-03-31 20:40:48 +00:00
} ) ;
}
} ;
renderForm ( ) : TemplateResult {
return html ` <form class="pf-c-form pf-m-horizontal">
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` Name ` }
2021-03-31 20:40:48 +00:00
? required = $ { true }
name = "name" >
2021-05-11 10:05:30 +00:00
< input type = "text" value = "${ifDefined(this.instance?.name)}" class = "pf-c-form-control" required >
2021-03-31 20:40:48 +00:00
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
< ak - form - element - horizontal name = "local" >
< div class = "pf-c-check" >
2021-05-11 10:05:30 +00:00
< input type = "checkbox" class = "pf-c-check__input" ? checked = $ { first ( this.instance ? .local , false ) } >
2021-03-31 20:40:48 +00:00
< label class = "pf-c-check__label" >
2021-04-03 17:26:43 +00:00
$ { t ` Local ` }
2021-03-31 20:40:48 +00:00
< / label >
< / div >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` If enabled, use the local connection. Required Docker socket/Kubernetes Integration. ` } < / p >
2021-03-31 20:40:48 +00:00
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` Docker URL ` }
2021-03-31 20:40:48 +00:00
? required = $ { true }
name = "url" >
2021-05-11 10:05:30 +00:00
< input type = "text" value = "${ifDefined(this.instance?.url)}" class = "pf-c-form-control" required >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Can be in the format of 'unix://' when connecting to a local docker daemon, or 'https://:2376' when connecting to a remote system. ` } < / p >
2021-03-31 20:40:48 +00:00
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` TLS Verification Certificate ` }
2021-03-31 20:40:48 +00:00
name = "tlsVerification" >
< select class = "pf-c-form-control" >
2021-05-11 10:05:30 +00:00
< option value = "" ? selected = $ { this.instance ? .tlsVerification = = = undefined } > -- -- -- -- - < / option >
2021-03-31 20:40:48 +00:00
$ { until ( new CryptoApi ( DEFAULT_CONFIG ) . cryptoCertificatekeypairsList ( {
ordering : "pk"
} ) . then ( certs = > {
return certs . results . map ( cert = > {
2021-05-11 10:05:30 +00:00
return html ` <option value= ${ ifDefined ( cert . pk ) } ?selected= ${ this . instance ? . tlsVerification === cert . pk } > ${ cert . name } </option> ` ;
2021-03-31 20:40:48 +00:00
} ) ;
2021-04-03 22:24:06 +00:00
} ) , html ` <option> ${ t ` Loading... ` } </option> ` ) }
2021-03-31 20:40:48 +00:00
< / select >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` CA which the endpoint's Certificate is verified against. Can be left empty for no validation. ` } < / p >
2021-03-31 20:40:48 +00:00
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
< ak - form - element - horizontal
2021-04-03 17:26:43 +00:00
label = $ { t ` TLS Authentication Certificate ` }
2021-03-31 20:40:48 +00:00
name = "tlsAuthentication" >
< select class = "pf-c-form-control" >
2021-05-11 10:05:30 +00:00
< option value = "" ? selected = $ { this.instance ? .tlsAuthentication = = = undefined } > -- -- -- -- - < / option >
2021-03-31 20:40:48 +00:00
$ { until ( new CryptoApi ( DEFAULT_CONFIG ) . cryptoCertificatekeypairsList ( {
ordering : "pk"
} ) . then ( certs = > {
return certs . results . map ( cert = > {
2021-05-11 10:05:30 +00:00
return html ` <option value= ${ ifDefined ( cert . pk ) } ?selected= ${ this . instance ? . tlsAuthentication === cert . pk } > ${ cert . name } </option> ` ;
2021-03-31 20:40:48 +00:00
} ) ;
2021-04-03 22:24:06 +00:00
} ) , html ` <option> ${ t ` Loading... ` } </option> ` ) }
2021-03-31 20:40:48 +00:00
< / select >
2021-04-03 17:26:43 +00:00
< p class = "pf-c-form__helper-text" > $ { t ` Certificate/Key used for authentication. Can be left empty for no authentication. ` } < / p >
2021-03-31 20:40:48 +00:00
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
< / form > ` ;
}
}