2022-09-14 22:05:21 +00:00
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config" ;
import { first } from "@goauthentik/common/utils" ;
import "@goauthentik/elements/forms/HorizontalFormElement" ;
import { ModelForm } from "@goauthentik/elements/forms/ModelForm" ;
2023-01-02 13:51:44 +00:00
import "@goauthentik/elements/forms/SearchSelect" ;
2022-06-25 15:44:17 +00:00
2021-04-03 17:26:43 +00:00
import { t } from "@lingui/macro" ;
2021-09-21 09:31:37 +00:00
2021-10-28 07:48:51 +00:00
import { TemplateResult , html } from "lit" ;
2021-11-04 21:34:48 +00:00
import { customElement } from "lit/decorators.js" ;
import { ifDefined } from "lit/directives/if-defined.js" ;
2021-09-21 09:31:37 +00:00
2022-12-29 12:15:09 +00:00
import {
CertificateKeyPair ,
CryptoApi ,
CryptoCertificatekeypairsListRequest ,
DockerServiceConnection ,
OutpostsApi ,
} from "@goauthentik/api" ;
2021-09-21 09:31:37 +00:00
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 > {
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-08-03 22:18:15 +00:00
return t ` Successfully updated integration. ` ;
2021-03-31 20:40:48 +00:00
} else {
2021-08-03 22:18:15 +00:00
return t ` Successfully created integration. ` ;
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-08-03 15:52:21 +00:00
dockerServiceConnectionRequest : data ,
2021-03-31 20:40:48 +00:00
} ) ;
} else {
return new OutpostsApi ( DEFAULT_CONFIG ) . outpostsServiceConnectionsDockerCreate ( {
2021-08-03 15:52:21 +00:00
dockerServiceConnectionRequest : data ,
2021-03-31 20:40:48 +00:00
} ) ;
}
} ;
renderForm ( ) : TemplateResult {
return html ` <form class="pf-c-form pf-m-horizontal">
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Name ` } ? required = $ { true } name = "name" >
< 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" >
2023-01-11 12:37:49 +00:00
< label class = "pf-c-switch" >
2021-08-03 15:52:21 +00:00
< input
2023-01-11 12:37:49 +00:00
class = "pf-c-switch__input"
2021-08-03 15:52:21 +00:00
type = "checkbox"
? checked = $ { first ( this . instance ? . local , false ) }
/ >
2023-01-11 12:37:49 +00:00
< span class = "pf-c-switch__toggle" >
< span class = "pf-c-switch__toggle-icon" >
< i class = "fas fa-check" aria - hidden = "true" > < / i >
< / span >
< / span >
< span class = "pf-c-switch__label" > $ { t ` Local ` } < / span >
< / label >
2021-08-03 15:52:21 +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 >
2021-08-03 15:52:21 +00:00
< ak - form - element - horizontal label = $ { t ` Docker URL ` } ? required = $ { true } name = "url" >
< input
type = "text"
value = "${ifDefined(this.instance?.url)}"
class = "pf-c-form-control"
required
/ >
< p class = "pf-c-form__helper-text" >
2021-12-25 15:31:34 +00:00
$ { t ` Can be in the format of 'unix://' when connecting to a local docker daemon, using 'ssh://' to connect via SSH, or 'https://:2376' when connecting to a remote system. ` }
2021-08-03 15:52:21 +00:00
< / 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-08-03 15:52:21 +00:00
name = "tlsVerification"
>
2022-12-29 12:15:09 +00:00
< ak - search - select
. fetchObjects = $ { async ( query? : string ) : Promise < CertificateKeyPair [ ] > = > {
const args : CryptoCertificatekeypairsListRequest = {
ordering : "name" ,
hasKey : true ,
includeDetails : false ,
} ;
if ( query !== undefined ) {
args . search = query ;
}
const certificates = await new CryptoApi (
DEFAULT_CONFIG ,
) . cryptoCertificatekeypairsList ( args ) ;
return certificates . results ;
} }
. renderElement = $ { ( item : CertificateKeyPair ) : string = > {
return item . name ;
} }
. value = $ { ( item : CertificateKeyPair | undefined ) : string | undefined = > {
return item ? . pk ;
} }
. selected = $ { ( item : CertificateKeyPair ) : boolean = > {
return this . instance ? . tlsVerification === item . pk ;
} }
? blankable = $ { true }
>
< / a k - s e a r c h - s e l e c t >
2021-08-03 15:52:21 +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-12-25 15:31:34 +00:00
label = $ { t ` TLS Authentication Certificate/SSH Keypair ` }
2021-08-03 15:52:21 +00:00
name = "tlsAuthentication"
>
2022-12-29 12:15:09 +00:00
< ak - search - select
. fetchObjects = $ { async ( query? : string ) : Promise < CertificateKeyPair [ ] > = > {
const args : CryptoCertificatekeypairsListRequest = {
ordering : "name" ,
hasKey : true ,
includeDetails : false ,
} ;
if ( query !== undefined ) {
args . search = query ;
}
const certificates = await new CryptoApi (
DEFAULT_CONFIG ,
) . cryptoCertificatekeypairsList ( args ) ;
return certificates . results ;
} }
. renderElement = $ { ( item : CertificateKeyPair ) : string = > {
return item . name ;
} }
. value = $ { ( item : CertificateKeyPair | undefined ) : string | undefined = > {
return item ? . pk ;
} }
. selected = $ { ( item : CertificateKeyPair ) : boolean = > {
return this . instance ? . tlsAuthentication === item . pk ;
} }
? blankable = $ { true }
>
< / a k - s e a r c h - s e l e c t >
2021-08-03 15:52:21 +00:00
< p class = "pf-c-form__helper-text" >
$ { t ` Certificate/Key used for authentication. Can be left empty for no authentication. ` }
< / p >
2021-12-25 15:31:34 +00:00
< p class = "pf-c-form__helper-text" >
$ { t ` When connecting via SSH, this keypair is used for 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 > ` ;
}
}