-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(rcm-40) improve key format (#10278)
* (rcm-40) improve key format * remove proto key * add msgpkey * migrate to msgp * fix linting issues * python lint
- Loading branch information
Showing
9 changed files
with
368 additions
and
28 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
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,46 @@ | ||
package service | ||
|
||
import ( | ||
"encoding/base32" | ||
"testing" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/proto/msgpgo" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRemoteConfigKey(t *testing.T) { | ||
tests := []struct { | ||
input string | ||
err bool | ||
output *msgpgo.RemoteConfigKey | ||
}{ | ||
{input: generateKey(t, 2, "datadoghq.com", "58d58c60b8ac337293ce2ca6b28b19eb"), output: &msgpgo.RemoteConfigKey{AppKey: "58d58c60b8ac337293ce2ca6b28b19eb", OrgID: 2, Datacenter: "datadoghq.com"}}, | ||
{input: generateKey(t, 2, "datadoghq.com", ""), err: true}, | ||
{input: generateKey(t, 2, "", "app_Key"), err: true}, | ||
{input: generateKey(t, 0, "datadoghq.com", "app_Key"), err: true}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.input, func(tt *testing.T) { | ||
output, err := parseRemoteConfigKey(test.input) | ||
if test.err { | ||
assert.Error(tt, err) | ||
} else { | ||
assert.Equal(tt, test.output, output) | ||
assert.NoError(tt, err) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func generateKey(t *testing.T, orgID int64, datacenter string, appKey string) string { | ||
key := msgpgo.RemoteConfigKey{ | ||
AppKey: appKey, | ||
OrgID: orgID, | ||
Datacenter: datacenter, | ||
} | ||
rawKey, err := key.MarshalMsg(nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
return base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(rawKey) | ||
} |
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,8 @@ | ||
package msgpgo | ||
|
||
// RemoteConfigKey is a RemoteConfigKey | ||
type RemoteConfigKey struct { | ||
AppKey string `msgpack:"key"` | ||
OrgID int64 `msgpack:"org"` | ||
Datacenter string `msgpack:"dc"` | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.