From ec65c7c5b4b8ce90cc277a65f079144c59fc02cf Mon Sep 17 00:00:00 2001 From: Bird Date: Fri, 30 Dec 2022 15:35:54 +0800 Subject: [PATCH 1/2] feat: trello plugin use env to set apiKey and token Signed-off-by: Bird --- docs/core-concepts/config.md | 20 +++++++++++--------- docs/core-concepts/config.zh.md | 13 +++++++++---- internal/pkg/plugin/trello/options.go | 2 ++ internal/pkg/plugin/trello/state.go | 2 +- internal/pkg/plugin/trello/trello.go | 6 +++--- internal/pkg/plugin/trello/validate.go | 2 +- internal/pkg/plugin/trello/validate_test.go | 2 ++ internal/pkg/show/config/plugins/trello.yaml | 9 ++++++--- pkg/util/trello/trello.go | 5 +---- test/e2e/yaml/e2e-trello-config.yaml | 3 +++ 10 files changed, 39 insertions(+), 25 deletions(-) diff --git a/docs/core-concepts/config.md b/docs/core-concepts/config.md index e7a25088a..6acbd2316 100644 --- a/docs/core-concepts/config.md +++ b/docs/core-concepts/config.md @@ -101,15 +101,17 @@ For example, given config: ```yaml tools: - name: trello - instanceID: default - options: - scm: - owner: IronCore864 - name: golang-demo - scmType: github - borad: - name: golang-demo-board -``` +instanceID: default +options: + board: + name: golang-demo-board + apikey: xxx + token: xxx + scm: + owner: IronCore864 + repo: golang-demo + scmType: github + ``` - `TOOL_NAME` is "trello" - `TOOL_INSTANCE_ID` is "default" diff --git a/docs/core-concepts/config.zh.md b/docs/core-concepts/config.zh.md index ca243a2fc..a0d2f256c 100644 --- a/docs/core-concepts/config.zh.md +++ b/docs/core-concepts/config.zh.md @@ -100,10 +100,15 @@ tools: - name: trello instanceID: default options: - owner: IronCore864 - repo: golang-demo - kanbanBoardName: golang-demo-board -``` + board: + name: golang-demo-board + apikey: xxx + token: xxx + scm: + owner: IronCore864 + repo: golang-demo + scmType: github + ``` - `TOOL_NAME` 是 "trello" - `TOOL_INSTANCE_ID` 是 "default" diff --git a/internal/pkg/plugin/trello/options.go b/internal/pkg/plugin/trello/options.go index 8ef7a85ca..68310de77 100644 --- a/internal/pkg/plugin/trello/options.go +++ b/internal/pkg/plugin/trello/options.go @@ -24,6 +24,8 @@ type options struct { type board struct { Name string `mapstructure:"name"` Description string `mapstructure:"description"` + APIKey string `mapstructure:"apiKey"` + Token string `mapstructure:"token"` } type boardIDInfo struct { diff --git a/internal/pkg/plugin/trello/state.go b/internal/pkg/plugin/trello/state.go index 4e7c3aaca..9b31647d5 100644 --- a/internal/pkg/plugin/trello/state.go +++ b/internal/pkg/plugin/trello/state.go @@ -16,7 +16,7 @@ func getState(rawOptions configmanager.RawOptions) (statemanager.ResourceStatus, return nil, err } - c, err := trello.NewClient() + c, err := trello.NewClient(opts.Board.APIKey, opts.Board.Token) if err != nil { return nil, err } diff --git a/internal/pkg/plugin/trello/trello.go b/internal/pkg/plugin/trello/trello.go index 98fb9f595..fe547ccd9 100644 --- a/internal/pkg/plugin/trello/trello.go +++ b/internal/pkg/plugin/trello/trello.go @@ -13,7 +13,7 @@ func createBoard(rawOptions configmanager.RawOptions) error { if err != nil { return err } - c, err := trello.NewClient() + c, err := trello.NewClient(opts.Board.APIKey, opts.Board.Token) if err != nil { return err } @@ -27,7 +27,7 @@ func deleteBoard(rawOptions configmanager.RawOptions) error { if err != nil { return err } - c, err := trello.NewClient() + c, err := trello.NewClient(opts.Board.APIKey, opts.Board.Token) if err != nil { return err } @@ -48,7 +48,7 @@ func addTrelloSecret(rawOptions configmanager.RawOptions) error { } // 2. init trello client - trelloClient, err := trello.NewClient() + trelloClient, err := trello.NewClient(opts.Board.APIKey, opts.Board.Token) if err != nil { return err } diff --git a/internal/pkg/plugin/trello/validate.go b/internal/pkg/plugin/trello/validate.go index c2b9f827a..14289545d 100644 --- a/internal/pkg/plugin/trello/validate.go +++ b/internal/pkg/plugin/trello/validate.go @@ -32,7 +32,7 @@ func setDefault(rawOptions configmanager.RawOptions) (configmanager.RawOptions, if err != nil { return nil, err } - // set board dedefault value + // set board default value var boardDefaultConfig = &board{ Name: fmt.Sprintf("%s/%s", opts.Scm.GetRepoOwner(), opts.Scm.GetRepoName()), Description: fmt.Sprintf("Description is managed by DevStream, please don't modify. %s/%s", opts.Scm.GetRepoOwner(), opts.Scm.GetRepoName()), diff --git a/internal/pkg/plugin/trello/validate_test.go b/internal/pkg/plugin/trello/validate_test.go index 77286132c..9ed2c1a5c 100644 --- a/internal/pkg/plugin/trello/validate_test.go +++ b/internal/pkg/plugin/trello/validate_test.go @@ -25,6 +25,8 @@ var _ = Describe("setDefault method", func() { Expect(data["board"]).Should(Equal(map[string]any{ "name": "test_user/test", "description": "Description is managed by DevStream, please don't modify. test_user/test", + "apiKey": "", + "token": "", })) Expect(data["scm"]).Should(Equal(map[string]any{ "owner": "test_user", diff --git a/internal/pkg/show/config/plugins/trello.yaml b/internal/pkg/show/config/plugins/trello.yaml index e2f2bdae6..6742df595 100644 --- a/internal/pkg/show/config/plugins/trello.yaml +++ b/internal/pkg/show/config/plugins/trello.yaml @@ -9,10 +9,13 @@ tools: options: # the repo's owner board: - # the Tello board name. If empty, use owner/name as the board's name. + # the Trello board name. If empty, use owner/name as the board's name. name: KANBAN_BOARD_NAME - # the Tello board description. If empty, use devstream's default description + # the Trello board description. If empty, use devstream's default description description: KANBAN_DESCRIPTION + # Trello apiKey and token, see https://docs.servicenow.com/bundle/quebec-it-asset-management/page/product/software-asset-management2/task/generate-trello-apikey-token.html for more information + apikey: [[ env TRELLO_API_KEY ]] # use environment variable "TRELLO_API_KEY" to set the value + token: [[ env TRELLO_TOKEN ]] # use environment variable "TRELLO_TOKEN" to set the value scm: name: YOUR_PROJECT_NAME owner: YOUR_REPO_OWNER @@ -21,4 +24,4 @@ tools: # project branch branch: YOUR_PROJECT_BRANCH # scm repo token - token: YOUR_REPO_TOKEN + token: [[ env GITHUB_TOKEN ]] # use environment variable "GITHUB_TOKEN" to set the value diff --git a/pkg/util/trello/trello.go b/pkg/util/trello/trello.go index 72fa04275..a37436d74 100644 --- a/pkg/util/trello/trello.go +++ b/pkg/util/trello/trello.go @@ -2,7 +2,6 @@ package trello import ( "fmt" - "os" "github.com/adlio/trello" ) @@ -16,9 +15,7 @@ type client struct { *trello.Client } -func NewClient() (TrelloAPI, error) { - apiKey := os.Getenv("TRELLO_API_KEY") - token := os.Getenv("TRELLO_TOKEN") +func NewClient(apiKey, token string) (TrelloAPI, error) { if apiKey == "" || token == "" { const helpUrl = "https://docs.servicenow.com/bundle/quebec-it-asset-management/page/product/software-asset-management2/task/generate-trello-apikey-token.html" return nil, fmt.Errorf("TRELLO_API_KEY and/or TRELLO_TOKEN are/is empty. see %s for more info", helpUrl) diff --git a/test/e2e/yaml/e2e-trello-config.yaml b/test/e2e/yaml/e2e-trello-config.yaml index 29eea7394..a2603c722 100644 --- a/test/e2e/yaml/e2e-trello-config.yaml +++ b/test/e2e/yaml/e2e-trello-config.yaml @@ -18,5 +18,8 @@ tools: org: [[ githubOrganization ]] name: [[ repoName ]] scmType: github + token: [[ env GITHUB_TOKEN ]] board: name: [[ kanbanBoardName ]] + apikey: [[ env TRELLO_API_KEY ]] + token: [[ env TRELLO_TOKEN ]] From 651c34c119bdb59d0345f2d3605985c9d882b20b Mon Sep 17 00:00:00 2001 From: Bird Date: Tue, 3 Jan 2023 15:54:07 +0800 Subject: [PATCH 2/2] chore: fix doc indentation Signed-off-by: Bird --- docs/core-concepts/config.md | 20 ++++++++++---------- docs/core-concepts/config.zh.md | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/core-concepts/config.md b/docs/core-concepts/config.md index 6acbd2316..4deec7c64 100644 --- a/docs/core-concepts/config.md +++ b/docs/core-concepts/config.md @@ -101,16 +101,16 @@ For example, given config: ```yaml tools: - name: trello -instanceID: default -options: - board: - name: golang-demo-board - apikey: xxx - token: xxx - scm: - owner: IronCore864 - repo: golang-demo - scmType: github + instanceID: default + options: + board: + name: golang-demo-board + apikey: xxx + token: xxx + scm: + owner: IronCore864 + repo: golang-demo + scmType: github ``` - `TOOL_NAME` is "trello" diff --git a/docs/core-concepts/config.zh.md b/docs/core-concepts/config.zh.md index a0d2f256c..232217718 100644 --- a/docs/core-concepts/config.zh.md +++ b/docs/core-concepts/config.zh.md @@ -108,7 +108,7 @@ tools: owner: IronCore864 repo: golang-demo scmType: github - ``` +``` - `TOOL_NAME` 是 "trello" - `TOOL_INSTANCE_ID` 是 "default"