Add Env support to placeholders
This commit is contained in:
parent
b151d19794
commit
72db7043a6
|
@ -0,0 +1,25 @@
|
||||||
|
package com.artemchep.keyguard.common.service.placeholder.impl
|
||||||
|
|
||||||
|
import com.artemchep.keyguard.common.io.IO
|
||||||
|
import com.artemchep.keyguard.common.io.ioEffect
|
||||||
|
import com.artemchep.keyguard.common.service.placeholder.Placeholder
|
||||||
|
|
||||||
|
class EnvironmentPlaceholder(
|
||||||
|
) : Placeholder {
|
||||||
|
private val regex = "^%(.+)%$".toRegex()
|
||||||
|
|
||||||
|
override fun get(
|
||||||
|
key: String,
|
||||||
|
): IO<String?>? = kotlin.run {
|
||||||
|
val result = regex.matchEntire(key)
|
||||||
|
if (result != null) {
|
||||||
|
ioEffect {
|
||||||
|
val variable = result.groupValues[1]
|
||||||
|
System.getenv(variable)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// unknown
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,6 +72,7 @@ import com.artemchep.keyguard.common.service.placeholder.impl.CipherPlaceholder
|
||||||
import com.artemchep.keyguard.common.service.placeholder.impl.CommentPlaceholder
|
import com.artemchep.keyguard.common.service.placeholder.impl.CommentPlaceholder
|
||||||
import com.artemchep.keyguard.common.service.placeholder.impl.CustomPlaceholder
|
import com.artemchep.keyguard.common.service.placeholder.impl.CustomPlaceholder
|
||||||
import com.artemchep.keyguard.common.service.placeholder.impl.DateTimePlaceholder
|
import com.artemchep.keyguard.common.service.placeholder.impl.DateTimePlaceholder
|
||||||
|
import com.artemchep.keyguard.common.service.placeholder.impl.EnvironmentPlaceholder
|
||||||
import com.artemchep.keyguard.common.service.placeholder.impl.TextTransformPlaceholder
|
import com.artemchep.keyguard.common.service.placeholder.impl.TextTransformPlaceholder
|
||||||
import com.artemchep.keyguard.common.service.placeholder.impl.UrlPlaceholder
|
import com.artemchep.keyguard.common.service.placeholder.impl.UrlPlaceholder
|
||||||
import com.artemchep.keyguard.common.service.placeholder.placeholderFormat
|
import com.artemchep.keyguard.common.service.placeholder.placeholderFormat
|
||||||
|
@ -474,6 +475,7 @@ fun vaultViewScreenState(
|
||||||
CustomPlaceholder(secretOrNull),
|
CustomPlaceholder(secretOrNull),
|
||||||
DateTimePlaceholder(),
|
DateTimePlaceholder(),
|
||||||
TextTransformPlaceholder(),
|
TextTransformPlaceholder(),
|
||||||
|
EnvironmentPlaceholder(),
|
||||||
)
|
)
|
||||||
val extractors = LinkInfoRegistry(linkInfoExtractors)
|
val extractors = LinkInfoRegistry(linkInfoExtractors)
|
||||||
val cipherUris = secretOrNull
|
val cipherUris = secretOrNull
|
||||||
|
|
|
@ -88,6 +88,16 @@ _Example_:
|
||||||
https://example.com?user=joe&password=Password1%21
|
https://example.com?user=joe&password=Password1%21
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Environmental variables
|
||||||
|
|
||||||
|
System environment variables are supported.
|
||||||
|
The name of the variable must be enclosed in `%` characters.
|
||||||
|
|
||||||
|
_Example_:
|
||||||
|
```
|
||||||
|
> {%HOME%}
|
||||||
|
/home/username
|
||||||
|
```
|
||||||
|
|
||||||
#### Date-time
|
#### Date-time
|
||||||
##### Local
|
##### Local
|
||||||
|
|
Loading…
Reference in New Issue