-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: hz.GenericObject to support any fields, not just spec & status
Added basic secret object and serviceaccount which creates a secret with nats creds
- Loading branch information
Showing
13 changed files
with
551 additions
and
119 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
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,24 @@ | ||
package secrets | ||
|
||
import "github.com/verifa/horizon/pkg/hz" | ||
|
||
var _ hz.Objecter = (*Secret)(nil) | ||
|
||
type Secret struct { | ||
hz.ObjectMeta `json:"metadata" cue:""` | ||
Data SecretData `json:"data" cue:",optional"` | ||
} | ||
|
||
func (s Secret) ObjectGroup() string { | ||
return "secrets" | ||
} | ||
|
||
func (s Secret) ObjectVersion() string { | ||
return "v1" | ||
} | ||
|
||
func (s Secret) ObjectKind() string { | ||
return "Secret" | ||
} | ||
|
||
type SecretData map[string]string |
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,55 @@ | ||
package secrets_test | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/verifa/horizon/pkg/extensions/secrets" | ||
"github.com/verifa/horizon/pkg/hz" | ||
"github.com/verifa/horizon/pkg/server" | ||
tu "github.com/verifa/horizon/pkg/testutil" | ||
) | ||
|
||
func TestSecrets(t *testing.T) { | ||
ctx := context.Background() | ||
|
||
ts := server.Test(t, ctx) | ||
|
||
ctlr, err := hz.StartController( | ||
ctx, | ||
ts.Conn, | ||
hz.WithControllerFor(secrets.Secret{}), | ||
) | ||
tu.AssertNoError(t, err) | ||
t.Cleanup(func() { | ||
_ = ctlr.Stop() | ||
}) | ||
|
||
secret := secrets.Secret{ | ||
ObjectMeta: hz.ObjectMeta{ | ||
Name: "my-secret", | ||
Account: "my-account", | ||
}, | ||
Data: secrets.SecretData{ | ||
"username": "admin", | ||
"password": "password", | ||
}, | ||
} | ||
client := hz.NewClient( | ||
ts.Conn, | ||
hz.WithClientInternal(true), | ||
hz.WithClientDefaultManager(), | ||
) | ||
err = client.Apply(ctx, hz.WithApplyObject(secret)) | ||
tu.AssertNoError(t, err) | ||
|
||
raw, err := client.Get(ctx, hz.WithGetKey(secret)) | ||
tu.AssertNoError(t, err) | ||
|
||
getSecret := secrets.Secret{} | ||
err = json.Unmarshal(raw, &getSecret) | ||
tu.AssertNoError(t, err) | ||
|
||
tu.AssertEqual(t, secret.Data, getSecret.Data) | ||
} |
Oops, something went wrong.