Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Ntfy_archive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Ntfy_archive
Commits
b89c18e8
Commit
b89c18e8
authored
3 years ago
by
lrabane
Browse files
Options
Downloads
Patches
Plain Diff
Add support for auth in client config
parent
f4f5edb2
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
client/client.yml
+4
-0
4 additions, 0 deletions
client/client.yml
client/config.go
+5
-3
5 additions, 3 deletions
client/config.go
client/config_test.go
+6
-2
6 additions, 2 deletions
client/config_test.go
cmd/subscribe.go
+3
-0
3 additions, 0 deletions
cmd/subscribe.go
with
18 additions
and
5 deletions
client/client.yml
+
4
−
0
View file @
b89c18e8
...
...
@@ -16,6 +16,10 @@
# command: 'echo "$message"'
# if:
# priority: high,urgent
# - topic: secret
# command: 'notify-send "$m"'
# user: phill
# password: mypass
#
# Variables:
# Variable Aliases Description
...
...
This diff is collapsed.
Click to expand it.
client/config.go
+
5
−
3
View file @
b89c18e8
...
...
@@ -14,9 +14,11 @@ const (
type
Config
struct
{
DefaultHost
string
`yaml:"default-host"`
Subscribe
[]
struct
{
Topic
string
`yaml:"topic"`
Command
string
`yaml:"command"`
If
map
[
string
]
string
`yaml:"if"`
Topic
string
`yaml:"topic"`
User
string
`yaml:"user"`
Password
string
`yaml:"password"`
Command
string
`yaml:"command"`
If
map
[
string
]
string
`yaml:"if"`
}
`yaml:"subscribe"`
}
...
...
This diff is collapsed.
Click to expand it.
client/config_test.go
+
6
−
2
View file @
b89c18e8
...
...
@@ -13,7 +13,9 @@ func TestConfig_Load(t *testing.T) {
require
.
Nil
(
t
,
os
.
WriteFile
(
filename
,
[]
byte
(
`
default-host: http://localhost
subscribe:
- topic: no-command
- topic: no-command-with-auth
user: phil
password: mypass
- topic: echo-this
command: 'echo "Message received: $message"'
- topic: alerts
...
...
@@ -26,8 +28,10 @@ subscribe:
require
.
Nil
(
t
,
err
)
require
.
Equal
(
t
,
"http://localhost"
,
conf
.
DefaultHost
)
require
.
Equal
(
t
,
3
,
len
(
conf
.
Subscribe
))
require
.
Equal
(
t
,
"no-command"
,
conf
.
Subscribe
[
0
]
.
Topic
)
require
.
Equal
(
t
,
"no-command
-with-auth
"
,
conf
.
Subscribe
[
0
]
.
Topic
)
require
.
Equal
(
t
,
""
,
conf
.
Subscribe
[
0
]
.
Command
)
require
.
Equal
(
t
,
"phil"
,
conf
.
Subscribe
[
0
]
.
User
)
require
.
Equal
(
t
,
"mypass"
,
conf
.
Subscribe
[
0
]
.
Password
)
require
.
Equal
(
t
,
"echo-this"
,
conf
.
Subscribe
[
1
]
.
Topic
)
require
.
Equal
(
t
,
`echo "Message received: $message"`
,
conf
.
Subscribe
[
1
]
.
Command
)
require
.
Equal
(
t
,
"alerts"
,
conf
.
Subscribe
[
2
]
.
Topic
)
...
...
This diff is collapsed.
Click to expand it.
cmd/subscribe.go
+
3
−
0
View file @
b89c18e8
...
...
@@ -162,6 +162,9 @@ func doSubscribe(c *cli.Context, cl *client.Client, conf *client.Config, topic,
for
filter
,
value
:=
range
s
.
If
{
topicOptions
=
append
(
topicOptions
,
client
.
WithFilter
(
filter
,
value
))
}
if
s
.
User
!=
""
&&
s
.
Password
!=
""
{
topicOptions
=
append
(
topicOptions
,
client
.
WithBasicAuth
(
s
.
User
,
s
.
Password
))
}
subscriptionID
:=
cl
.
Subscribe
(
s
.
Topic
,
topicOptions
...
)
commands
[
subscriptionID
]
=
s
.
Command
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment