Skip to content

Commit

Permalink
Fix minor style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
coufalja committed Aug 14, 2019
1 parent 02b870d commit 434a465
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 50 deletions.
2 changes: 1 addition & 1 deletion cmd/decrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var decryptCmd = &cobra.Command{
},
}

//ExecuteDecrypt runs decrypt cmd
// ExecuteDecrypt runs decrypt cmd
func ExecuteDecrypt() error {
if dp.value == "" {
bytes, err := ioutil.ReadAll(os.Stdin)
Expand Down
2 changes: 1 addition & 1 deletion cmd/decrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ func ExampleExecuteDecrypt() {
dp.source = ts.URL
dp.value = tp.testContent
ExecuteDecrypt()
//Output: test
// Output: test
}
4 changes: 2 additions & 2 deletions cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func validateDiffParams(cmd *cobra.Command, args []string) error {
return nil
}

//ExecuteDiffValues runs diff values cmd
// ExecuteDiffValues runs diff values cmd
func ExecuteDiffValues() error {
ext, err := client.ParseExtension(diffp.format)

Expand Down Expand Up @@ -96,7 +96,7 @@ func ExecuteDiffValues() error {
return difflib.WriteUnifiedDiff(os.Stdout, d)
}

//ExecuteDiffFiles runs diff files cmd
// ExecuteDiffFiles runs diff files cmd
func ExecuteDiffFiles() error {
errorHandler := func(data []byte, err error) []byte {
if e, ok := err.(client.HTTPError); ok && e.StatusCode() == http.StatusNotFound {
Expand Down
2 changes: 1 addition & 1 deletion cmd/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var encryptCmd = &cobra.Command{
},
}

//ExecuteEncrypt runs encrypt cmd
// ExecuteEncrypt runs encrypt cmd
func ExecuteEncrypt() error {
if ep.value == "" {
bytes, err := ioutil.ReadAll(os.Stdin)
Expand Down
2 changes: 1 addition & 1 deletion cmd/encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ func ExampleExecuteEncrypt() {
ep.source = ts.URL
ep.value = tp.testContent
ExecuteEncrypt()
//Output: test
// Output: test
}
14 changes: 7 additions & 7 deletions cmd/filemapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
const mappingSeparator = ","
const sourceDestSeparator = ":"

//FileMapping single file mapping source:dest
// FileMapping single file mapping source:dest
type FileMapping struct {
source string
destination string
}

//FileMappings file mappings source:dest,source:dest...
// FileMappings file mappings source:dest,source:dest...
type FileMappings struct {
mappings []FileMapping
}
Expand All @@ -23,7 +23,7 @@ func (m *FileMappings) String() string {
return ""
}

//Set parse mappings from string
// Set parse mappings from string
func (m *FileMappings) Set(value string) error {
mappings := strings.Split(value, mappingSeparator)

Expand All @@ -41,17 +41,17 @@ func (m *FileMappings) Set(value string) error {
return nil
}

//Type type name (for cobra)
// Type type name (for cobra)
func (m *FileMappings) Type() string {
return "FileMappings"
}

//Mappings all mappings
// Mappings all mappings
func (m *FileMappings) Mappings() []FileMapping {
return m.mappings
}

//Sources all sources
// Sources all sources
func (m *FileMappings) Sources() []string {
sources := make([]string, len(m.mappings))
for i, mapping := range m.mappings {
Expand All @@ -61,7 +61,7 @@ func (m *FileMappings) Sources() []string {
return sources
}

//Destinations all destinations
// Destinations all destinations
func (m *FileMappings) Destinations() []string {
destinations := make([]string, len(m.mappings))
for i, mapping := range m.mappings {
Expand Down
4 changes: 2 additions & 2 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var getFilesCmd = &cobra.Command{
},
}

//ExecuteGetValues runs get values cmd
// ExecuteGetValues runs get values cmd
func ExecuteGetValues() error {
ext, err := client.ParseExtension(gp.format)

Expand Down Expand Up @@ -75,7 +75,7 @@ func ExecuteGetValues() error {
return nil
}

//ExecuteGetFiles runs get files cmd
// ExecuteGetFiles runs get files cmd
func ExecuteGetFiles() error {
for _, mapping := range gp.fileMappings.Mappings() {
resp, err := client.
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func init() {
rootCmd.AddCommand(versionCmd)
}

//Execute run root command (main entrypoint)
// Execute run root command (main entrypoint)
func Execute() error {
return rootCmd.Execute()
}
2 changes: 1 addition & 1 deletion internal/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
)

//AssertString asserts string values and prints the expected and received values if failed
// AssertString asserts string values and prints the expected and received values if failed
func AssertString(t *testing.T, message string, expected string, got string) {
expected = trimString(expected)
got = trimString(got)
Expand Down
52 changes: 26 additions & 26 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"strings"
)

//Extension format of downloaded config
// Extension format of downloaded config
type Extension string

//ParseExtension parse string into Extension type
// ParseExtension parse string into Extension type
func ParseExtension(str string) (Extension, error) {
switch value := strings.TrimRight(str, "\n"); value {
case "json":
Expand Down Expand Up @@ -40,38 +40,38 @@ const (
unknown Extension = "_"
)

//Client Spring Cloud Config Client
// Client Spring Cloud Config Client
type Client interface {
//Config of the client
// Config of the client
Config() *Config

//FetchFile queries the remote configuration service and returns the resulting file
//it is possible to pass error handler function as second parameter
// FetchFile queries the remote configuration service and returns the resulting file
// it is possible to pass error handler function as second parameter
FetchFile(source string, errorHandler func([]byte, error) []byte) []byte

//FetchFileE queries the remote configuration service and returns the resulting file
// FetchFileE queries the remote configuration service and returns the resulting file
FetchFileE(source string) ([]byte, error)

//FetchAs queries the remote configuration service and returns the result in specified format
// FetchAs queries the remote configuration service and returns the result in specified format
FetchAs(extension Extension) (string, error)

//FetchAsJSON queries the remote configuration service and returns the result as a JSON string
// FetchAsJSON queries the remote configuration service and returns the result as a JSON string
FetchAsJSON() (string, error)

//FetchAsYAML queries the remote configuration service and returns the result as a YAML string
// FetchAsYAML queries the remote configuration service and returns the result as a YAML string
FetchAsYAML() (string, error)

//FetchAsProperties queries the remote configuration service and returns the result as a Properties string
// FetchAsProperties queries the remote configuration service and returns the result as a Properties string
FetchAsProperties() (string, error)

//Encrypt encrypts the value server side and returns result
// Encrypt encrypts the value server side and returns result
Encrypt(value string) (string, error)

//Decrypt decrypts the value server side and returns result
// Decrypt decrypts the value server side and returns result
Decrypt(value string) (string, error)
}

//Config needed to fetch a remote configuration
// Config needed to fetch a remote configuration
type Config struct {
URI string
Profile string
Expand All @@ -83,17 +83,17 @@ type client struct {
config *Config
}

//HTTPError used for wrapping an exception returned from Client
// HTTPError used for wrapping an exception returned from Client
type HTTPError struct {
*resty.Response
}

//Error is an implementation of error type interface method
// Error is an implementation of error type interface method
func (e HTTPError) Error() string {
return fmt.Sprintf("unexpected response %d %v", e.StatusCode(), string(e.Body()))
}

//NewClient creates instance of the Client
// NewClient creates instance of the Client
func NewClient(c Config) Client {
client := &client{
config: &c,
Expand All @@ -113,19 +113,19 @@ func NewClient(c Config) Client {
return client
}

//Config of the client
// Config of the client
func (c *client) Config() *Config {
return c.config
}

//FetchFileE queries the remote configuration service and returns the resulting file
// FetchFileE queries the remote configuration service and returns the resulting file
func (c *client) FetchFileE(source string) ([]byte, error) {
resp, err := resty.R().Get(c.formatFileURI(source))

return resp.Body(), err
}

//FetchFile queries the remote configuration service and returns the resulting file
// FetchFile queries the remote configuration service and returns the resulting file
func (c *client) FetchFile(source string, errorHandler func([]byte, error) []byte) []byte {
resp, err := resty.R().Get(c.formatFileURI(source))

Expand All @@ -135,28 +135,28 @@ func (c *client) FetchFile(source string, errorHandler func([]byte, error) []byt
return resp.Body()
}

//FetchAsProperties queries the remote configuration service and returns the result as a Properties string
// FetchAsProperties queries the remote configuration service and returns the result as a Properties string
func (c *client) FetchAsProperties() (string, error) {
return c.FetchAs(properties)
}

//FetchAsJSON queries the remote configuration service and returns the result as a JSON string
// FetchAsJSON queries the remote configuration service and returns the result as a JSON string
func (c *client) FetchAsJSON() (string, error) {
return c.FetchAs(json)
}

//FetchAsYAML queries the remote configuration service and returns the result as a YAML string
// FetchAsYAML queries the remote configuration service and returns the result as a YAML string
func (c *client) FetchAsYAML() (string, error) {
return c.FetchAs(yaml)
}

//FetchAs queries the remote configuration service and returns the result in specified format
// FetchAs queries the remote configuration service and returns the result in specified format
func (c *client) FetchAs(extension Extension) (string, error) {
resp, err := resty.R().Get(c.formatValuesURI(extension))
return resp.String(), err
}

//Encrypt encrypts the value server side and returns result
// Encrypt encrypts the value server side and returns result
func (c *client) Encrypt(value string) (string, error) {
resp, err := resty.R().
SetHeader("Content-Type", "text/plain").
Expand All @@ -165,7 +165,7 @@ func (c *client) Encrypt(value string) (string, error) {
return resp.String(), err
}

//Decrypt decrypts the value server side and returns result
// Decrypt decrypts the value server side and returns result
func (c *client) Decrypt(value string) (string, error) {
resp, err := resty.R().
SetHeader("Content-Type", "text/plain").
Expand Down
7 changes: 0 additions & 7 deletions pkg/inject/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,4 @@ func toAdmissionResponse(err error) *v1beta1.AdmissionResponse {

func init() {
_ = corev1.AddToScheme(runtimeScheme)
//
// // The `v1` package from k8s.io/kubernetes/pkgp/apis/core/v1 has
// // the object defaulting functions which are not included in
// // k8s.io/api/corev1. The default functions are required by
// // runtime.ObjectDefaulter to workaround lack of server-side
// // defaulting with webhooks (see
// // https://github.com/kubernetes/kubernetes/issues/57982).
}

0 comments on commit 434a465

Please sign in to comment.