Skip to content

Commit

Permalink
fix tests and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
andersjohnsen committed Sep 18, 2024
1 parent 413f41b commit e449e03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
28 changes: 6 additions & 22 deletions cmd/rig-proxy/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ var verbose = false
func createRootCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "rig-proxy",
RunE: func(cmd *cobra.Command, args []string) error {
core := zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(os.Stderr), zapcore.DebugLevel)
RunE: func(_ *cobra.Command, _ []string) error {
core := zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
zapcore.AddSync(os.Stderr),
zapcore.DebugLevel,
)
logger := zap.New(core)

p := tunnel.New(logger)
Expand Down Expand Up @@ -58,23 +62,3 @@ func createRootCMD() *cobra.Command {

return cmd
}

type proxyConfig struct {
ForwardRules []forwardRule `yaml:"forwardRules"`
ReverseRules []reverseRule `yaml:"reverseRules"`
TunnelPort uint32 `yaml:"tunnelPort"`
}

type forwardRule struct {
Type string `yaml:"type"`
Port uint32 `yaml:"port"`
Target string `yaml:"target"`
AllowOrigin string `yaml:"allowOrigin"`
targetName string
targetPort uint32
}

type reverseRule struct {
Port uint32 `yaml:"port"`
Target string `yaml:"target"`
}
12 changes: 10 additions & 2 deletions cmd/rig-proxy/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ func (t *tunnelScope) Write(tunnelID uint64, data []byte) error {
func (t *tunnelScope) Close(tunnelID uint64, err error) {
logger := t.h.logger.With(zap.Uint64("tunnel_id", tunnelID))
if err != nil {
logger.Warn("socket closed with error", zap.Stringer("code", errors.CodeOf(err)), zap.String("message", errors.MessageOf(err)))
logger.Warn(
"socket closed with error",
zap.Stringer("code", errors.CodeOf(err)),
zap.String("message", errors.MessageOf(err)),
)
} else {
logger.Info("socket closed")
}
Expand Down Expand Up @@ -162,7 +166,11 @@ func (h *tunnelHandler) Tunnel(stream api_tunnel.Service_TunnelServer) error {
return
}

h.logger.Info("new incoming request", zap.Stringer("local", conn.LocalAddr()), zap.Stringer("remote", conn.RemoteAddr()))
h.logger.Info(
"new incoming request",
zap.Stringer("local", conn.LocalAddr()),
zap.Stringer("remote", conn.RemoteAddr()),
)

if err := tunnel.HandleInbound(stream.Context(), t, conn, uint32(port)); err != nil {
h.logger.Error("error initializing reverse tunnel", zap.Error(err))
Expand Down
12 changes: 7 additions & 5 deletions pkg/cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ type configSessionManager struct {
func (s *configSessionManager) GetAccessToken() string {
accessToken := s.ctx.GetAuth().AccessToken
if accessToken == "" && s.ctx.GetAuth().RefreshToken != "" {
res, err := s.noAuthClient.Authentication().RefreshToken(context.Background(), &connect.Request[authentication.RefreshTokenRequest]{
Msg: &authentication.RefreshTokenRequest{
RefreshToken: s.ctx.GetAuth().RefreshToken,
},
})
res, err := s.noAuthClient.Authentication().RefreshToken(
context.Background(),
&connect.Request[authentication.RefreshTokenRequest]{
Msg: &authentication.RefreshTokenRequest{
RefreshToken: s.ctx.GetAuth().RefreshToken,
},
})
if err != nil {
fmt.Fprintf(os.Stderr, "error refreshing auth token: %v\n", err)
fmt.Fprintf(os.Stderr, "run `rig auth login` to reconnect\n")
Expand Down

0 comments on commit e449e03

Please sign in to comment.