From a509781a03f5fad6890a28641a55d949da55fb98 Mon Sep 17 00:00:00 2001 From: Roman Mingazeev Date: Tue, 24 Nov 2020 20:04:37 +0300 Subject: [PATCH 1/2] added check of service account id in export --- post-processor/yandex-export/post-processor.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/post-processor/yandex-export/post-processor.go b/post-processor/yandex-export/post-processor.go index 8c48da450..e10deed7c 100644 --- a/post-processor/yandex-export/post-processor.go +++ b/post-processor/yandex-export/post-processor.go @@ -21,6 +21,8 @@ import ( "github.com/hashicorp/packer/packer-plugin-sdk/template/config" "github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate" "github.com/hashicorp/packer/post-processor/artifice" + "github.com/yandex-cloud/go-genproto/yandex/cloud/iam/v1" + ycsdk "github.com/yandex-cloud/go-sdk" ) const defaultStorageEndpoint = "storage.yandexcloud.net" @@ -196,6 +198,11 @@ func (p *PostProcessor) PostProcess(ctx context.Context, ui packer.Ui, artifact return nil, false, false, err } + ui.Say(fmt.Sprintf("Validating service_account_id: '%s'...", yandexConfig.ServiceAccountID)) + if err := validateServiceAccount(ctx, driver.SDK(), yandexConfig.ServiceAccountID); err != nil { + return nil, false, false, err + } + // Set up the state. state := new(multistep.BasicStateBag) state.Put("config", &yandexConfig) @@ -259,3 +266,10 @@ func formUrls(paths []string) []string { } return result } + +func validateServiceAccount(ctx context.Context, ycsdk *ycsdk.SDK, serviceAccountID string) error { + _, err := ycsdk.IAM().ServiceAccount().Get(ctx, &iam.GetServiceAccountRequest{ + ServiceAccountId: serviceAccountID, + }) + return err +} From 677c48d294c5ab5684d53a5f138efe389f745529 Mon Sep 17 00:00:00 2001 From: Roman Mingazeev Date: Tue, 24 Nov 2020 20:07:52 +0300 Subject: [PATCH 2/2] add record to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f320c681c..60d1cd44b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ ### BUG FIXES * builder/amazon: Fix single `tag` interpolation to allow for templating engine usage. [GH-10224] +* post-processort/yandex-export: added check of service account id ## 1.6.5 (October 30, 2020)