refactor-git-trust #4
6 changed files with 97 additions and 34 deletions
38
doc/dev/ADRServicesImplementationStatic.md
Normal file
38
doc/dev/ADRServicesImplementationStatic.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
# ADR: We implement domain services static
|
||||
|
||||
Domain services can be implemented either as object (and composed like done in spring / example1 ) or with extension
|
||||
function and composed static (see example2).
|
||||
|
||||
## example1
|
||||
```kotlin
|
||||
class DesktopServie(val aptApi: AptApi, val prov: Prov) {
|
||||
fun provisionIdeDesktop(onlyModules: List<String>? = null) {
|
||||
prov.task {
|
||||
if (onlyModules == null) {
|
||||
aptApi.aptInstall(OPEN_VPM)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## example2
|
||||
```kotlin
|
||||
fun Prov.provisionIdeDesktop(onlyModules: List<String>? = null) {
|
||||
if (onlyModules == null) {
|
||||
aptInstall(OPEN_VPM)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Decission
|
||||
|
||||
We use extension function and composed static.
|
||||
|
||||
## Reason
|
||||
|
||||
1. Similar to composed objects we can easily mock `aptInstall` in tests. Both solutions are equivalent.
|
||||
2. Inheritance in case of composed objects we can solve by static composition.
|
||||
3. Object composition we can solve by static composition.
|
||||
|
||||
There is no reason left to change the current implementd pattern.
|
|
@ -6,7 +6,7 @@ sequenceDiagram
|
|||
actor user
|
||||
participant app as Application
|
||||
participant ds as DesktopService
|
||||
participant gtr as GitTrustFactory
|
||||
participant gtr as KnownHost
|
||||
participant pa as CliArgumentsParser
|
||||
participant cr as DesktopConfigRepository
|
||||
participant ut as CliUtils
|
||||
|
@ -20,8 +20,8 @@ sequenceDiagram
|
|||
app ->> su: ensureSudoWithoutPassword(cmd.target.remoteTarget()?.password)
|
||||
app ->> ds: provisionDesktopCommand(cmd, config)
|
||||
activate ds
|
||||
ds ->> gtr: get("github", "gitlab")
|
||||
gtr -->> ds: GitTrust
|
||||
ds ->> gtr: values()
|
||||
gtr -->> ds: List(KnownHost)
|
||||
deactivate ds
|
||||
deactivate app
|
||||
```
|
||||
|
@ -62,6 +62,11 @@ classDiagram
|
|||
<<enum>>
|
||||
FIREFOX, VERIFY
|
||||
}
|
||||
|
||||
class KnownHost {
|
||||
hostName: String,
|
||||
hostKeys: List<HostKey>
|
||||
}
|
||||
}
|
||||
|
||||
DesktopCliCommand "1" *-- "1" DesktopType: type
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.provisionKeys
|
|||
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.currentUserCanSudoWithoutPassword
|
||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.whoami
|
||||
|
||||
|
||||
internal fun Prov.provisionDesktopCommand(cmd: DesktopCliCommand, conf: DesktopConfig) = task {
|
||||
provisionDesktop(
|
||||
cmd.type,
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package org.domaindrivenarchitecture.provs.desktop.domain
|
||||
|
||||
/**
|
||||
* A HostKey should contain space-separated: keytype, key and (optionally) a comment
|
||||
*
|
||||
* See: https://man7.org/linux/man-pages/man8/sshd.8.html#SSH_KNOWN_HOSTS_FILE_FORMAT
|
||||
*/
|
||||
typealias HostKey = String
|
||||
|
||||
open class KnownHost protected constructor(val hostName: String, val hostKeys: List<HostKey>) {
|
||||
companion object {
|
||||
val GITHUB = KnownHost(
|
||||
"github.com", listOf(
|
||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl",
|
||||
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=",
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphn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bmlzdHAyNTYAAABBBFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QlYWrOLXBpQ6KWjbjTDTdDkoohFzgbEY=",
|
||||
)
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
protected val values = listOf(KnownHost.GITHUB, KnownHost.GITLAB)
|
||||
|
||||
fun values(): List<KnownHost> {
|
||||
return values
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun valueOf(value: String): KnownHost = valueOf(value, KnownHost.values)
|
||||
|
||||
@JvmStatic
|
||||
protected fun valueOf(value: String, valueList: List<KnownHost>): KnownHost {
|
||||
for (type in valueList) {
|
||||
if (value.uppercase().equals(type.hostName)) {
|
||||
return type
|
||||
}
|
||||
}
|
||||
throw RuntimeException("No KnownHost found for value: $value")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
package org.domaindrivenarchitecture.provs.desktop.domain
|
||||
|
||||
/**
|
||||
* A HostKey should contain space-separated: keytype, key and (optionally) a comment
|
||||
*
|
||||
* See: https://man7.org/linux/man-pages/man8/sshd.8.html#SSH_KNOWN_HOSTS_FILE_FORMAT
|
||||
*/
|
||||
typealias HostKey = String
|
||||
|
||||
data class KnownHost(val hostName: String, val hostKeys: List<HostKey>)
|
||||
|
||||
|
||||
val defaultKnownHosts = listOf(
|
||||
// github - https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
|
||||
KnownHost(
|
||||
"github.com", listOf(
|
||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl",
|
||||
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEmKSENjQEezOmxkZMy7opKgwFB9nkt5YRrYMjNuG5N87uRgg6CLrbo5wAdT/y6v0mKV0U2w0WZ2YB/++Tpockg=",
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=",
|
||||
)
|
||||
),
|
||||
// gitlab.com - https://docs.gitlab.com/ee/user/gitlab_com/
|
||||
KnownHost(
|
||||
"gitlab.com", listOf(
|
||||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfuCHKVTjquxvt6CM6tdG4SLp1Btn/nOeHHE5UOzRdf",
|
||||
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsj2bNKTBSpIYDEGk9KxsGh3mySTRgMtXL583qmBpzeQ+jqCMRgBqB98u3z++J1sKlXHWfM9dyhSevkMwSbhoR8XIq/U0tCNyokEi/ueaBMCvbcTHhO7FcwzY92WK4Yt0aGROY5qX2UKSeOvuP4D6TPqKF1onrSzH9bx9XUf2lEdWT/ia1NEKjunUqu1xOB/StKDHMoX4/OKyIzuS0q/T1zOATthvasJFoPrAjkohTyaDUz2LN5JoH839hViyEG82yB+MjcFV5MU3N1l1QL3cVUCh93xSaua1N85qivl+siMkPGbO5xR/En4iEY6K2XPASUEMaieWVNTRCtJ4S8H+9",
|
||||
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QlYWrOLXBpQ6KWjbjTDTdDkoohFzgbEY=",
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -15,7 +15,9 @@ fun Prov.installDevOps() = task {
|
|||
installTerraform()
|
||||
installKubectlAndTools()
|
||||
installYq()
|
||||
// TODO: the can be removed
|
||||
installAwsCredentials()
|
||||
// TODO: the can be removed
|
||||
installDevOpsFolder()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue