File tree 4 files changed +22
-3
lines changed
src/main/kotlin/com/github/liff/dbexternalcommandauth
4 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 4
4
5
5
## [ Unreleased]
6
6
7
+ - Attempt to use the project directory as the working directory when running the command.
8
+
7
9
## [ 0.1.0] - 2024-03-18
8
10
9
11
- Extend compatibility to 2024.1
Original file line number Diff line number Diff line change 7
7
<!-- Plugin description -->
8
8
Use an external command to acquire database connection credentials.
9
9
10
- Executes an external command and extracts database and username from its output.
10
+ Executes an external command and extracts database and username from its output. The command is executed in the
11
+ project’s root directory, if that can be resolved.
11
12
12
13
The plugin will first attempt to extract the information from output from a [ Vault] ( https://www.vaultproject.io/ ) -like JSON with the following format:
13
14
Original file line number Diff line number Diff line change @@ -4,13 +4,20 @@ import com.intellij.credentialStore.Credentials
4
4
import com.intellij.util.io.awaitExit
5
5
import kotlinx.coroutines.Dispatchers
6
6
import kotlinx.coroutines.withContext
7
+ import java.io.File
7
8
8
9
suspend fun acquire (
9
10
command : String ,
11
+ directory : File ? ,
10
12
parse : (String ) -> Credentials ? = ::parse,
11
13
): Credentials ? =
12
14
withContext(Dispatchers .IO ) {
13
- val proc = wrap(command).start()
15
+ val proc = wrap(command)
16
+ .apply {
17
+ if (directory != null )
18
+ directory(directory)
19
+ }
20
+ .start()
14
21
15
22
proc.outputStream.close()
16
23
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import com.intellij.database.dataSource.DatabaseCredentialsAuthProvider.Companio
9
9
import com.intellij.database.dataSource.ui.AuthWidgetBuilder
10
10
import com.intellij.database.view.DatabaseCoreUiService
11
11
import com.intellij.openapi.project.Project
12
+ import com.intellij.openapi.project.guessProjectDir
12
13
13
14
class CommandAuthProvider : DatabaseAuthProvider {
14
15
override suspend fun interceptConnection (
@@ -19,7 +20,15 @@ class CommandAuthProvider : DatabaseAuthProvider {
19
20
proto.connectionPoint.getAdditionalProperty(" command" )
20
21
? : error(MyBundle .message(" no-command" ))
21
22
22
- val credentials = acquire(command)
23
+ val directory = proto.project.guessProjectDir()?.let {
24
+ try {
25
+ it.toNioPath().toFile()
26
+ } catch (_: UnsupportedOperationException ) {
27
+ null
28
+ }
29
+ }
30
+
31
+ val credentials = acquire(command = command, directory = directory)
23
32
24
33
applyCredentials(
25
34
proto = proto,
You can’t perform that action at this time.
0 commit comments