-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins: Additive updates to services when discovery enabled
Earlier with discovery enabled, there was no protection against accidental changes to the discovery service. This change prevents the discovery service from being modified by checking it's config in the service bundle. Fixes #2058 Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
- Loading branch information
1 parent
f7747e7
commit 5261011
Showing
6 changed files
with
316 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2020 The OPA Authors. All rights reserved. | ||
// Use of this source code is governed by an Apache2 | ||
// license that can be found in the LICENSE file. | ||
|
||
// Package config implements helper functions to parse OPA's configuration. | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/open-policy-agent/opa/plugins/rest" | ||
"github.com/open-policy-agent/opa/util" | ||
) | ||
|
||
// ParseServicesConfig returns a set of named service clients. The service | ||
// clients can be specified either as an array or as a map. Some systems (e.g., | ||
// Helm) do not have proper support for configuration values nested under | ||
// arrays, so just support both here. | ||
func ParseServicesConfig(raw json.RawMessage) (map[string]rest.Client, error) { | ||
|
||
services := map[string]rest.Client{} | ||
|
||
var arr []json.RawMessage | ||
var obj map[string]json.RawMessage | ||
|
||
if err := util.Unmarshal(raw, &arr); err == nil { | ||
for _, s := range arr { | ||
client, err := rest.New(s) | ||
if err != nil { | ||
return nil, err | ||
} | ||
services[client.Service()] = client | ||
} | ||
} else if util.Unmarshal(raw, &obj) == nil { | ||
for k := range obj { | ||
client, err := rest.New(obj[k], rest.Name(k)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
services[client.Service()] = client | ||
} | ||
} else { | ||
// Return error from array decode as that is the default format. | ||
return nil, err | ||
} | ||
|
||
return services, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.