Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devel #6

Merged
merged 2 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,28 @@ jobs:
with:
version: "2022.1.3"

# codeql:
# runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# language: [ 'go' ]
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Install Go
# uses: actions/setup-go@v5
# with:
# go-version-file: "go.mod"
# cache: true
# - name: Initialize CodeQL
# uses: github/codeql-action/init@v3
# with:
# languages: ${{ matrix.language }}
# - name: Autobuild
# uses: github/codeql-action/autobuild@v3
# - name: Perform CodeQL Analysis
# uses: github/codeql-action/analyze@v3
codeql:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: true
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

sonarcloud:
runs-on: ubuntu-latest
Expand Down
50 changes: 20 additions & 30 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ jobs:
with:
version: "2022.1.3"

# codeql:
# runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# language: [ 'go' ]
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Initialize CodeQL
# uses: github/codeql-action/init@v3
# with:
# languages: ${{ matrix.language }}
# - name: Autobuild
# uses: github/codeql-action/autobuild@v3
# - name: Perform CodeQL Analysis
# uses: github/codeql-action/analyze@v3
codeql:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

sonarcloud:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -102,36 +102,26 @@ jobs:
- name: Build CLi
run: make -s build-cli

tag:
release:
runs-on: ubuntu-latest
needs:
- lint
- test
# - codeql
- codeql
- staticcheck
- sonarcloud
- build
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: '0'
fetch-depth: 0
- name: Bump version and push tag
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch

release:
runs-on: ubuntu-latest
needs:
- tag
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set outputs
id: vars
run: |
Expand Down
6 changes: 4 additions & 2 deletions cmd/cli/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package add
import (
"fmt"

"github.com/bilalcaliskan/split-the-tunnel/internal/constants"

"github.com/bilalcaliskan/split-the-tunnel/cmd/cli/utils"
"github.com/bilalcaliskan/split-the-tunnel/internal/logging"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -34,11 +36,11 @@ to quickly create a Cobra application.`,
req := fmt.Sprintf("%s %s", cmd.Name(), arg)
res, err := utils.SendCommandToDaemon(utils.SocketPath, req)
if err != nil {
logger.Error().Str("command", req).Err(err).Msg("error sending command to daemon")
logger.Error().Str("command", req).Err(err).Msg(constants.FailedToSendCommand)
continue
}

logger.Info().Str("command", req).Str("response", res).Msg("successfully processed command")
logger.Info().Str("command", req).Str("response", res).Msg(constants.SuccessfullyProcessed)
}

return nil
Expand Down
5 changes: 3 additions & 2 deletions cmd/cli/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package list

import (
"github.com/bilalcaliskan/split-the-tunnel/cmd/cli/utils"
"github.com/bilalcaliskan/split-the-tunnel/internal/constants"
"github.com/bilalcaliskan/split-the-tunnel/internal/logging"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -29,12 +30,12 @@ to quickly create a Cobra application.`,
logger.Info().Msg("list called")
res, err := utils.SendCommandToDaemon(utils.SocketPath, cmd.Name())
if err != nil {
logger.Error().Str("command", cmd.Name()).Err(err).Msg("error sending command to daemon")
logger.Error().Str("command", cmd.Name()).Err(err).Msg(constants.FailedToSendCommand)

return &utils.CommandError{Err: err, Code: 10}
}

logger.Info().Str("command", cmd.Name()).Str("response", res).Msg("successfully processed command")
logger.Info().Str("command", cmd.Name()).Str("response", res).Msg(constants.SuccessfullyProcessed)

return nil
},
Expand Down
6 changes: 4 additions & 2 deletions cmd/cli/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package remove
import (
"fmt"

"github.com/bilalcaliskan/split-the-tunnel/internal/constants"

"github.com/bilalcaliskan/split-the-tunnel/cmd/cli/utils"
"github.com/bilalcaliskan/split-the-tunnel/internal/logging"

Expand Down Expand Up @@ -35,11 +37,11 @@ to quickly create a Cobra application.`,
req := fmt.Sprintf("%s %s", cmd.Name(), arg)
res, err := utils.SendCommandToDaemon(utils.SocketPath, req)
if err != nil {
logger.Error().Str("command", req).Err(err).Msg("error sending command to daemon")
logger.Error().Str("command", req).Err(err).Msg(constants.FailedToSendCommand)
continue
}

logger.Info().Str("command", req).Str("response", res).Msg("successfully processed command")
logger.Info().Str("command", req).Str("response", res).Msg(constants.SuccessfullyProcessed)
}

return nil
Expand Down
26 changes: 9 additions & 17 deletions cmd/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"os/signal"
"syscall"

"github.com/bilalcaliskan/split-the-tunnel/internal/ipc"
"github.com/bilalcaliskan/split-the-tunnel/internal/utils"
"github.com/bilalcaliskan/split-the-tunnel/internal/constants"

"github.com/bilalcaliskan/split-the-tunnel/cmd/daemon/options"
"github.com/bilalcaliskan/split-the-tunnel/internal/ipc"
"github.com/bilalcaliskan/split-the-tunnel/internal/logging"
"github.com/bilalcaliskan/split-the-tunnel/internal/version"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -36,41 +36,33 @@ var daemonCmd = &cobra.Command{
logger := logging.GetLogger()
logger.Info().Str("appVersion", ver.GitVersion).Str("goVersion", ver.GoVersion).Str("goOS", ver.GoOs).
Str("goArch", ver.GoArch).Str("gitCommit", ver.GitCommit).Str("buildDate", ver.BuildDate).
Msg("split-the-tunnel is started!")

gateway, err := utils.GetDefaultNonVPNGateway()
if err != nil {
logger.Error().Err(err).Msg("failed to get default gateway")
return err
}

logger.Info().Str("gateway", gateway).Msg("found default gateway")
Msg(constants.AppStarted)

// Setup signal handling for a graceful shutdown
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

// Initialize IPC mechanism
if err := ipc.InitIPC(socketPath, logger); err != nil {
logger.Error().Err(err).Msg("failed to initialize IPC")
logger.Error().Err(err).Msg(constants.FailedToInitializeIPC)
return err
}

logger.Info().Str("socket", socketPath).Msg("IPC is initialized")
logger.Info().Str("socket", socketPath).Msg(constants.IPCInitialized)

defer func() {
if err := ipc.Cleanup(socketPath); err != nil {
logger.Error().Err(err).Msg("failed to cleanup IPC")
logger.Error().Err(err).Msg(constants.FailedToCleanupIPC)
}
}()

logger.Info().Msg("daemon is running...")
logger.Info().Msg(constants.DaemonRunning)

// Wait for termination signal
<-sigs

logger.Info().Msg("termination signal received")
logger.Info().Msg("shutting down daemon...")
logger.Info().Msg(constants.TermSignalReceived)
logger.Info().Msg(constants.ShuttingDownDaemon)

return nil
},
Expand Down
24 changes: 24 additions & 0 deletions internal/constants/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package constants

const (
FailedToAcceptConnection = "failed to accept connection"
FailedToConnectToUnixDomainSocket = "failed to connect to unix domain socket"
FailedToOpenRoutingInfoFile = "failed to open routing info file"
FailedToWriteToUnixDomainSocket = "failed to write to unix domain socket"
FileDoesNotExist = "file does not exist"
NoArgumentsProvided = "no arguments provided"
FailedToReadFromIPC = "failed to read from IPC connection"
FailedToReadState = "failed to read state"
FailedToGetDefaultGateway = "failed to get default gateway"
EmptyCommandReceived = "empty command received"
FailedToResolveDomain = "failed to resolve domain"
FailedToMarshalResponse = "failed to marshal response"
FailedToWriteRouteEntry = "failed to write RouteEntry to state"
EntryNotFound = "entry not found"
NonVPNGatewayNotFound = "non-VPN gateway not found"
FailedToDecodeHex = "failed to decode hex string"
InvalidIpLength = "invalid IP length: %d"
FailedToSendCommand = "failed to send command to daemon"
FailedToCleanupIPC = "failed to cleanup IPC"
FailedToInitializeIPC = "failed to initialize IPC"
)
10 changes: 10 additions & 0 deletions internal/constants/infos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package constants

const (
SuccessfullyProcessed = "successfully processed command"
IPCInitialized = "IPC is initialized"
DaemonRunning = "daemon is running..."
TermSignalReceived = "termination signal received"
ShuttingDownDaemon = "shutting down daemon..."
AppStarted = "split-the-tunnel is started!"
)
Loading
Loading