Skip to content

Commit dac007c

Browse files
committed
v0.5.5
1 parent 9c44b60 commit dac007c

26 files changed

+299
-200
lines changed

adapter/grpc/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type ClientOptions struct {
1010
clientKey string
1111
}
1212

13+
// ClientOpt represents Client option
1314
type ClientOpt func(options *ClientOptions)
1415

1516
var defaultOptions = &ClientOptions{

adapter/k8s/auth.go

+11-6
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ func (c *Client) gcsAuth(ctx context.Context, r *entity.GCSAuth) (*rest.Config,
2121
var token *oauth2.Token
2222

2323
credentials, err := auth.FindDefaultCredentials(ctx, gcsScopes...)
24-
if err == nil {
25-
token, err = credentials.TokenSource.Token()
26-
if err != nil {
27-
return nil, err
28-
}
24+
if err != nil {
25+
return nil, err
2926
}
3027

31-
containerService, _ := container.NewService(ctx)
28+
token, err = credentials.TokenSource.Token()
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
containerService, err := container.NewService(ctx)
34+
if err != nil {
35+
return nil, err
36+
}
3237

3338
name := fmt.Sprintf("projects/%s/locations/%s/clusters/%s", r.Project, r.Location, r.Cluster)
3439
resp, err := containerService.Projects.Locations.Clusters.Get(name).Do()

adapter/k8s/control.go

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"k8s.io/client-go/rest"
88
)
99

10+
// PortForwardControl port forwarding control
1011
type PortForwardControl struct {
1112
config *rest.Config
1213
client *kubernetes.Clientset
@@ -15,14 +16,17 @@ type PortForwardControl struct {
1516
errOut *bytes.Buffer
1617
}
1718

19+
// Close stop port forwarding
1820
func (c *PortForwardControl) Close() {
1921
close(c.stopCh)
2022
}
2123

24+
// Output returns a buffer containing port forward messages
2225
func (c *PortForwardControl) Output() *bytes.Buffer {
2326
return c.out
2427
}
2528

29+
// Error returns a buffer containing error messages for port forwarding
2630
func (c *PortForwardControl) Error() *bytes.Buffer {
2731
return c.errOut
2832
}

bin/bundler-darwin.sh

+2-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ cp -R ../resources/* ../deploy/app/resources
1111
mv ../deploy/app/bind.go ../deploy/app/bind.go.tmp
1212

1313
cd ../deploy/app || exit
14-
astilectron-bundler -c ../../bin/bundler-darwin.json -ldflags X:main.UseBootstrap=true -ldflags X:main.AppVersion="${version}" -ldflags "-s -w" || exit
14+
astilectron-bundler -c ../../bin/bundler-darwin.json -ldflags X:main.UseBootstrap=true -ldflags X:main.AppVersion="${version}" -ldflags "-s -w"
1515

1616
cp resources/icons/tray24.png ../../bin/distr/darwin-amd64/warthog.app/Contents/Resources/
1717
rm -R resources
1818
mv bind.go.tmp bind.go
19-
rm bind_darwin_amd64.go
20-
21-
#cd ../../bin/distr/darwin-amd64/warthog.app/Contents/MacOS/ || exit
22-
#upx -9 Warthog
23-
24-
19+
rm bind_darwin_amd64.go

bin/bundler-linux.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
#go install github.com/asticode/go-astilectron-bundler/astilectron-bundler
4+
35
version=$(cat version)
46

57
mkdir -p distr
@@ -9,7 +11,7 @@ cp -R ../resources/* ../deploy/app/resources
911
mv ../deploy/app/bind.go ../deploy/app/bind.go.tmp
1012

1113
cd ../deploy/app || exit
12-
astilectron-bundler -c ../../bin/bundler-linux.json -ldflags X:main.UseBootstrap=true -ldflags X:main.AppVersion="${version}" -ldflags "-s -w" || exit
14+
astilectron-bundler -c ../../bin/bundler-linux.json -ldflags X:main.UseBootstrap=true -ldflags X:main.AppVersion="${version}" -ldflags "-s -w"
1315

1416
rm -R resources
1517
mv bind.go.tmp bind.go

bin/bundler-windows64.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22

33
version=$(cat version)
44

5+
#sudo apt-get install gcc-multilib
6+
#sudo apt-get install gcc-mingw-w64
57
#go install github.com/asticode/go-astilectron-bundler/astilectron-bundler
68

79
mkdir -p ../deploy/app/resources
810
cp -R ../resources/* ../deploy/app/resources
911
mv ../deploy/app/bind.go ../deploy/app/bind.go.tmp
1012

1113
cd ../deploy/app || exit
12-
astilectron-bundler -c ../../bin/bundler-windows64.json -ldflags X:main.UseBootstrap=true -ldflags X:main.AppVersion="${version}" -ldflags "-s -w" || exit
14+
astilectron-bundler -c ../../bin/bundler-windows64.json -ldflags X:main.UseBootstrap=true -ldflags X:main.AppVersion="${version}" -ldflags "-s -w"
1315

1416
rm -R resources
1517
mv bind.go.tmp bind.go
1618
rm bind_windows_amd64.go
1719
rm windows.syso
1820

21+
cd ../../bin/distr/windows-amd64 || exit
22+
upx -9 Warthog.exe
23+

bin/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.0
1+
0.5.5

business/entity/auth.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import (
66
)
77

88
const (
9-
AuthTypeNone = "none"
10-
AuthTypeBasic = "basic"
9+
// AuthTypeNone do not use authentication
10+
AuthTypeNone = "none"
11+
// AuthTypeBasic basic authentication
12+
AuthTypeBasic = "basic"
13+
// AuthTypeBearer bearer token authentication
1114
AuthTypeBearer = "bearer"
12-
AuthTypeJWT = "jwt"
13-
AuthTypeGCE = "google"
15+
// AuthTypeJWT jwt token authentication
16+
AuthTypeJWT = "jwt"
17+
// AuthTypeGCE Google Compute Engine authentication
18+
AuthTypeGCE = "google"
1419
)
1520

1621
// Auth authentication data

business/entity/errors.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package entity
33
import "errors"
44

55
var (
6+
// ErrK8SPodNotFound error - pod not found
67
ErrK8SPodNotFound = errors.New("pod not found")
7-
ErrNotConnected = errors.New("not connected")
8+
// ErrNotConnected error - server not connected
9+
ErrNotConnected = errors.New("not connected")
810
)

business/entity/messages.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package entity
22

33
const (
4-
MsgCreatingPortForward = "Creating port forwarding..."
5-
MsgConnectingServer = "Connecting to server..."
4+
// MsgCreatingPortForward message creating port forwarding
5+
MsgCreatingPortForward = "Creating port forwarding..."
6+
// MsgConnectingServer message connecting to server
7+
MsgConnectingServer = "Connecting to server..."
8+
// MsgServerReflectionInfo message getting information about services
69
MsgServerReflectionInfo = "Getting information about publicly-accessible gRPC services..."
710
)

business/entity/query.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ func getBytesValue(val map[string]interface{}) ([]byte, error) {
102102
return nil, err
103103
}
104104
return data, nil
105-
} else {
106-
return []byte(val["value"].(string)), nil
107105
}
106+
return []byte(val["value"].(string)), nil
108107
}
109108

110109
// GetBytes transforms to bytes

business/entity/workspace.go

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const (
1515
WorkspaceTypeQuery WorkspaceType = "r"
1616

1717
WorkspaceDuplicatePostfix = "Copy"
18+
19+
WorkspaceEventServerUpdated = "server.updated"
1820
)
1921

2022
var (
@@ -45,6 +47,14 @@ func (t WorkspaceType) String() string {
4547
return string(t)
4648
}
4749

50+
// WorkspaceEvent workspace event
51+
type WorkspaceEvent string
52+
53+
// String returns workspace event string
54+
func (e WorkspaceEvent) String() string {
55+
return string(e)
56+
}
57+
4858
// WorkspaceRequest workspace request by type
4959
type WorkspaceRequest struct {
5060
Type []WorkspaceType `json:"type"`

business/entity/workspace.server.go

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func (s *WorkspaceItemServer) Model(server map[string]interface{}) error {
140140
return nil
141141
}
142142

143+
// IsK8SEnabled checks whether it is enabled k8s port forwarding
143144
func (s *WorkspaceItemServer) IsK8SEnabled() bool {
144145
return s.K8SPortForward != nil && s.K8SPortForward.Enabled
145146
}

business/usecase/grpc.forward.go

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package usecase
2+
3+
import (
4+
"crypto/md5"
5+
"encoding/hex"
6+
"fmt"
7+
8+
"github.com/forest33/warthog/business/entity"
9+
)
10+
11+
func (uc *GrpcUseCase) getPortForwardErrorHandler(srv entity.WorkspaceItemServer, serverID int64) func(error) {
12+
return func(err error) {
13+
uc.deletePortForward(srv)
14+
if uc.curConnectedServerID == serverID {
15+
uc.curConnectedServerID = 0
16+
uc.errorCh <- &entity.Error{
17+
Message: err.Error(),
18+
}
19+
}
20+
}
21+
}
22+
23+
func (uc *GrpcUseCase) getPortForward(srv *entity.WorkspaceItemServer) *forwardPort {
24+
uc.muForwardPorts.RLock()
25+
defer uc.muForwardPorts.RUnlock()
26+
27+
if uc.forwardPorts == nil {
28+
return nil
29+
}
30+
31+
if fp, ok := uc.forwardPorts[srv.K8SPortForward.LocalPort]; ok {
32+
return fp
33+
}
34+
35+
return nil
36+
}
37+
38+
func (uc *GrpcUseCase) addPortForward(srv *entity.WorkspaceItemServer, control entity.PortForwardControl) {
39+
uc.muForwardPorts.Lock()
40+
defer uc.muForwardPorts.Unlock()
41+
42+
if uc.forwardPorts == nil {
43+
uc.forwardPorts = make(map[int16]*forwardPort, 10)
44+
}
45+
46+
uc.forwardPorts[srv.K8SPortForward.LocalPort] = &forwardPort{
47+
control: control,
48+
hash: getPortForwardHash(srv),
49+
}
50+
}
51+
52+
func (uc *GrpcUseCase) deletePortForward(srv entity.WorkspaceItemServer) {
53+
uc.muForwardPorts.Lock()
54+
defer uc.muForwardPorts.Unlock()
55+
56+
if uc.forwardPorts == nil {
57+
return
58+
}
59+
60+
delete(uc.forwardPorts, srv.K8SPortForward.LocalPort)
61+
}
62+
63+
func getPortForwardHash(srv *entity.WorkspaceItemServer) string {
64+
data := fmt.Sprintf("%d|%s|%s|%s",
65+
srv.K8SPortForward.PodPort,
66+
srv.K8SPortForward.Namespace,
67+
srv.K8SPortForward.PodName,
68+
srv.K8SPortForward.PodNameSelector,
69+
)
70+
71+
if srv.K8SPortForward.ClientConfig.GCSAuth != nil && srv.K8SPortForward.ClientConfig.GCSAuth.Enabled {
72+
data = fmt.Sprintf("|%s|%s|%s|%s",
73+
data,
74+
srv.K8SPortForward.ClientConfig.GCSAuth.Project,
75+
srv.K8SPortForward.ClientConfig.GCSAuth.Location,
76+
srv.K8SPortForward.ClientConfig.GCSAuth.Cluster,
77+
)
78+
}
79+
80+
hash := md5.Sum([]byte(data))
81+
return hex.EncodeToString(hash[:])
82+
}

0 commit comments

Comments
 (0)