Skip to content

Commit 16dc5e9

Browse files
committed
General updates along with a bugfix where slower IO will cause the removal of accounts to fail
1 parent 6a70c6f commit 16dc5e9

15 files changed

+458
-199
lines changed

.gitignore

100644100755
+3-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ dist/*
1717
*.out
1818
vendor/
1919
*.tar.gz
20-
build.sh
20+
github.com/
21+
golang.org/
22+
gopkg.in/

.gitmodules

100644100755
File mode changed.

.goreleaser.yml

100644100755
File mode changed.

CHANGELOG.md

100644100755
+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,4 @@
22

33
## [2.0.0] - 2020-07-20
44
### Added
5-
- New release system using Go Releaser
6-
- Support for Server Monitoring Added
7-
- Reworked the codebase to move to using Go Modules
8-
5+
- New release system

LICENSE

100644100755
File mode changed.

README.md

100644100755
File mode changed.

cmd/add.go

100644100755
File mode changed.

cmd/monitor.go

100644100755
File mode changed.

cmd/remove.go

100644100755
+15-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ package cmd
2323

2424
import (
2525
"os/user"
26-
26+
"fmt"
27+
"time"
2728
"github.com/fatih/color"
2829
"github.com/spf13/cobra"
2930
"github.com/spf13/viper"
@@ -42,6 +43,13 @@ var removeCmd = &cobra.Command{
4243
return
4344
}
4445

46+
// Sleep for 1 second.
47+
time.Sleep(1 * time.Second)
48+
49+
if err := viper.ReadInConfig(); err != nil {
50+
fmt.Println("Failed to read the config file:", viper.ConfigFileUsed())
51+
}
52+
4553
// Load existing accounts from config
4654
var accounts []Account
4755
configErr := viper.UnmarshalKey("accounts", &accounts)
@@ -50,6 +58,7 @@ var removeCmd = &cobra.Command{
5058
panic("There was a problem setting up the user account. Please try again or contact ServerAuth for assistance")
5159
}
5260

61+
5362
// Remove the account and update the config
5463
// Loop over accounts and search for the username
5564
var updatedAccounts []Account
@@ -61,6 +70,10 @@ var removeCmd = &cobra.Command{
6170

6271
// Save the updated accounts list
6372
viper.Set("accounts", updatedAccounts)
73+
74+
// Sleep for 1 second to allow the config to be written on slower systems
75+
time.Sleep(1 * time.Second)
76+
6477
viper.WriteConfig()
6578
color.Green("\nThe selected account has been removed from ServerAuth.")
6679
color.Green("\nThe authorized_keys file has been left in tact to allow you to manually update it.")
@@ -72,5 +85,5 @@ func init() {
7285

7386
// User flag
7487
removeCmd.Flags().StringVarP(&username, "username", "u", "", "The username of the system account to add to ServerAuth")
75-
removeCmd.MarkFlagRequired("user")
88+
removeCmd.MarkFlagRequired("username")
7689
}

cmd/root.go

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import (
3333
var cfgFile string
3434

3535
type Account struct {
36-
Username string
37-
ApiKey string
36+
Username string `yaml:"username"`
37+
ApiKey string `yaml:"apiKey"`
3838
}
3939

4040
var keysFileTemplate = []byte(`# This file is managed by ServerAuth.\n

cmd/sync.go

100644100755
File mode changed.

go.mod

+32-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1-
module github.com/serverauth-com/serverauth-agent/v2
1+
module github.com/serverauth-com/serverauth-agent
22

3-
go 1.14
3+
go 1.17
44

5-
require github.com/fatih/color v1.9.0
6-
7-
require github.com/spf13/cobra v1.0.0
5+
require (
6+
github.com/fatih/color v1.15.0
7+
github.com/fsnotify/fsnotify v1.6.0
8+
github.com/mattn/go-colorable v0.1.13
9+
github.com/mattn/go-isatty v0.0.19
10+
github.com/shirou/gopsutil v3.21.11+incompatible
11+
github.com/spf13/cobra v1.7.0
12+
github.com/spf13/pflag v1.0.5
13+
github.com/spf13/viper v1.16.0
14+
github.com/stretchr/testify v1.8.4
15+
github.com/subosito/gotenv v1.4.2
16+
golang.org/x/sys v0.10.0
17+
)
818

919
require (
10-
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
11-
github.com/go-ole/go-ole v1.2.4 // indirect
12-
github.com/shirou/gopsutil v2.20.6+incompatible
13-
github.com/spf13/viper v1.7.0
14-
golang.org/x/sys v0.0.0-20200316230553-a7d97aace0b0 // indirect
20+
github.com/davecgh/go-spew v1.1.1 // indirect
21+
github.com/go-ole/go-ole v1.2.6 // indirect
22+
github.com/hashicorp/hcl v1.0.0 // indirect
23+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
24+
github.com/magiconair/properties v1.8.7 // indirect
25+
github.com/mitchellh/mapstructure v1.5.0 // indirect
26+
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
27+
github.com/pmezard/go-difflib v1.0.0 // indirect
28+
github.com/spf13/afero v1.9.5 // indirect
29+
github.com/spf13/cast v1.5.1 // indirect
30+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
31+
github.com/tklauser/go-sysconf v0.3.11 // indirect
32+
github.com/tklauser/numcpus v0.6.0 // indirect
33+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
34+
golang.org/x/text v0.9.0 // indirect
35+
gopkg.in/ini.v1 v1.67.0 // indirect
36+
gopkg.in/yaml.v3 v3.0.1 // indirect
1537
)

go.sum

+362-179
Large diffs are not rendered by default.

main.go

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ THE SOFTWARE.
2121
*/
2222
package main
2323

24-
import "github.com/serverauth-com/serverauth-agent/v2/cmd"
24+
import "github.com/serverauth-com/serverauth-agent/cmd"
2525

2626
func main() {
2727
cmd.Execute()

serverauth-release-build.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# /bin/bash
2+
3+
if [ ! -t 0 ]; then x-terminal-emulator -e "$0"; exit 0; fi
4+
echo "Before proceeding please ensure you have installed Golang. In addition this file should be run from the top level of the git repository."
5+
read -n1 -r -p "Press any key to start build process..." key
6+
echo "What version do you want to tag this as? Please use the format of x.x.x (e.g 1.1.0)"
7+
read version
8+
echo "Downloading required modules"
9+
go mod download
10+
11+
12+
go get github.com/fatih/color
13+
go get github.com/spf13/cobra
14+
go get github.com/spf13/viper
15+
16+
echo "Building Linux 64bit package"
17+
env GOOS=linux GOARCH=amd64 go build -o serverauth ./main.go
18+
echo "Creating archive of Linux 64bit package"
19+
tar zcvf serverauth-agent-v"$version"-linux-64bit.tar.gz ./serverauth
20+
21+
echo "Building Linux 32bit package"
22+
env GOOS=linux GOARCH=386 go build -o serverauth ./main.go
23+
echo "Creating archive of Linux 32bit package"
24+
tar zcvf serverauth-agent-v"$version"-linux-32bit.tar.gz ./serverauth
25+
26+
echo "Building Linux ARMv5 package"
27+
env GOOS=linux GOARCH=arm GOARM=5 go build -o serverauth ./main.go
28+
echo "Creating archive of Linux ARMv5 package"
29+
tar zcvf serverauth-agent-v"$version"-linux-armv5.tar.gz ./serverauth
30+
31+
echo "Building Linux ARMv6 package"
32+
env GOOS=linux GOARCH=arm GOARM=6 go build -o serverauth ./main.go
33+
echo "Creating archive of Linux ARMv6 package"
34+
tar zcvf serverauth-agent-v"$version"-linux-armv6.tar.gz ./serverauth
35+
36+
echo "Building Linux ARMv7 package"
37+
env GOOS=linux GOARCH=arm GOARM=7 go build -o serverauth ./main.go
38+
echo "Creating archive of Linux ARMv7 package"
39+
tar zcvf serverauth-agent-v"$version"-linux-armv6.tar.gz ./serverauth
40+
41+
42+
echo "The ServerAuth release files have been created. These can now be added to the release"

0 commit comments

Comments
 (0)