Skip to content

Commit

Permalink
v0.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Forest33 committed Sep 8, 2023
1 parent 9c44b60 commit dac007c
Show file tree
Hide file tree
Showing 26 changed files with 299 additions and 200 deletions.
1 change: 1 addition & 0 deletions adapter/grpc/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type ClientOptions struct {
clientKey string
}

// ClientOpt represents Client option
type ClientOpt func(options *ClientOptions)

var defaultOptions = &ClientOptions{
Expand Down
17 changes: 11 additions & 6 deletions adapter/k8s/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ func (c *Client) gcsAuth(ctx context.Context, r *entity.GCSAuth) (*rest.Config,
var token *oauth2.Token

credentials, err := auth.FindDefaultCredentials(ctx, gcsScopes...)
if err == nil {
token, err = credentials.TokenSource.Token()
if err != nil {
return nil, err
}
if err != nil {
return nil, err
}

containerService, _ := container.NewService(ctx)
token, err = credentials.TokenSource.Token()
if err != nil {
return nil, err
}

containerService, err := container.NewService(ctx)
if err != nil {
return nil, err
}

name := fmt.Sprintf("projects/%s/locations/%s/clusters/%s", r.Project, r.Location, r.Cluster)
resp, err := containerService.Projects.Locations.Clusters.Get(name).Do()
Expand Down
4 changes: 4 additions & 0 deletions adapter/k8s/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"k8s.io/client-go/rest"
)

// PortForwardControl port forwarding control
type PortForwardControl struct {
config *rest.Config
client *kubernetes.Clientset
Expand All @@ -15,14 +16,17 @@ type PortForwardControl struct {
errOut *bytes.Buffer
}

// Close stop port forwarding
func (c *PortForwardControl) Close() {
close(c.stopCh)
}

// Output returns a buffer containing port forward messages
func (c *PortForwardControl) Output() *bytes.Buffer {
return c.out
}

// Error returns a buffer containing error messages for port forwarding
func (c *PortForwardControl) Error() *bytes.Buffer {
return c.errOut
}
9 changes: 2 additions & 7 deletions bin/bundler-darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ cp -R ../resources/* ../deploy/app/resources
mv ../deploy/app/bind.go ../deploy/app/bind.go.tmp

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

cp resources/icons/tray24.png ../../bin/distr/darwin-amd64/warthog.app/Contents/Resources/
rm -R resources
mv bind.go.tmp bind.go
rm bind_darwin_amd64.go

#cd ../../bin/distr/darwin-amd64/warthog.app/Contents/MacOS/ || exit
#upx -9 Warthog


rm bind_darwin_amd64.go
4 changes: 3 additions & 1 deletion bin/bundler-linux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

#go install github.com/asticode/go-astilectron-bundler/astilectron-bundler

version=$(cat version)

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

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

rm -R resources
mv bind.go.tmp bind.go
Expand Down
7 changes: 6 additions & 1 deletion bin/bundler-windows64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

version=$(cat version)

#sudo apt-get install gcc-multilib
#sudo apt-get install gcc-mingw-w64
#go install github.com/asticode/go-astilectron-bundler/astilectron-bundler

mkdir -p ../deploy/app/resources
cp -R ../resources/* ../deploy/app/resources
mv ../deploy/app/bind.go ../deploy/app/bind.go.tmp

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

rm -R resources
mv bind.go.tmp bind.go
rm bind_windows_amd64.go
rm windows.syso

cd ../../bin/distr/windows-amd64 || exit
upx -9 Warthog.exe

2 changes: 1 addition & 1 deletion bin/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.0
0.5.5
13 changes: 9 additions & 4 deletions business/entity/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import (
)

const (
AuthTypeNone = "none"
AuthTypeBasic = "basic"
// AuthTypeNone do not use authentication
AuthTypeNone = "none"
// AuthTypeBasic basic authentication
AuthTypeBasic = "basic"
// AuthTypeBearer bearer token authentication
AuthTypeBearer = "bearer"
AuthTypeJWT = "jwt"
AuthTypeGCE = "google"
// AuthTypeJWT jwt token authentication
AuthTypeJWT = "jwt"
// AuthTypeGCE Google Compute Engine authentication
AuthTypeGCE = "google"
)

// Auth authentication data
Expand Down
4 changes: 3 additions & 1 deletion business/entity/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package entity
import "errors"

var (
// ErrK8SPodNotFound error - pod not found
ErrK8SPodNotFound = errors.New("pod not found")
ErrNotConnected = errors.New("not connected")
// ErrNotConnected error - server not connected
ErrNotConnected = errors.New("not connected")
)
7 changes: 5 additions & 2 deletions business/entity/messages.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package entity

const (
MsgCreatingPortForward = "Creating port forwarding..."
MsgConnectingServer = "Connecting to server..."
// MsgCreatingPortForward message creating port forwarding
MsgCreatingPortForward = "Creating port forwarding..."
// MsgConnectingServer message connecting to server
MsgConnectingServer = "Connecting to server..."
// MsgServerReflectionInfo message getting information about services
MsgServerReflectionInfo = "Getting information about publicly-accessible gRPC services..."
)
3 changes: 1 addition & 2 deletions business/entity/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ func getBytesValue(val map[string]interface{}) ([]byte, error) {
return nil, err
}
return data, nil
} else {
return []byte(val["value"].(string)), nil
}
return []byte(val["value"].(string)), nil
}

// GetBytes transforms to bytes
Expand Down
10 changes: 10 additions & 0 deletions business/entity/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const (
WorkspaceTypeQuery WorkspaceType = "r"

WorkspaceDuplicatePostfix = "Copy"

WorkspaceEventServerUpdated = "server.updated"
)

var (
Expand Down Expand Up @@ -45,6 +47,14 @@ func (t WorkspaceType) String() string {
return string(t)
}

// WorkspaceEvent workspace event
type WorkspaceEvent string

// String returns workspace event string
func (e WorkspaceEvent) String() string {
return string(e)
}

// WorkspaceRequest workspace request by type
type WorkspaceRequest struct {
Type []WorkspaceType `json:"type"`
Expand Down
1 change: 1 addition & 0 deletions business/entity/workspace.server.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (s *WorkspaceItemServer) Model(server map[string]interface{}) error {
return nil
}

// IsK8SEnabled checks whether it is enabled k8s port forwarding
func (s *WorkspaceItemServer) IsK8SEnabled() bool {
return s.K8SPortForward != nil && s.K8SPortForward.Enabled
}
82 changes: 82 additions & 0 deletions business/usecase/grpc.forward.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package usecase

import (
"crypto/md5"
"encoding/hex"
"fmt"

"github.com/forest33/warthog/business/entity"
)

func (uc *GrpcUseCase) getPortForwardErrorHandler(srv entity.WorkspaceItemServer, serverID int64) func(error) {
return func(err error) {
uc.deletePortForward(srv)
if uc.curConnectedServerID == serverID {
uc.curConnectedServerID = 0
uc.errorCh <- &entity.Error{
Message: err.Error(),
}
}
}
}

func (uc *GrpcUseCase) getPortForward(srv *entity.WorkspaceItemServer) *forwardPort {
uc.muForwardPorts.RLock()
defer uc.muForwardPorts.RUnlock()

if uc.forwardPorts == nil {
return nil
}

if fp, ok := uc.forwardPorts[srv.K8SPortForward.LocalPort]; ok {
return fp
}

return nil
}

func (uc *GrpcUseCase) addPortForward(srv *entity.WorkspaceItemServer, control entity.PortForwardControl) {
uc.muForwardPorts.Lock()
defer uc.muForwardPorts.Unlock()

if uc.forwardPorts == nil {
uc.forwardPorts = make(map[int16]*forwardPort, 10)
}

uc.forwardPorts[srv.K8SPortForward.LocalPort] = &forwardPort{
control: control,
hash: getPortForwardHash(srv),
}
}

func (uc *GrpcUseCase) deletePortForward(srv entity.WorkspaceItemServer) {
uc.muForwardPorts.Lock()
defer uc.muForwardPorts.Unlock()

if uc.forwardPorts == nil {
return
}

delete(uc.forwardPorts, srv.K8SPortForward.LocalPort)
}

func getPortForwardHash(srv *entity.WorkspaceItemServer) string {
data := fmt.Sprintf("%d|%s|%s|%s",
srv.K8SPortForward.PodPort,
srv.K8SPortForward.Namespace,
srv.K8SPortForward.PodName,
srv.K8SPortForward.PodNameSelector,
)

if srv.K8SPortForward.ClientConfig.GCSAuth != nil && srv.K8SPortForward.ClientConfig.GCSAuth.Enabled {
data = fmt.Sprintf("|%s|%s|%s|%s",
data,
srv.K8SPortForward.ClientConfig.GCSAuth.Project,
srv.K8SPortForward.ClientConfig.GCSAuth.Location,
srv.K8SPortForward.ClientConfig.GCSAuth.Cluster,
)
}

hash := md5.Sum([]byte(data))
return hex.EncodeToString(hash[:])
}
Loading

0 comments on commit dac007c

Please sign in to comment.