2021-03-31 20:40:48 +00:00
import { CryptoApi , DockerServiceConnection , OutpostsApi } from "authentik-api" ;
import { gettext } from "django" ;
import { customElement , property } from "lit-element" ;
import { html , TemplateResult } from "lit-html" ;
import { DEFAULT_CONFIG } from "../../api/Config" ;
import { Form } from "../../elements/forms/Form" ;
import { until } from "lit-html/directives/until" ;
import { ifDefined } from "lit-html/directives/if-defined" ;
import "../../elements/forms/HorizontalFormElement" ;
@customElement ( "ak-service-connection-docker-form" )
export class ServiceConnectionDockerForm extends Form < DockerServiceConnection > {
set scUUID ( value : string ) {
new OutpostsApi ( DEFAULT_CONFIG ) . outpostsServiceConnectionsDockerRead ( {
uuid : value ,
} ) . then ( sc = > {
this . sc = sc ;
} ) ;
}
@property ( { attribute : false } )
sc? : DockerServiceConnection ;
getSuccessMessage ( ) : string {
if ( this . sc ) {
return gettext ( "Successfully updated service-connection." ) ;
} else {
return gettext ( "Successfully created service-connection." ) ;
}
}
send = ( data : DockerServiceConnection ) : Promise < DockerServiceConnection > = > {
if ( this . sc ) {
return new OutpostsApi ( DEFAULT_CONFIG ) . outpostsServiceConnectionsDockerUpdate ( {
uuid : this.sc.pk || "" ,
data : data
} ) ;
} else {
return new OutpostsApi ( DEFAULT_CONFIG ) . outpostsServiceConnectionsDockerCreate ( {
data : data
} ) ;
}
} ;
renderForm ( ) : TemplateResult {
return html ` <form class="pf-c-form pf-m-horizontal">
< ak - form - element - horizontal
label = $ { gettext ( "Name" ) }
? required = $ { true }
name = "name" >
< input type = "text" value = "${ifDefined(this.sc?.name)}" class = "pf-c-form-control" required >
< / 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" >
< input type = "checkbox" class = "pf-c-check__input" ? checked = $ { this.sc ? .local | | false } >
< label class = "pf-c-check__label" >
$ { gettext ( "Local" ) }
< / label >
< / div >
< p class = "pf-c-form__helper-text" > $ { gettext ( "If enabled, use the local connection. Required Docker socket/Kubernetes Integration." ) } < / p >
< / 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
label = $ { gettext ( "Docker URL" ) }
? required = $ { true }
name = "url" >
< input type = "text" value = "${ifDefined(this.sc?.url)}" class = "pf-c-form-control" required >
< p class = "pf-c-form__helper-text" > $ { gettext ( "Can be in the format of 'unix://' when connecting to a local docker daemon, or 'https://:2376' when connecting to a remote system." ) } < / p >
< / 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
label = $ { gettext ( "TLS Verification Certificate" ) }
? required = $ { true }
name = "tlsVerification" >
< select class = "pf-c-form-control" >
< option value = "" ? selected = $ { this.sc ? .tlsVerification = = = undefined } > -- -- -- -- - < / option >
$ { until ( new CryptoApi ( DEFAULT_CONFIG ) . cryptoCertificatekeypairsList ( {
ordering : "pk"
} ) . then ( certs = > {
return certs . results . map ( cert = > {
2021-04-01 13:39:59 +00:00
return html ` <option value= ${ ifDefined ( cert . pk ) } ?selected= ${ this . sc ? . tlsVerification === cert . pk } > ${ cert . name } </option> ` ;
2021-03-31 20:40:48 +00:00
} ) ;
} ) ) }
< / select >
< p class = "pf-c-form__helper-text" > $ { gettext ( "CA which the endpoint's Certificate is verified against. Can be left empty for no validation." ) } < / p >
< / 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
label = $ { gettext ( "TLS Authentication Certificate" ) }
? required = $ { true }
name = "tlsAuthentication" >
< select class = "pf-c-form-control" >
< option value = "" ? selected = $ { this.sc ? .tlsAuthentication = = = undefined } > -- -- -- -- - < / option >
$ { until ( new CryptoApi ( DEFAULT_CONFIG ) . cryptoCertificatekeypairsList ( {
ordering : "pk"
} ) . then ( certs = > {
return certs . results . map ( cert = > {
2021-04-01 13:39:59 +00:00
return html ` <option value= ${ ifDefined ( cert . pk ) } ?selected= ${ this . sc ? . tlsAuthentication === cert . pk } > ${ cert . name } </option> ` ;
2021-03-31 20:40:48 +00:00
} ) ;
} ) ) }
< / select >
< p class = "pf-c-form__helper-text" > $ { gettext ( "Certificate/Key used for authentication. Can be left empty for no authentication." ) } < / p >
< / a k - f o r m - e l e m e n t - h o r i z o n t a l >
< / form > ` ;
}
}