-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KATC] Update config schema, including overlays (#1772)
- Loading branch information
1 parent
fe97939
commit 70b6d0b
Showing
11 changed files
with
350 additions
and
174 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,47 @@ | ||
package keyvalueconsumer | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/kolide/launcher/ee/agent/types" | ||
) | ||
|
||
type ConfigConsumer struct { | ||
updater types.Updater | ||
} | ||
|
||
func NewConfigConsumer(updater types.Updater) *ConfigConsumer { | ||
c := &ConfigConsumer{ | ||
updater: updater, | ||
} | ||
|
||
return c | ||
} | ||
|
||
func (c *ConfigConsumer) Update(data io.Reader) error { | ||
if c == nil { | ||
return errors.New("key value consumer is nil") | ||
} | ||
|
||
var kvPairs map[string]any | ||
if err := json.NewDecoder(data).Decode(&kvPairs); err != nil { | ||
return fmt.Errorf("failed to decode key-value json: %w", err) | ||
} | ||
|
||
kvStringPairs := make(map[string]string) | ||
for k, v := range kvPairs { | ||
b, err := json.Marshal(v) | ||
if err != nil { | ||
return fmt.Errorf("unable to marshal value for `%s`: %w", k, err) | ||
} | ||
kvStringPairs[k] = string(b) | ||
} | ||
|
||
// Turn the map into a slice of key, value, ... and send it to the thing storing this data | ||
_, err := c.updater.Update(kvStringPairs) | ||
|
||
return err | ||
} |
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
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.