From f69a402322ea5d3661f5c8e3f84cc82350d8dfd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20T=C3=B6tterman?= Date: Sun, 26 Nov 2017 18:04:56 +0200 Subject: [PATCH] Use secrets that can be overridden --- README.md | 16 ++++++---------- main.go | 30 +++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5794912..63f0c2d 100644 --- a/README.md +++ b/README.md @@ -7,17 +7,13 @@ Usage: ```yaml matrix: image: ptman/drone-plugin-matrix - homeserver: https://matrix.org + homeserver: https://matrix.org # defaults to https://matrix.org roomid: '!0123456789abcdef:matrix.org' # room has to already be joined - username: ourbot # either username - password: *account-password* # and password - userid: @ourbot:matrix.org # or userid - accesstoken: 0123456789abcdef # and accesstoken - secrets: # and a better idea - - source: matrix_username # is to not store - target: plugin_username # credentials in the git repo - - source: matrix_password # but instead use drone - target: plugin_password # secret management + secrets: + - matrix_username # either username ('ourbot') + - matrix_password # and password ('*ourbot-password*') + # - matrix_userid # or userid ('@ourbot:matrix.org') + # - matrix_accesstoken # and access token ('long string of characters') ``` ## License diff --git a/main.go b/main.go index c5b29c7..4fbce1c 100644 --- a/main.go +++ b/main.go @@ -11,13 +11,33 @@ import ( ) func main() { + // Secrets + password := os.Getenv("MATRIX_PASSWORD") + accessToken := os.Getenv("MATRIX_ACCESSTOKEN") + // Not sure if these are secrets or nice to have close to them + userName := os.Getenv("MATRIX_USERNAME") + userID := os.Getenv("MATRIX_USERID") + + // Override secrets if present + if pw := os.Getenv("PLUGIN_PASSWORD"); pw != "" { + password = pw + } + if at := os.Getenv("PLUGIN_ACCESSTOKEN"); at != "" { + accessToken = at + } + if un := os.Getenv("PLUGIN_USERNAME"); un != "" { + userName = un + } + if ui := os.Getenv("PLUGIN_USERID"); ui != "" { + userID = ui + } + homeServer := os.Getenv("PLUGIN_HOMESERVER") - userName := os.Getenv("PLUGIN_USERNAME") - password := os.Getenv("PLUGIN_PASSWORD") - - userID := os.Getenv("PLUGIN_USERID") - accessToken := os.Getenv("PLUGIN_ACCESSTOKEN") + if homeServer == "" { + homeServer = "https://matrix.org" + } + // TODO: resolve room aliases roomID := os.Getenv("PLUGIN_ROOMID") message := os.Getenv("PLUGIN_MESSAGE")