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-03-31 20:40:48 +00:00
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 ) {
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 > = > {
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
2021-04-03 17:26:43 +00:00
label = $ { t ` Name ` }
2021-03-31 20:40:48 +00:00
? 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" >
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" >
< input type = "text" value = "${ifDefined(this.sc?.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
? 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
} ) ;
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
? 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
} ) ;
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 > ` ;
}
}