From ec7933dad13272a02ba8fe69c7fb5e672cc11689 Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Fri, 5 Mar 2021 18:02:40 +0100 Subject: [PATCH 1/8] feat: Added reading service account in Github action --- action.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/action.yml b/action.yml index 1e2705e55d..c3bca9e1cc 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,9 @@ inputs: version: description: 'Flank version to run' required: false + service_account: + description: 'Service account for authentication. It could be file content or file itself.' + required: true runs: using: "composite" steps: @@ -17,3 +20,7 @@ runs: run: | ./flankScripts github download_flank --version=${{ inputs.version }} shell: bash + - id: authentication + run: | + ./flankScripts --service_account=${{ inputs.service_account }} + shell: bash From 89495f572c49c6a3b1aacc411cfc386340462f30 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 5 Mar 2021 19:25:27 +0100 Subject: [PATCH 2/8] Added command for service account --- common/src/main/kotlin/flank/common/Files.kt | 4 ++++ flank-scripts/build.gradle.kts | 2 +- .../scripts/cli/firebase/FirebaseCommand.kt | 3 ++- .../cli/firebase/SaveServiceAccountCommand.kt | 16 +++++++++++++++ .../ops/firebase/SaveServiceAccount.kt | 20 +++++++++++++++++++ .../src/main/kotlin/ftl/args/ArgsHelper.kt | 2 +- .../kotlin/ftl/args/ValidateCommonArgs.kt | 2 +- .../src/main/kotlin/ftl/config/Credentials.kt | 8 +------- .../kotlin/ftl/args/FetchProjectIdTest.kt | 4 ++-- 9 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/SaveServiceAccountCommand.kt create mode 100644 flank-scripts/src/main/kotlin/flank/scripts/ops/firebase/SaveServiceAccount.kt diff --git a/common/src/main/kotlin/flank/common/Files.kt b/common/src/main/kotlin/flank/common/Files.kt index 245be9e610..94b404b46e 100644 --- a/common/src/main/kotlin/flank/common/Files.kt +++ b/common/src/main/kotlin/flank/common/Files.kt @@ -9,6 +9,10 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths +val defaultCredentialPath: Path by lazy { + Paths.get(userHome, ".config/gcloud/application_default_credentials.json") +} + val userHome: String by lazy { if (isWindows) System.getenv("HOMEPATH") else System.getProperty("user.home") } diff --git a/flank-scripts/build.gradle.kts b/flank-scripts/build.gradle.kts index 8a3ab19d9f..752f198ebb 100644 --- a/flank-scripts/build.gradle.kts +++ b/flank-scripts/build.gradle.kts @@ -26,7 +26,7 @@ shadowJar.apply { } } // .. -version = "1.8.0" +version = "1.8.1" group = "com.github.flank" application { diff --git a/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/FirebaseCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/FirebaseCommand.kt index 6faf3a325d..d87a9c18b9 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/FirebaseCommand.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/FirebaseCommand.kt @@ -11,7 +11,8 @@ object FirebaseCommand : CliktCommand( subcommands( UpdateApiCommand, GenerateClientCommand, - CheckForSdkUpdatesCommand + CheckForSdkUpdatesCommand, + SaveServiceAccountCommand ) } diff --git a/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/SaveServiceAccountCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/SaveServiceAccountCommand.kt new file mode 100644 index 0000000000..becb9d06d4 --- /dev/null +++ b/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/SaveServiceAccountCommand.kt @@ -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 = "" +) { + private val serviceAccount: String by option("--account").required() + override fun run() { + saveServiceAccount(serviceAccount) + } +} diff --git a/flank-scripts/src/main/kotlin/flank/scripts/ops/firebase/SaveServiceAccount.kt b/flank-scripts/src/main/kotlin/flank/scripts/ops/firebase/SaveServiceAccount.kt new file mode 100644 index 0000000000..93a4f180f0 --- /dev/null +++ b/flank-scripts/src/main/kotlin/flank/scripts/ops/firebase/SaveServiceAccount.kt @@ -0,0 +1,20 @@ +package flank.scripts.ops.firebase + +import flank.common.defaultCredentialPath +import flank.common.downloadFile +import java.io.File + +fun saveServiceAccount(serviceAccount: String) = + when { + serviceAccount.startsWith("http", true) -> downloadFile(serviceAccount, defaultCredentialPath.toAbsolutePath()) + serviceAccount.endsWith(".json", true) -> saveFromFile(serviceAccount) + else -> saveFromStr(serviceAccount) + } + +private fun saveFromFile(path: String) { + File(path).copyTo(defaultCredentialPath.toFile(), overwrite = true) +} + +private fun saveFromStr(serviceAccountData: String) { + defaultCredentialPath.toFile().writeText(serviceAccountData) +} diff --git a/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt b/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt index 99fb06038e..eb6d5c8020 100644 --- a/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt +++ b/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt @@ -9,6 +9,7 @@ import com.google.cloud.storage.BucketInfo import com.google.cloud.storage.Storage import com.google.cloud.storage.StorageClass import com.google.cloud.storage.StorageOptions +import flank.common.defaultCredentialPath import flank.common.isWindows import flank.common.logLn import ftl.args.IArgs.Companion.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE @@ -17,7 +18,6 @@ import ftl.config.FtlConstants.GCS_PREFIX import ftl.config.FtlConstants.JSON_FACTORY import ftl.config.FtlConstants.useMock import ftl.config.credential -import ftl.config.defaultCredentialPath import ftl.gc.GcStorage import ftl.gc.GcToolResults import ftl.reports.xml.model.JUnitTestResult diff --git a/test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt b/test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt index 45f67721f1..8ca1fead7e 100644 --- a/test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt @@ -1,9 +1,9 @@ package ftl.args +import flank.common.defaultCredentialPath import flank.common.logLn import ftl.config.Device import ftl.config.FtlConstants -import ftl.config.defaultCredentialPath import ftl.gc.GcStorage import ftl.reports.FullJUnitReport import ftl.reports.JUnitReport diff --git a/test_runner/src/main/kotlin/ftl/config/Credentials.kt b/test_runner/src/main/kotlin/ftl/config/Credentials.kt index 268c00990e..f4f299cc44 100644 --- a/test_runner/src/main/kotlin/ftl/config/Credentials.kt +++ b/test_runner/src/main/kotlin/ftl/config/Credentials.kt @@ -5,20 +5,14 @@ import com.google.api.client.http.HttpRequestInitializer import com.google.auth.oauth2.AccessToken import com.google.auth.oauth2.GoogleCredentials import com.google.auth.oauth2.ServiceAccountCredentials +import flank.common.defaultCredentialPath import flank.common.isWindows -import flank.common.userHome import ftl.gc.UserAuth import ftl.http.HttpTimeoutIncrease import ftl.run.exception.FlankGeneralError import java.io.IOException -import java.nio.file.Path -import java.nio.file.Paths import java.util.Date -val defaultCredentialPath: Path by lazy { - Paths.get(userHome, ".config/gcloud/application_default_credentials.json") -} - val credential: GoogleCredentials by lazy { when { FtlConstants.useMock -> GoogleCredentials.create(AccessToken("mock", Date())) diff --git a/test_runner/src/test/kotlin/ftl/args/FetchProjectIdTest.kt b/test_runner/src/test/kotlin/ftl/args/FetchProjectIdTest.kt index 10e9aa7008..0815e9e989 100644 --- a/test_runner/src/test/kotlin/ftl/args/FetchProjectIdTest.kt +++ b/test_runner/src/test/kotlin/ftl/args/FetchProjectIdTest.kt @@ -2,8 +2,8 @@ package ftl.args import com.google.cloud.ServiceOptions import com.google.common.truth.Truth.assertThat +import flank.common.defaultCredentialPath import ftl.config.FtlConstants -import ftl.config.defaultCredentialPath import ftl.util.getGACPathOrEmpty import io.mockk.every import io.mockk.mockkStatic @@ -63,7 +63,7 @@ class FetchProjectIdTest { fun `should fetch project id from default credentials`() { mockkStatic( "ftl.util.Utils", - "ftl.config.CredentialsKt", + "flank.common.FilesKt", ServiceOptions::class.qualifiedName ?: "" ) { every { defaultCredentialPath } returns def.toPath() From de80232736423ec6ff5c03c3e34bb3608b238fd8 Mon Sep 17 00:00:00 2001 From: piotradamczyk5 <65554637+piotradamczyk5@users.noreply.github.com> Date: Mon, 8 Mar 2021 07:12:39 +0100 Subject: [PATCH 3/8] change command name --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c3bca9e1cc..d73ac8c0a3 100644 --- a/action.yml +++ b/action.yml @@ -22,5 +22,6 @@ runs: shell: bash - id: authentication run: | - ./flankScripts --service_account=${{ inputs.service_account }} + ./flankScripts firebase save_service_account + --account=${{ inputs.service_account }} shell: bash From 12078b1e5e34f6ca0744575d796098d0825911d6 Mon Sep 17 00:00:00 2001 From: piotradamczyk5 <65554637+piotradamczyk5@users.noreply.github.com> Date: Mon, 8 Mar 2021 07:13:10 +0100 Subject: [PATCH 4/8] version up --- flank-scripts/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flank-scripts/build.gradle.kts b/flank-scripts/build.gradle.kts index 752f198ebb..9456756481 100644 --- a/flank-scripts/build.gradle.kts +++ b/flank-scripts/build.gradle.kts @@ -26,7 +26,7 @@ shadowJar.apply { } } // .. -version = "1.8.1" +version = "1.9.0" group = "com.github.flank" application { From d8b7eb79413789ec8ea3daab41ca51f6783227f3 Mon Sep 17 00:00:00 2001 From: piotradamczyk5 <65554637+piotradamczyk5@users.noreply.github.com> Date: Mon, 8 Mar 2021 07:14:01 +0100 Subject: [PATCH 5/8] version up --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index d73ac8c0a3..c2b7810d7c 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,7 @@ runs: steps: - name: Download flankScripts run: | - curl -L https://github.com/Flank/flank/releases/download/flank-scripts-1.8.0/flank-scripts.jar --output flank-scripts.jar + curl -L https://github.com/Flank/flank/releases/download/flank-scripts-1.9.0/flank-scripts.jar --output flank-scripts.jar echo 'java -jar ./flank-scripts.jar "$@"' > flankScripts chmod +x flankScripts shell: bash From 6e51d7d072a1eb32021f2ffce9b17176f92ef2ed Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Mon, 8 Mar 2021 08:41:21 +0100 Subject: [PATCH 6/8] update docs --- action.yml | 3 +- docs/flank-scripts/command_overview.md | 88 +----------------------- docs/flank-scripts/ops_structure.md | 92 -------------------------- 3 files changed, 2 insertions(+), 181 deletions(-) diff --git a/action.yml b/action.yml index c2b7810d7c..aa5e314392 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,5 @@ runs: shell: bash - id: authentication run: | - ./flankScripts firebase save_service_account - --account=${{ inputs.service_account }} + ./flankScripts firebase save_service_account --account=${{ inputs.service_account }} shell: bash diff --git a/docs/flank-scripts/command_overview.md b/docs/flank-scripts/command_overview.md index 7b468cfb56..9b139934fe 100644 --- a/docs/flank-scripts/command_overview.md +++ b/docs/flank-scripts/command_overview.md @@ -31,6 +31,7 @@ ___ - `check_for_sdk_updates` - Check for new SDK features and create update tasks for it - `generate_client` - Generate Java Client based on api schema - `update_api` - Update api schema + - `save_service_account` - Save given service account to flank credentials location ___ @@ -75,93 +76,6 @@ ___ (1) - please note that there is only one command, but it may change in the future. -### Package structure for CLI - -```bash -flank-scripts/ -├── cli -│ ├── Main.kt -│ ├── assemble -│ │ ├── AssembleCommand.kt -│ │ ├── FlankCommand.kt -│ │ ├── GoCommand.kt -│ │ ├── android -│ │ │ ├── AndroidCommand.kt -│ │ │ └── AppCommand.kt -│ │ └── ios -│ │ ├── EarlGreyCommand.kt -│ │ ├── ExampleCommand.kt -│ │ ├── FlankExampleCommand.kt -│ │ ├── FtlCommand.kt -│ │ ├── GameLoopExampleCommand.kt -│ │ ├── IosCommand.kt -│ │ ├── RunFtlLocalCommand.kt -│ │ └── TestPlansExample.kt -│ ├── dependencies -│ │ ├── DependenciesCommand.kt -│ │ ├── InstallXcPrettyCommand.kt -│ │ ├── SetupIosEnvCommand.kt -│ │ ├── UniversalFrameworkCommand.kt -│ │ ├── UpdateBinariesCommand.kt -│ │ └── UpdateCommand.kt -│ ├── firebase -│ │ ├── CheckForSdkUpdatesCommand.kt -│ │ ├── FirebaseCommand.kt -│ │ ├── GenerateClientCommand.kt -│ │ └── UpdateApiCommand.kt -│ ├── github -│ │ ├── CopyIssuePropertiesCommand.kt -│ │ ├── DeleteOldTagCommand.kt -│ │ ├── DeleteReleaseCommand.kt -│ │ ├── DownloadFlankCommand.kt -│ │ ├── GitHubCommand.kt -│ │ └── MakeReleaseCommand.kt -│ ├── integrationtests -│ │ ├── IntegrationTestsCommand.kt -│ │ └── ProcessResultCommand.kt -│ ├── linter -│ │ ├── ApplyToGitHooksCommand.kt -│ │ ├── ApplyToIdeCommand.kt -│ │ └── LinterCommand.kt -│ ├── release -│ │ ├── GenerateReleaseNotesCommand.kt -│ │ ├── NextTagCommand.kt -│ │ └── ReleaseCommand.kt -│ └── testartifacts -│ ├── DownloadCommand.kt -│ ├── LinkCommand.kt -│ ├── PrepareCommand.kt -│ ├── RemoveRemoteCommand.kt -│ ├── ResolveCommand.kt -│ ├── TestArtifactsCommand.kt -│ ├── UnzipCommand.kt -│ ├── UploadCommand.kt -│ └── ZipCommand.kt -├── data -│ ├── github -│ │ ├── GitHubErrorResponse.kt -│ │ ├── GithubApi.kt -│ │ ├── commons -│ │ │ └── LastWorkflowRunDate.kt -│ │ └── objects -│ │ ├── GitHubCommit.kt -│ │ ├── GitHubCreateIssue.kt -│ │ ├── GitHubCreateIssueComment.kt -│ │ ├── GitHubRelease.kt -│ │ ├── GitHubSetAssigneesRequest.kt -│ │ ├── GitHubSetLabelsRequest.kt -│ │ ├── GitHubUpdateIssue.kt -│ │ ├── GitHubWorkflowRun.kt -│ │ └── GithubPullRequest.kt -│ └── zenhub -│ ├── ZenHubAPI.kt -│ ├── ZenHubIssue.kt -│ └── objects -│ └── ConvertToEpicRequest.kt - - -``` - ### Usage `flankScripts [] []` diff --git a/docs/flank-scripts/ops_structure.md b/docs/flank-scripts/ops_structure.md index 33f917d639..8de44f3201 100644 --- a/docs/flank-scripts/ops_structure.md +++ b/docs/flank-scripts/ops_structure.md @@ -4,95 +4,3 @@ Flank-scripts `ops` packages mostly match `cli` structure, however, for widely u called `common`. For better code organization `updatebinaries` has a separate package inside `dependencies`, as well as `jfrog` in `release` package. - -Ops package structure and file organization are presented on the tree below: - -```bash -├── ops -│ ├── assemble -│ │ ├── BuildFlank.kt -│ │ ├── BuildGo.kt -│ │ ├── android -│ │ │ ├── BuildBaseAndroidApk.kt -│ │ │ ├── BuildBaseAndroidTests.kt -│ │ │ ├── BuildCucumberSampleApk.kt -│ │ │ ├── BuildDuplicatedNamesApks.kt -│ │ │ ├── BuildMultiModulesApks.kt -│ │ │ ├── Common.kt -│ │ │ └── RunAndroidOps.kt -│ │ └── ios -│ │ ├── BuildEarlGreyExample.kt -│ │ ├── BuildExample.kt -│ │ ├── BuildFlankExampleCommand.kt -│ │ ├── BuildFtl.kt -│ │ ├── BuildGameLoopExampleCommand.kt -│ │ ├── BuildIosIPA.kt -│ │ ├── BuildIosTestArtifacts.kt -│ │ ├── BuildTestPlansExample.kt -│ │ ├── IosBuildCommand.kt -│ │ ├── RunFtlLocal.kt -│ │ └── UniversalFramework.kt -│ ├── common -│ │ ├── DownloadSoftware.kt -│ │ ├── EarlGreyExampleConsts.kt -│ │ ├── GenerateChangeLog.kt -│ │ └── ReleaseNotesWithType.kt -│ ├── dependencies -│ │ ├── InstallXcPretty.kt -│ │ ├── SetupIosEnv.kt -│ │ ├── UpdateAllDependencies.kt -│ │ └── common -│ │ ├── DependenciesResultCheck.kt -│ │ ├── DependencyExtensions.kt -│ │ ├── DependencyUpdate.kt -│ │ ├── FindOutdatedDependencies.kt -│ │ ├── GradleDependency.kt -│ │ ├── UpdateDependencies.kt -│ │ ├── UpdateGradle.kt -│ │ ├── UpdatePlugins.kt -│ │ └── UpdateVersionsInFile.kt -│ ├── firebase -│ │ ├── CheckForSDKUpdate.kt -│ │ ├── CommitList.kt -│ │ ├── GenerateJavaClient.kt -│ │ ├── SDKUpdateContext.kt -│ │ ├── UpdateApiJson.kt -│ │ └── common -│ │ └── Extensions.kt -│ ├── github -│ │ ├── CopyGitHubProperties.kt -│ │ ├── DeleteOldRelease.kt -│ │ ├── DeleteOldTag.kt -│ │ ├── DownloadFlank.kt -│ │ └── ReleaseFlank.kt -│ ├── integrationtests -│ │ ├── ProcessIntegrationTestsResult.kt -│ │ └── common -│ │ ├── ITResult.kt -│ │ ├── IntegrationResultContext.kt -│ │ └── PrepareMessage.kt -│ ├── linter -│ │ ├── ApplyKtlintToIdea.kt -│ │ └── LinkGitHooks.kt -│ ├── release -│ │ ├── CreateReleaseNotes.kt -│ │ └── NextReleaseTag.kt -│ ├── testartifacts -│ │ ├── ArtifactsArchive.kt -│ │ ├── Context.kt -│ │ ├── DownloadFixtures.kt -│ │ ├── Helpers.kt -│ │ ├── LinkArtifacts.kt -│ │ ├── PrepareTestArtifacts.kt -│ │ ├── RemoveRemoteCopy.kt -│ │ ├── ResolveArtifacts.kt -│ │ ├── UploadFixtures.kt -│ │ └── ZipArtifacts.kt -│ └── updatebinaries -│ ├── UpdateAtomic.kt -│ ├── UpdateBinaries.kt -│ ├── UpdateLlvm.kt -│ └── UpdateSwift.kt - - -``` From 0a061869b42d55dcd7f3e378bdd9952f43d14c65 Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Mon, 8 Mar 2021 09:56:03 +0100 Subject: [PATCH 7/8] added tests --- .../cli/firebase/SaveServiceAccountCommand.kt | 2 +- .../ops/firebase/SaveServiceAccount.kt | 29 ++++++---- .../kotlin/flank/scripts/FuelMockServer.kt | 2 + .../ops/firebase/SaveServiceAccountTest.kt | 56 +++++++++++++++++++ 4 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 flank-scripts/src/test/kotlin/flank/scripts/ops/firebase/SaveServiceAccountTest.kt diff --git a/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/SaveServiceAccountCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/SaveServiceAccountCommand.kt index becb9d06d4..a906f31cc2 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/SaveServiceAccountCommand.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/cli/firebase/SaveServiceAccountCommand.kt @@ -7,7 +7,7 @@ import flank.scripts.ops.firebase.saveServiceAccount object SaveServiceAccountCommand : CliktCommand( name = "save_service_account", - help = "" + help = "Save given service account to flank credentials location" ) { private val serviceAccount: String by option("--account").required() override fun run() { diff --git a/flank-scripts/src/main/kotlin/flank/scripts/ops/firebase/SaveServiceAccount.kt b/flank-scripts/src/main/kotlin/flank/scripts/ops/firebase/SaveServiceAccount.kt index 93a4f180f0..c276fb6de0 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/ops/firebase/SaveServiceAccount.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/ops/firebase/SaveServiceAccount.kt @@ -3,18 +3,27 @@ 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) = - when { - serviceAccount.startsWith("http", true) -> downloadFile(serviceAccount, defaultCredentialPath.toAbsolutePath()) - serviceAccount.endsWith(".json", true) -> saveFromFile(serviceAccount) - else -> saveFromStr(serviceAccount) - } +fun saveServiceAccount( + serviceAccount: String, + serviceAccountPath: Path = defaultCredentialPath.toAbsolutePath() +) = when { + serviceAccount.startsWith("http", true) -> downloadFile(serviceAccount, serviceAccountPath) + serviceAccount.endsWith(".json", true) -> saveFromFile(serviceAccount, serviceAccountPath) + else -> saveFromStr(serviceAccount, serviceAccountPath) +} -private fun saveFromFile(path: String) { - File(path).copyTo(defaultCredentialPath.toFile(), overwrite = true) +private fun saveFromFile( + path: String, + serviceAccountPath: Path = defaultCredentialPath.toAbsolutePath() +) { + File(path).copyTo(serviceAccountPath.toFile(), overwrite = true) } -private fun saveFromStr(serviceAccountData: String) { - defaultCredentialPath.toFile().writeText(serviceAccountData) +private fun saveFromStr( + serviceAccountData: String, + serviceAccountPath: Path = defaultCredentialPath.toAbsolutePath() +) { + serviceAccountPath.toFile().writeText(serviceAccountData) } diff --git a/flank-scripts/src/test/kotlin/flank/scripts/FuelMockServer.kt b/flank-scripts/src/test/kotlin/flank/scripts/FuelMockServer.kt index 3940c0bf5f..a8786e032e 100644 --- a/flank-scripts/src/test/kotlin/flank/scripts/FuelMockServer.kt +++ b/flank-scripts/src/test/kotlin/flank/scripts/FuelMockServer.kt @@ -5,6 +5,7 @@ import com.github.kittinunf.fuel.core.Request import com.github.kittinunf.fuel.core.Response import com.github.kittinunf.fuel.core.requests.DefaultBody import flank.scripts.data.zenhub.ZENHUB_BASE_URL +import flank.scripts.ops.firebase.testContent class FuelMockServer : Client { override fun executeRequest(request: Request): Response { @@ -12,6 +13,7 @@ class FuelMockServer : Client { return when { url.startsWith("https://api.github.com/repos/flank/flank/", ignoreCase = true) -> handleGithubMockRequest(url, request) url.startsWith(ZENHUB_BASE_URL) -> handleZenhubMockRequest(url, request) + url == "http://test.account.service" -> request.buildResponse(testContent, 200) else -> Response(request.url) } } diff --git a/flank-scripts/src/test/kotlin/flank/scripts/ops/firebase/SaveServiceAccountTest.kt b/flank-scripts/src/test/kotlin/flank/scripts/ops/firebase/SaveServiceAccountTest.kt new file mode 100644 index 0000000000..375c2492ba --- /dev/null +++ b/flank-scripts/src/test/kotlin/flank/scripts/ops/firebase/SaveServiceAccountTest.kt @@ -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" From e967d02c800db3be8ea3627d9de381292d19091a Mon Sep 17 00:00:00 2001 From: piotradamczyk5 <65554637+piotradamczyk5@users.noreply.github.com> Date: Tue, 9 Mar 2021 08:56:54 +0100 Subject: [PATCH 8/8] fix indention --- docs/flank-scripts/command_overview.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/flank-scripts/command_overview.md b/docs/flank-scripts/command_overview.md index 9b139934fe..ba7721fa98 100644 --- a/docs/flank-scripts/command_overview.md +++ b/docs/flank-scripts/command_overview.md @@ -29,9 +29,9 @@ ___ - `firebase` - Group of commands for managing firebase integrations - `check_for_sdk_updates` - Check for new SDK features and create update tasks for it - - `generate_client` - Generate Java Client based on api schema - - `update_api` - Update api schema - - `save_service_account` - Save given service account to flank credentials location + - `generate_client` - Generate Java Client based on api schema + - `update_api` - Update api schema + - `save_service_account` - Save given service account to flank credentials location ___