-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*) path file is passed by metadata
- Loading branch information
1 parent
5b69eed
commit 33a9056
Showing
46 changed files
with
565 additions
and
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package config_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Kuma DP Config Suite") | ||
} |
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,20 @@ | ||
package config | ||
|
||
import ( | ||
util_files "github.com/Kong/kuma/pkg/util/files" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func ValidateTokenPath(path string) error { | ||
if path == "" { | ||
return nil | ||
} | ||
empty, err := util_files.FileEmpty(path) | ||
if err != nil { | ||
return errors.Wrap(err, "could not read file") | ||
} | ||
if empty { | ||
return errors.Errorf("token under file %s is empty", path) | ||
} | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package config_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Kong/kuma/app/kuma-dp/pkg/config" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
var _ = Describe("ValidateTokenPath", func() { | ||
|
||
var tokenFile *os.File | ||
|
||
BeforeEach(func() { | ||
tf, err := ioutil.TempFile("", "") | ||
Expect(err).ToNot(HaveOccurred()) | ||
tokenFile = tf | ||
}) | ||
|
||
It("should pass validation for empty path", func() { | ||
// when | ||
err := config.ValidateTokenPath("") | ||
|
||
// then | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("should pass validation for empty path", func() { | ||
// given | ||
_, err := tokenFile.WriteString("sampletoken") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
// when | ||
err = config.ValidateTokenPath("") | ||
|
||
// then | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("should fail for non existing file", func() { | ||
// when | ||
err := config.ValidateTokenPath("nonexistingfile") | ||
|
||
// then | ||
Expect(err).To(MatchError("could not read file: stat nonexistingfile: no such file or directory")) | ||
}) | ||
|
||
It("should fail for empty file", func() { | ||
// when | ||
err := config.ValidateTokenPath(tokenFile.Name()) | ||
|
||
// then | ||
Expect(err).To(MatchError(fmt.Sprintf("token under file %s is empty", tokenFile.Name()))) | ||
}) | ||
}) |
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
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
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,18 @@ | ||
package xds | ||
|
||
import "github.com/envoyproxy/go-control-plane/envoy/api/v2/core" | ||
|
||
type DataplaneMetadata struct { | ||
DataplaneTokenPath string | ||
} | ||
|
||
func DataplaneMetadataFromNode(node *core.Node) *DataplaneMetadata { | ||
metadata := DataplaneMetadata{} | ||
if node.Metadata == nil { | ||
return &metadata | ||
} | ||
if field := node.Metadata.Fields["dataplaneTokenPath"]; field != nil { | ||
metadata.DataplaneTokenPath = field.GetStringValue() | ||
} | ||
return &metadata | ||
} |
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,44 @@ | ||
package xds_test | ||
|
||
import ( | ||
"github.com/Kong/kuma/pkg/core/xds" | ||
"github.com/envoyproxy/go-control-plane/envoy/api/v2/core" | ||
"github.com/gogo/protobuf/types" | ||
. "github.com/onsi/ginkgo/extensions/table" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
type testCase struct { | ||
node core.Node | ||
expected xds.DataplaneMetadata | ||
} | ||
|
||
var _ = DescribeTable("DataplaneMetadataFromNode", | ||
func(given testCase) { | ||
// when | ||
metadata := xds.DataplaneMetadataFromNode(&given.node) | ||
|
||
// then | ||
Expect(*metadata).To(Equal(given.expected)) | ||
}, | ||
Entry("should parse metadata from empty node", testCase{ | ||
node: core.Node{}, | ||
expected: xds.DataplaneMetadata{}, | ||
}), | ||
Entry("should parse metadata", testCase{ | ||
node: core.Node{ | ||
Metadata: &types.Struct{ | ||
Fields: map[string]*types.Value{ | ||
"dataplaneTokenPath": &types.Value{ | ||
Kind: &types.Value_StringValue{ | ||
StringValue: "/tmp/token", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: xds.DataplaneMetadata{ | ||
DataplaneTokenPath: "/tmp/token", | ||
}, | ||
}), | ||
) |
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,16 @@ | ||
package files | ||
|
||
import "os" | ||
|
||
func FileExists(path string) bool { | ||
_, err := os.Stat(path) | ||
return err == nil | ||
} | ||
|
||
func FileEmpty(path string) (bool, error) { | ||
file, err := os.Stat(path) | ||
if err != nil { | ||
return true, err | ||
} | ||
return file.Size() == 0, 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
Oops, something went wrong.