Skip to content

Commit

Permalink
Update release branch (#82)
Browse files Browse the repository at this point in the history
* Updated makefile (#79)

* Integration Test (#81)

Map/Cluster command outputs to stdout; added a test

* [Trivial] Update cloud ssl configuration example (#80)

* update cloud ssl configuration example

* move assignment of default ssl servername earlier

* set SSL servername to "hazelcast.cloud" only if SSL configuration modified and cloud is enabled

* minor fixes

* refactor SSL configuration

Co-authored-by: Yüce Tekol <[email protected]>
  • Loading branch information
utku-caglayan and yuce authored Jun 10, 2022
1 parent af57a78 commit b20158e
Show file tree
Hide file tree
Showing 12 changed files with 2,088 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ hz-cli
/dev_scripts/devcontainer.sh
/dist/
/hzc
coverage.out
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
.PHONY: build
.PHONY: build generate-completion test test-cover view-cover

TAG=$(shell git describe --tags 2> /dev/null || echo unknown)
CLIENT_TYPE="CLC"
LDFLAGS="-X 'github.com/hazelcast/hazelcast-go-client/internal.ClientType=$(CLIENT_TYPE)' -X 'github.com/hazelcast/hazelcast-go-client/internal.ClientVersion=$(TAG)'"
TEST_FLAGS ?= -v -count 1
COVERAGE_OUT = coverage.out

build:
go build -ldflags $(LDFLAGS) -o hzc github.com/hazelcast/hazelcast-commandline-client

generate-completion: build
mkdir -p extras
MODE="dev" ./hzc completion bash --no-descriptions > extras/bash_completion.sh
MODE="dev" ./hzc completion zsh --no-descriptions > extras/zsh_completion.zsh

test:
go test -v ./...
go test $(TESTFLAGS) ./...

test-cover:
go test $(TESTFLAGS) -coverprofile=$(COVERAGE_OUT) ./...

view-cover:
go tool cover -func $(COVERAGE_OUT) | grep total:
go tool cover -html $(COVERAGE_OUT) -o coverage.html
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ The cluster creation and retrieving connection info can be done directly in comm
You can use the following configuration file to enable SSL support:
```
ssl:
enabled: true
servername: "HOSTNAME-FOR-SERVER"
# or: insecureskipverify: true
hazelcast:
Expand All @@ -184,6 +185,7 @@ hazelcast:
Mutual authentication is also supported:
```
ssl:
enabled: true
servername: "HOSTNAME-FOR-SERVER"
# insecureskipverify: true
capath: "/tmp/ca.pem"
Expand All @@ -205,6 +207,7 @@ hazelcast:
Cloud SSL configuration:
```
ssl:
enabled: true
capath: "/tmp/ca.pem"
certpath: "/tmp/cert.pem"
keypath: "/tmp/key.pem"
Expand Down
4 changes: 2 additions & 2 deletions clustercmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func New(config *hazelcast.Config) *cobra.Command {
if err != nil {
return err
}
cmd.Println(*result)
fmt.Println(*result)
return nil
},
})
Expand All @@ -92,7 +92,7 @@ func NewChangeState(config *hazelcast.Config) *cobra.Command {
if err != nil {
return err
}
cmd.Println(*result)
fmt.Println(*result)
return nil
},
}
Expand Down
28 changes: 11 additions & 17 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ import (

const defaultConfigFilename = "config.yaml"
const (
DefaultClusterAddress = "localhost:5701"
DefaultClusterName = "dev"
DefaultClusterAddress = "localhost:5701"
DefaultClusterName = "dev"
DefaultCloudServerName = "hazelcast.cloud"
)

type SSLConfig struct {
Enabled bool
ServerName string
InsecureSkipVerify bool
CAPath string
Expand Down Expand Up @@ -104,10 +106,6 @@ func mergeFlagsWithConfig(flags *GlobalFlagValues, config *Config) error {
if flags.Cluster != "" {
config.Hazelcast.Cluster.Name = strings.TrimSpace(flags.Cluster)
}
if config.Hazelcast.Cluster.Cloud.Enabled {
config.SSL.ServerName = "hazelcast.cloud"
config.SSL.InsecureSkipVerify = false
}
// must return nil err
verboseWeight, _ := logger.WeightForLogLevel(logger.DebugLevel)
confLevel := config.Hazelcast.Logger.Level
Expand Down Expand Up @@ -154,20 +152,16 @@ func DefaultConfigPath() string {
}

func updateConfigWithSSL(config *hazelcast.Config, sslc *SSLConfig) error {
if sslc.ServerName != "" && sslc.InsecureSkipVerify {
return fmt.Errorf("SSL.ServerName and SSL.InsecureSkipVerify are mutually exclusive")
if !sslc.Enabled {
// SSL configuration is not set, skip
return nil
}
var tlsc *tls.Config
if sslc.ServerName != "" {
tlsc = &tls.Config{ServerName: sslc.ServerName}
} else if sslc.InsecureSkipVerify {
tlsc = &tls.Config{InsecureSkipVerify: true}
if config.Cluster.Cloud.Enabled && sslc.ServerName == "" {
sslc.ServerName = DefaultCloudServerName
}
csslc := &config.Cluster.Network.SSL
if tlsc != nil {
csslc.SetTLSConfig(tlsc)
csslc.Enabled = true
}
csslc.SetTLSConfig(&tls.Config{ServerName: sslc.ServerName, InsecureSkipVerify: sslc.InsecureSkipVerify})
csslc.Enabled = true
if sslc.CAPath != "" {
if err := csslc.SetCAPath(sslc.CAPath); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (e LoggableError) VerboseError() string {
if e.err == nil {
return fmt.Sprintln(e.msg)
}
return fmt.Sprintf("%s\nDetails: %s", e.msg, e.err)
return fmt.Sprintf("%s\nDetails: %s", e.msg, e.err.Error())
}

func (e LoggableError) Unwrap() error {
Expand Down
22 changes: 22 additions & 0 deletions tests/compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env python3

import sys


def compare_lines():
line_count = 0
while True:
line = sys.stdin.readline().strip()
if line == "":
break
line_count += 1
# assumes the line format in: kN\tvN
k, v = tuple(line.split("\t", 1))
n = k[1:]
expected = f"v{n}"
if v != expected:
raise Exception(f"line {line_count}: expected: {expected}, got: {v}")
return line_count


print(compare_lines())
Loading

0 comments on commit b20158e

Please sign in to comment.