0
0
mirror of https://github.com/thegeeklab/wp-matrix.git synced 2024-11-21 14:20:41 +00:00

Use secrets that can be overridden

This commit is contained in:
Paul Tötterman 2017-11-26 18:04:56 +02:00
parent cb1c390141
commit f69a402322
2 changed files with 31 additions and 15 deletions

View File

@ -7,17 +7,13 @@ Usage:
```yaml ```yaml
matrix: matrix:
image: ptman/drone-plugin-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 roomid: '!0123456789abcdef:matrix.org' # room has to already be joined
username: ourbot # either username secrets:
password: *account-password* # and password - matrix_username # either username ('ourbot')
userid: @ourbot:matrix.org # or userid - matrix_password # and password ('*ourbot-password*')
accesstoken: 0123456789abcdef # and accesstoken # - matrix_userid # or userid ('@ourbot:matrix.org')
secrets: # and a better idea # - matrix_accesstoken # and access token ('long string of characters')
- 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
``` ```
## License ## License

30
main.go
View File

@ -11,13 +11,33 @@ import (
) )
func main() { 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") homeServer := os.Getenv("PLUGIN_HOMESERVER")
userName := os.Getenv("PLUGIN_USERNAME") if homeServer == "" {
password := os.Getenv("PLUGIN_PASSWORD") homeServer = "https://matrix.org"
}
userID := os.Getenv("PLUGIN_USERID")
accessToken := os.Getenv("PLUGIN_ACCESSTOKEN")
// TODO: resolve room aliases
roomID := os.Getenv("PLUGIN_ROOMID") roomID := os.Getenv("PLUGIN_ROOMID")
message := os.Getenv("PLUGIN_MESSAGE") message := os.Getenv("PLUGIN_MESSAGE")