Skip to content

Commit

Permalink
Merge pull request #55 from aakso/chore/restructure-project
Browse files Browse the repository at this point in the history
chore!: quality: restructure project to better align with the best practices
  • Loading branch information
aakso authored Oct 30, 2023
2 parents 9ab75a1 + a0ae40e commit 13e30d2
Show file tree
Hide file tree
Showing 73 changed files with 177 additions and 155 deletions.
12 changes: 6 additions & 6 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ builds:
- id: &build_id_ssh_inscribe ssh-inscribe
env:
- CGO_ENABLED=0
main: .
main: ./cmd/ssh-inscribe
binary: ssh-inscribe
ldflags:
- -X github.com/aakso/ssh-inscribe/pkg/globals.version={{ .Version }}
- -X github.com/aakso/ssh-inscribe/pkg/globals.confDir=/etc/ssh-inscribe
- -X github.com/aakso/ssh-inscribe/pkg/globals.varDir=/var/lib/ssh-inscribe
- -X github.com/aakso/ssh-inscribe/internal/globals.version={{ .Version }}
- -X github.com/aakso/ssh-inscribe/internal/globals.confDir=/etc/ssh-inscribe
- -X github.com/aakso/ssh-inscribe/internal/globals.varDir=/var/lib/ssh-inscribe
goos: [darwin, linux]
goarch: [amd64, arm64]
ignore:
Expand All @@ -17,10 +17,10 @@ builds:
- id: &build_id_sshi sshi
env:
- CGO_ENABLED=0
main: ./cliclient/sshi
main: ./cmd/sshi
binary: sshi
ldflags:
- -X github.com/aakso/ssh-inscribe/pkg/globals.version={{ .Version }}
- -X github.com/aakso/ssh-inscribe/internal/globals.version={{ .Version }}
goos: [darwin, linux, windows]
goarch: [amd64, arm64]
ignore:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ dist:

.PHONY: test
test:
go test $(shell git grep -l '!race' ./pkg | xargs -n 1 dirname | uniq | sed 's/^/\.\//')
go test -race ./pkg/...
go test $(shell git grep -l '!race' ./internal | xargs -n 1 dirname | uniq | sed 's/^/\.\//')
go test -race ./internal/...
15 changes: 0 additions & 15 deletions cliclient/sshi/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/crypt.go → cmd/ssh-inscribe/crypt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"fmt"
Expand Down
9 changes: 5 additions & 4 deletions cmd/defaults.go → cmd/ssh-inscribe/defaults.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package cmd
package main

import (
"fmt"

_ "github.com/aakso/ssh-inscribe/pkg/auth/backend/all"
"github.com/aakso/ssh-inscribe/pkg/config"
_ "github.com/aakso/ssh-inscribe/pkg/server"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

_ "github.com/aakso/ssh-inscribe/internal/auth/backend/all"
"github.com/aakso/ssh-inscribe/internal/config"
_ "github.com/aakso/ssh-inscribe/internal/server"
)

// serverCmd represents the server command
Expand Down
10 changes: 8 additions & 2 deletions main.go → cmd/ssh-inscribe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@

package main

import "github.com/aakso/ssh-inscribe/cmd"
import (
"fmt"
"os"
)

func main() {
cmd.Execute()
if err := RootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
}
14 changes: 4 additions & 10 deletions cmd/root.go → cmd/ssh-inscribe/root.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package cmd
package main

import (
"fmt"
"os"
"path"

"github.com/aakso/ssh-inscribe/pkg/config"
"github.com/aakso/ssh-inscribe/pkg/logging"
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/aakso/ssh-inscribe/internal/config"
"github.com/aakso/ssh-inscribe/internal/logging"
)

var cfgFile string
Expand All @@ -20,13 +21,6 @@ var RootCmd = &cobra.Command{
Long: "",
}

func Execute() {
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
}

func init() {
cobra.OnInitialize(rootInit)
RootCmd.PersistentFlags().StringVar(
Expand Down
5 changes: 3 additions & 2 deletions cmd/server.go → cmd/ssh-inscribe/server.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd
package main

import (
"github.com/aakso/ssh-inscribe/pkg/server"
"github.com/spf13/cobra"

"github.com/aakso/ssh-inscribe/internal/server"
)

// serverCmd represents the server command
Expand Down
5 changes: 3 additions & 2 deletions cmd/version.go → cmd/ssh-inscribe/version.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package cmd
package main

import (
"fmt"

"github.com/aakso/ssh-inscribe/pkg/globals"
"github.com/spf13/cobra"

"github.com/aakso/ssh-inscribe/internal/globals"
)

// serverCmd represents the server command
Expand Down
10 changes: 5 additions & 5 deletions cliclient/cmd/ca.go → cmd/sshi/ca.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"fmt"
Expand All @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh"

"github.com/aakso/ssh-inscribe/pkg/client"
"github.com/aakso/ssh-inscribe/internal/ui"
)

var principals []string
Expand All @@ -23,7 +23,7 @@ var ShowCaCmd = &cobra.Command{
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
c := &client.Client{
c := &ui.Client{
Config: ClientConfig,
}
defer c.Close()
Expand Down Expand Up @@ -51,7 +51,7 @@ var AddCaCmd = &cobra.Command{
if len(args) > 0 {
ClientConfig.CAKeyFile = args[0]
}
c := &client.Client{
c := &ui.Client{
Config: ClientConfig,
}
defer c.Close()
Expand All @@ -65,7 +65,7 @@ var ResponseCmd = &cobra.Command{
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
c := &client.Client{
c := &ui.Client{
Config: ClientConfig,
}
defer c.Close()
Expand Down
12 changes: 6 additions & 6 deletions cliclient/cmd/exec.go → cmd/sshi/exec.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"fmt"
Expand All @@ -14,10 +14,10 @@ import (
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/agent"

"github.com/aakso/ssh-inscribe/pkg/client"
"github.com/aakso/ssh-inscribe/pkg/filteringagent"
"github.com/aakso/ssh-inscribe/pkg/logging"
"github.com/aakso/ssh-inscribe/pkg/util"
"github.com/aakso/ssh-inscribe/internal/filteringagent"
"github.com/aakso/ssh-inscribe/internal/logging"
"github.com/aakso/ssh-inscribe/internal/ui"
"github.com/aakso/ssh-inscribe/internal/util"
)

const (
Expand Down Expand Up @@ -80,7 +80,7 @@ func runExecCommand(args []string) error {
}
}
ClientConfig.GenerateKeypair = true
c := &client.Client{Config: ClientConfig}
c := &ui.Client{Config: ClientConfig}
defer c.Close()
if err := c.Login(); err != nil {
return err
Expand Down
13 changes: 13 additions & 0 deletions cmd/sshi/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
"os"
)

func main() {
if err := RootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
}
7 changes: 4 additions & 3 deletions cliclient/cmd/request.go → cmd/sshi/request.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package cmd
package main

import (
"fmt"
"os"
"strconv"

"github.com/aakso/ssh-inscribe/pkg/client"
"github.com/spf13/cobra"

"github.com/aakso/ssh-inscribe/internal/ui"
)

var ReqCmd = &cobra.Command{
Expand All @@ -15,7 +16,7 @@ var ReqCmd = &cobra.Command{
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
c := &client.Client{
c := &ui.Client{
Config: ClientConfig,
}
defer c.Close()
Expand Down
10 changes: 5 additions & 5 deletions cliclient/cmd/root.go → cmd/sshi/root.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"fmt"
Expand All @@ -9,8 +9,8 @@ import (

"github.com/spf13/cobra"

"github.com/aakso/ssh-inscribe/pkg/client"
"github.com/aakso/ssh-inscribe/pkg/logging"
"github.com/aakso/ssh-inscribe/internal/logging"
"github.com/aakso/ssh-inscribe/internal/ui"
)

var RootCmd = &cobra.Command{
Expand All @@ -19,7 +19,7 @@ var RootCmd = &cobra.Command{
SilenceErrors: true,
SilenceUsage: true,
}
var ClientConfig = &client.Config{
var ClientConfig = &ui.Config{
UseAgent: true,
Timeout: 2 * time.Second,
Retries: 3,
Expand Down Expand Up @@ -173,7 +173,7 @@ func init() {
"Login to specific auth endpoints ($SSH_INSCRIBE_LOGIN_AUTH_ENDPOINTS)",
)
_ = RootCmd.RegisterFlagCompletionFunc("login", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
c := &client.Client{
c := &ui.Client{
Config: ClientConfig,
}
defer c.Close()
Expand Down
2 changes: 1 addition & 1 deletion cliclient/cmd/ssh.go → cmd/sshi/ssh.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"bufio"
Expand Down
9 changes: 5 additions & 4 deletions cliclient/cmd/version.go → cmd/sshi/version.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package cmd
package main

import (
"fmt"
"os"

"github.com/aakso/ssh-inscribe/pkg/client"
"github.com/aakso/ssh-inscribe/internal/ui"

"github.com/aakso/ssh-inscribe/pkg/globals"
"github.com/spf13/cobra"

"github.com/aakso/ssh-inscribe/internal/globals"
)

// versionCmd represents the version command
Expand All @@ -18,7 +19,7 @@ var versionCmd = &cobra.Command{
Args: cobra.NoArgs,
ValidArgsFunction: cobra.NoFileCompletions,
RunE: func(cmd *cobra.Command, args []string) error {
c := &client.Client{Config: ClientConfig}
c := &ui.Client{Config: ClientConfig}
fmt.Printf("local: %s\n", globals.Version())

if ClientConfig.URL == "" {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package authzfilter

import (
"github.com/sirupsen/logrus"
"github.com/aakso/ssh-inscribe/pkg/logging"

"github.com/aakso/ssh-inscribe/internal/logging"
)

var Log *logrus.Entry = logging.GetLogger("authzfilter").WithField("pkg", "auth/authz/authzfilter")
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package authzfilter

import (
"github.com/sirupsen/logrus"
"github.com/aakso/ssh-inscribe/pkg/auth"
"github.com/gobwas/glob"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/aakso/ssh-inscribe/internal/auth"
)

type PrincipalFilterConfig struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"

"github.com/aakso/ssh-inscribe/pkg/auth"
"github.com/aakso/ssh-inscribe/pkg/logging"
"github.com/aakso/ssh-inscribe/internal/auth"
"github.com/aakso/ssh-inscribe/internal/logging"
)

func authContext() *auth.AuthContext {
Expand Down
7 changes: 7 additions & 0 deletions internal/auth/backend/all/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package all

import (
_ "github.com/aakso/ssh-inscribe/internal/auth/backend/authfile"
_ "github.com/aakso/ssh-inscribe/internal/auth/backend/authldap"
_ "github.com/aakso/ssh-inscribe/internal/auth/backend/authoidc"
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (

"golang.org/x/crypto/bcrypt"

"github.com/sirupsen/logrus"
"github.com/aakso/ssh-inscribe/pkg/auth"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"

"github.com/aakso/ssh-inscribe/internal/auth"
)

type AuthFile struct {
Expand Down
Loading

0 comments on commit 13e30d2

Please sign in to comment.