Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions modules/firehose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ func (mc *moduleConfig) validateAndSanitize(r resource.Resource) error {
return nil
}

func generateFirehoseName(r resource.Resource) string {
return fmt.Sprintf("%s-%s-firehose", r.Project, r.Name)
}

func (mc moduleConfig) GetHelmReleaseConfig(r resource.Resource) (*helm.ReleaseConfig, error) {
func (mc *moduleConfig) GetHelmReleaseConfig(r resource.Resource) (*helm.ReleaseConfig, error) {
var output Output
err := json.Unmarshal(r.State.Output, &output)
if err != nil {
Expand Down Expand Up @@ -94,10 +90,14 @@ func (mc moduleConfig) GetHelmReleaseConfig(r resource.Resource) (*helm.ReleaseC
return rc, nil
}

func (mc moduleConfig) JSON() []byte {
func (mc *moduleConfig) JSON() []byte {
b, err := json.Marshal(mc)
if err != nil {
panic(err)
}
return b
}

func generateFirehoseName(r resource.Resource) string {
return fmt.Sprintf("%s-%s-firehose", r.Project, r.Name)
}
67 changes: 21 additions & 46 deletions modules/kubernetes/config_schema.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"host": {
"type": "string",
"format": "uri",
"pattern": "^https?://"
"format": "uri"
},
"insecure": {
"type": "boolean",
Expand All @@ -21,61 +19,38 @@
"client_certificate": {
"type": "string"
},
"cluster_ca_certificate": {
"client_ca_certificate": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In go struct this is mentioned as cluster_ca_certificate

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any specific reason we chose to rename this field?

"type": "string"
},
"timeout": {
"type": "number",
"default": 100000000
}
},
"allOf": [
"required": [
"host"
],
"anyOf": [
{
"oneOf": [
{
"required": [
"token"
]
},
{
"allOf": [
{
"required": [
"client_key"
]
},
{
"required": [
"client_certificate"
]
}
]
}
"required": [
"token"
]
},
{
"oneOf": [
{
"required": [
"cluster_ca_certificate"
]
},
{
"required": [
"client_key",
"client_certificate"
],
"if": {
"not": {
"properties": {
"insecure": {
"const": true
}
},
"required": [
"insecure"
]
}
}
]
},
{
"required": [
"host"
]
},
"then": {
"required": [
"client_ca_certificate"
]
}
}
]
}
101 changes: 54 additions & 47 deletions modules/kubernetes/config_schema_test.go
Original file line number Diff line number Diff line change
@@ -1,113 +1,120 @@
package kubernetes

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/xeipuuv/gojsonschema"
)

func TestModule_KubernetesJSONSchema(t *testing.T) {
tests := []struct {
Case string
wantErr error
want bool
title string
Case string
shouldBeValid bool
}{
{
title: "TokenAuthPresent_InsecureTrue",
Case: `{
"host": "http://0.0.0.0:1234",
"insecure": true,
"token": "token"
}`,
wantErr: nil,
want: true,
shouldBeValid: true,
},
{
title: "TokenAuthPresent_InsecureFalse",
Case: `{
"host": "http://0.0.0.0:1234",
"insecure": false,
"token": "foo"
}`,
shouldBeValid: true,
},
{
title: "TokenAuthPresent_CertIsPresentToo",
Case: `{
"host": "http://0.0.0.0:1234",
"insecure": false,
"token": "token"
"token": "token",
"cluster_certificate": "c_ca_cert"
}`,
wantErr: nil,
want: false,
shouldBeValid: true,
},
{
title: "CertAuthPresent_InsecureTrue",
Case: `{
"host": "http://0.0.0.0:1234",
"insecure": false,
"cluster_ca_certificate": "c_ca_cert",
"token": "token"
"insecure": true,
"client_key": "c_key",
"client_certificate": "c_cert"
}`,
wantErr: nil,
want: true,
shouldBeValid: true,
},
{
title: "CertAuthPresent_InsecureFalse",
Case: `{
"host": "http://0.0.0.0:1234",
"cluster_ca_certificate": "c_ca_cert",
"token": "token"
"insecure": false,
"client_key": "c_key",
"client_certificate": "c_cert"
}`,
wantErr: nil,
want: true,
shouldBeValid: false,
},

{
title: "CertAuthPresent_InsecureFalse_WithCACert",
Case: `{
"host": "http://0.0.0.0:1234",
"insecure": true,
"insecure": false,
"client_key": "c_key",
"client_certificate": "c_cert"
"client_certificate": "c_cert",
"client_ca_certificate": "ca_cert"
}`,
wantErr: nil,
want: true,
shouldBeValid: true,
},
{
Case: ` "host": "http://0.0.0.0:1234",
"insecure": true,
"client_key": "c_key"
}`,
wantErr: nil,
want: false,
title: "Missing_ClientCert",
Case: `{
"host": "http://0.0.0.0:1234",
"client_key": "c_key"
}`,
shouldBeValid: false,
},
{
title: "Missing_ClientKey",
Case: `{
"host": "http://0.0.0.0:1234",
"insecure": true,
"token": "token",
"client_key": "c_key",
"client_certificate": "c_cert"
}`,
wantErr: nil,
want: false,
shouldBeValid: false,
},
{
title: "Missing_CACert",
Case: `{
"host": "http://0.0.0.0:1234",
"insecure": true,
"token": "token",
"client_key": "c_key"
"insecure": false,
"client_key": "foo",
"client_certificate": "c_cert"
}`,
wantErr: nil,
want: true,
shouldBeValid: false,
},
}
loader := gojsonschema.NewStringLoader(configSchema)
schema, _ := gojsonschema.NewSchema(loader)

schema, err := gojsonschema.NewSchema(gojsonschema.NewStringLoader(configSchema))
require.NoError(t, err)

for _, tt := range tests {
tt := tt
t.Run(tt.Case, func(t *testing.T) {
t.Run(tt.title, func(t *testing.T) {
t.Parallel()

c := gojsonschema.NewStringLoader(tt.Case)
result, err := schema.Validate(c)
if tt.wantErr != nil {
assert.Error(t, err)
assert.True(t, errors.Is(err, tt.wantErr))
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.want, result.Valid())
require.NoError(t, err)
assert.Equal(t, tt.shouldBeValid, result.Valid())
})
}
}