Skip to content

Commit

Permalink
feat(endpoint): drop id specific check for secret keys in all endpoints
Browse files Browse the repository at this point in the history
the original design made the secrets unable to be reused, a bit to opinionated
to be useful eleswhere. This relaxes that requirement so that secrets can be
referenced here.
  • Loading branch information
jsteenb2 committed Dec 17, 2019
1 parent 2fb1a5d commit 9b1526b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 41 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

### Features

1. [16234](https://github.com/influxdata/influxdb/pull/16234): add support for notification endpoints to influx templates/pkgs.
1. [16234](https://github.com/influxdata/influxdb/pull/16234): add support for notification endpoints to influx templates/pkgs.
2. [16242](https://github.com/influxdata/influxdb/pull/16242): drop id prefix for secret key requirement for notification endpoints

### Bug Fixes
1. [16225](https://github.com/influxdata/influxdb/pull/16225): Ensures env vars are applied consistently across cmd, and fixes issue where INFLUX_ env var prefix was not set globally.
Expand Down
28 changes: 2 additions & 26 deletions notification/endpoint/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ func TestValidEndpoint(t *testing.T) {
},
},
{
name: "empty slack url and token",
name: "empty slack url",
src: &endpoint.Slack{
Base: goodBase,
},
err: &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "slack endpoint URL and token are empty",
Msg: "slack endpoint URL must be provided",
},
},
{
Expand All @@ -99,30 +99,6 @@ func TestValidEndpoint(t *testing.T) {
},
err: nil,
},
{
name: "invalid slack token",
src: &endpoint.Slack{
Base: goodBase,
URL: "localhost",
Token: influxdb.SecretField{Key: "bad-key"},
},
err: &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "slack endpoint token is invalid",
},
},
{
name: "invalid routine key",
src: &endpoint.PagerDuty{
Base: goodBase,
ClientURL: "localhost",
RoutingKey: influxdb.SecretField{Key: "bad-key"},
},
err: &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "pagerduty routing key is invalid",
},
},
{
name: "empty http http method",
src: &endpoint.HTTP{
Expand Down
6 changes: 2 additions & 4 deletions notification/endpoint/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,13 @@ func (s HTTP) Valid() error {
Msg: "invalid http auth method",
}
}
if s.AuthMethod == "basic" &&
(s.Username.Key != s.ID.String()+httpUsernameSuffix ||
s.Password.Key != s.ID.String()+httpPasswordSuffix) {
if s.AuthMethod == "basic" && (s.Username.Key == "" || s.Password.Key == "") {
return &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "invalid http username/password for basic auth",
}
}
if s.AuthMethod == "bearer" && s.Token.Key != s.ID.String()+httpTokenSuffix {
if s.AuthMethod == "bearer" && s.Token.Key == "" {
return &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "invalid http token for bearer auth",
Expand Down
2 changes: 1 addition & 1 deletion notification/endpoint/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s PagerDuty) Valid() error {
if err := s.Base.valid(); err != nil {
return err
}
if s.RoutingKey.Key != s.ID.String()+routingKeySuffix {
if s.RoutingKey.Key == "" {
return &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "pagerduty routing key is invalid",
Expand Down
11 changes: 2 additions & 9 deletions notification/endpoint/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func (s Slack) Valid() error {
if err := s.Base.valid(); err != nil {
return err
}
if s.URL == "" && s.Token.Key == "" {
if s.URL == "" {
return &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "slack endpoint URL and token are empty",
Msg: "slack endpoint URL must be provided",
}
}
if s.URL != "" {
Expand All @@ -59,13 +59,6 @@ func (s Slack) Valid() error {
}
}
}
// TODO(desa): this requirement seems odd
if s.Token.Key != "" && s.Token.Key != s.ID.String()+slackTokenSuffix {
return &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "slack endpoint token is invalid",
}
}
return nil
}

Expand Down

0 comments on commit 9b1526b

Please sign in to comment.