Skip to content

Commit f69a402

Browse files
committed
Use secrets that can be overridden
1 parent cb1c390 commit f69a402

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@ Usage:
77
```yaml
88
matrix:
99
image: ptman/drone-plugin-matrix
10-
homeserver: https://matrix.org
10+
homeserver: https://matrix.org # defaults to https://matrix.org
1111
roomid: '!0123456789abcdef:matrix.org' # room has to already be joined
12-
username: ourbot # either username
13-
password: *account-password* # and password
14-
userid: @ourbot:matrix.org # or userid
15-
accesstoken: 0123456789abcdef # and accesstoken
16-
secrets: # and a better idea
17-
- source: matrix_username # is to not store
18-
target: plugin_username # credentials in the git repo
19-
- source: matrix_password # but instead use drone
20-
target: plugin_password # secret management
12+
secrets:
13+
- matrix_username # either username ('ourbot')
14+
- matrix_password # and password ('*ourbot-password*')
15+
# - matrix_userid # or userid ('@ourbot:matrix.org')
16+
# - matrix_accesstoken # and access token ('long string of characters')
2117
```
2218

2319
## License

main.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,33 @@ import (
1111
)
1212

1313
func main() {
14-
homeServer := os.Getenv("PLUGIN_HOMESERVER")
15-
userName := os.Getenv("PLUGIN_USERNAME")
16-
password := os.Getenv("PLUGIN_PASSWORD")
14+
// Secrets
15+
password := os.Getenv("MATRIX_PASSWORD")
16+
accessToken := os.Getenv("MATRIX_ACCESSTOKEN")
17+
// Not sure if these are secrets or nice to have close to them
18+
userName := os.Getenv("MATRIX_USERNAME")
19+
userID := os.Getenv("MATRIX_USERID")
20+
21+
// Override secrets if present
22+
if pw := os.Getenv("PLUGIN_PASSWORD"); pw != "" {
23+
password = pw
24+
}
25+
if at := os.Getenv("PLUGIN_ACCESSTOKEN"); at != "" {
26+
accessToken = at
27+
}
28+
if un := os.Getenv("PLUGIN_USERNAME"); un != "" {
29+
userName = un
30+
}
31+
if ui := os.Getenv("PLUGIN_USERID"); ui != "" {
32+
userID = ui
33+
}
1734

18-
userID := os.Getenv("PLUGIN_USERID")
19-
accessToken := os.Getenv("PLUGIN_ACCESSTOKEN")
35+
homeServer := os.Getenv("PLUGIN_HOMESERVER")
36+
if homeServer == "" {
37+
homeServer = "https://matrix.org"
38+
}
2039

40+
// TODO: resolve room aliases
2141
roomID := os.Getenv("PLUGIN_ROOMID")
2242
message := os.Getenv("PLUGIN_MESSAGE")
2343

0 commit comments

Comments
 (0)