-
Notifications
You must be signed in to change notification settings - Fork 117
feat: Added reading service account in Github action #1663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ec7933d
feat: Added reading service account in Github action
89495f5
Added command for service account
adamfilipow92 de80232
change command name
piotradamczyk5 12078b1
version up
piotradamczyk5 d8b7eb7
version up
piotradamczyk5 6e51d7d
update docs
0a06186
added tests
e967d02
fix indention
piotradamczyk5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/SaveServiceAccountCommand.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package flank.scripts.cli.firebase | ||
|
|
||
| import com.github.ajalt.clikt.core.CliktCommand | ||
| import com.github.ajalt.clikt.parameters.options.option | ||
| import com.github.ajalt.clikt.parameters.options.required | ||
| import flank.scripts.ops.firebase.saveServiceAccount | ||
|
|
||
| object SaveServiceAccountCommand : CliktCommand( | ||
| name = "save_service_account", | ||
| help = "Save given service account to flank credentials location" | ||
| ) { | ||
| private val serviceAccount: String by option("--account").required() | ||
| override fun run() { | ||
| saveServiceAccount(serviceAccount) | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
flank-scripts/src/main/kotlin/flank/scripts/ops/firebase/SaveServiceAccount.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package flank.scripts.ops.firebase | ||
|
|
||
| import flank.common.defaultCredentialPath | ||
| import flank.common.downloadFile | ||
| import java.io.File | ||
| import java.nio.file.Path | ||
|
|
||
| fun saveServiceAccount( | ||
| serviceAccount: String, | ||
| serviceAccountPath: Path = defaultCredentialPath.toAbsolutePath() | ||
| ) = when { | ||
| serviceAccount.startsWith("http", true) -> downloadFile(serviceAccount, serviceAccountPath) | ||
|
pawelpasterz marked this conversation as resolved.
|
||
| serviceAccount.endsWith(".json", true) -> saveFromFile(serviceAccount, serviceAccountPath) | ||
| else -> saveFromStr(serviceAccount, serviceAccountPath) | ||
| } | ||
|
|
||
| private fun saveFromFile( | ||
| path: String, | ||
| serviceAccountPath: Path = defaultCredentialPath.toAbsolutePath() | ||
| ) { | ||
| File(path).copyTo(serviceAccountPath.toFile(), overwrite = true) | ||
| } | ||
|
|
||
| private fun saveFromStr( | ||
| serviceAccountData: String, | ||
| serviceAccountPath: Path = defaultCredentialPath.toAbsolutePath() | ||
| ) { | ||
| serviceAccountPath.toFile().writeText(serviceAccountData) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
flank-scripts/src/test/kotlin/flank/scripts/ops/firebase/SaveServiceAccountTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package flank.scripts.ops.firebase | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import flank.scripts.FuelTestRunner | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import java.nio.file.Files | ||
|
|
||
| @RunWith(FuelTestRunner::class) | ||
| class SaveServiceAccountTest { | ||
|
|
||
| @Test | ||
| fun `Should download service account`() { | ||
| // given | ||
| val testPath = Files.createTempFile("xxx", ".json") | ||
| val testLink = "http://test.account.service" | ||
|
|
||
| // when | ||
| saveServiceAccount(testLink, testPath) | ||
|
|
||
| // then | ||
| assertThat(testPath.toFile().readText()).isEqualTo(testContent) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Should store service account`() { | ||
| // given | ||
| val testPath = Files.createTempFile("xxx", ".json") | ||
| val storeTestContent = "$testContent store" | ||
|
|
||
| // when | ||
| saveServiceAccount(storeTestContent, testPath) | ||
|
|
||
| // then | ||
| assertThat(testPath.toFile().readText()).isEqualTo(storeTestContent) | ||
| } | ||
|
|
||
| @Test | ||
| fun `Should copy service account`() { | ||
| // given | ||
| val testPath = Files.createTempFile("xxx", ".json") | ||
| val fileTestContent = "$testContent file" | ||
| val serviceAccount = Files.createTempFile("account", ".json").apply { | ||
| toFile().writeText(fileTestContent) | ||
| } | ||
|
|
||
| // when | ||
| saveServiceAccount(serviceAccount.toString(), testPath) | ||
|
|
||
| // then | ||
| println(testPath.toFile().readText()) | ||
| assertThat(testPath.toFile().readText()).isEqualTo(fileTestContent) | ||
| } | ||
| } | ||
|
|
||
| internal const val testContent = "service @ccount" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.