Skip to content

Commit e30b46a

Browse files
authored
Merge branch 'Skyworship' into feat/admission-request-creator
2 parents a9783ea + fccd7e1 commit e30b46a

13 files changed

Lines changed: 828 additions & 2 deletions

File tree

cmd/nfs/cat.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package nfs
2+
3+
import (
4+
"fmt"
5+
6+
log "github.com/sirupsen/logrus"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func init() {
11+
NFSCommand.AddCommand(CatCommand)
12+
}
13+
14+
var CatCommand = &cobra.Command{
15+
Use: "cat",
16+
Short: "cat nfs file",
17+
Long: "cat nfs file",
18+
PreRunE: NotInit,
19+
Run: func(cmd *cobra.Command, args []string) {
20+
if len(args) == 0 {
21+
return
22+
}
23+
for _, arg := range args {
24+
content, err := Client.Cat(arg)
25+
if err != nil {
26+
log.Error(err)
27+
continue
28+
}
29+
fmt.Println(string(content))
30+
}
31+
},
32+
}

cmd/nfs/ls.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package nfs
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
log "github.com/sirupsen/logrus"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var lsOpts struct {
12+
ListAll bool
13+
}
14+
15+
func init() {
16+
ListCommand.Flags().BoolVarP(&lsOpts.ListAll, "all", "a", false, "List all attrs")
17+
NFSCommand.AddCommand(ListCommand)
18+
}
19+
20+
var ListCommand = &cobra.Command{
21+
Use: "list",
22+
Aliases: []string{"ls"},
23+
Short: "list nfs directory",
24+
Long: "list nfs directory",
25+
PreRunE: NotInit,
26+
Run: func(cmd *cobra.Command, args []string) {
27+
if len(args) == 0 {
28+
args = []string{"."}
29+
}
30+
for _, arg := range args {
31+
entries, err := Client.ListDir(arg)
32+
if err != nil {
33+
log.Error(err)
34+
continue
35+
}
36+
37+
for _, entry := range entries {
38+
if lsOpts.ListAll {
39+
modeStr := entry.Mode().Perm().String()
40+
if entry.IsDir() {
41+
modeStr = strings.Replace(modeStr, "-", "d", 1)
42+
}
43+
if entry.Attr.IsSet {
44+
fmt.Printf("%s\t%d\t%d\t%d\t%s\t%s\n",
45+
modeStr, entry.Attr.Attr.UID, entry.Attr.Attr.GID,
46+
entry.Size(), entry.ModTime().Format("2006-01-02 15:04:05"), entry.Name())
47+
} else {
48+
49+
fmt.Printf("%s\t%d\t%s\t%s\n",
50+
modeStr, entry.Size(), entry.ModTime().Format("2006-01-02 15:04:05"), entry.Name())
51+
}
52+
} else {
53+
fmt.Printf("%s\n", entry.Name())
54+
}
55+
}
56+
}
57+
},
58+
}

cmd/nfs/mkdir.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package nfs
2+
3+
import (
4+
log "github.com/sirupsen/logrus"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
func init() {
9+
NFSCommand.AddCommand(MkdirCommand)
10+
}
11+
12+
var MkdirCommand = &cobra.Command{
13+
Use: "mkdir",
14+
Aliases: []string{"md"},
15+
Short: "create nfs directory",
16+
Long: "create nfs directory",
17+
PreRunE: NotInit,
18+
Run: func(cmd *cobra.Command, args []string) {
19+
if len(args) == 0 {
20+
log.Errorf("mkdir: missing argument")
21+
return
22+
}
23+
for _, arg := range args {
24+
err := Client.Mkdir(arg)
25+
if err != nil {
26+
log.Error(err)
27+
continue
28+
}
29+
log.Infof("mkdir %s success", arg)
30+
}
31+
},
32+
}

cmd/nfs/mv.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package nfs
2+
3+
import (
4+
log "github.com/sirupsen/logrus"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
func init() {
9+
NFSCommand.AddCommand(RenameCommand)
10+
}
11+
12+
var RenameCommand = &cobra.Command{
13+
Use: "rename [f1] [f2]",
14+
Short: "rename nfs file",
15+
Long: "rename nfs file",
16+
Aliases: []string{"mv"},
17+
PreRunE: NotInit,
18+
Run: func(cmd *cobra.Command, args []string) {
19+
if len(args) != 2 {
20+
log.Errorf("rename: missing arguments")
21+
return
22+
}
23+
err := Client.Rename(args[0], args[1])
24+
if err != nil {
25+
log.Error(err)
26+
return
27+
}
28+
log.Infof("rename %s to %s success\n", args[0], args[1])
29+
},
30+
}

cmd/nfs/nfs.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package nfs
2+
3+
import (
4+
"errors"
5+
6+
cmd "github.com/esonhugh/k8spider/cmd"
7+
"github.com/esonhugh/k8spider/pkg/nfs"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var Opts struct {
12+
Server string
13+
BasePath string
14+
15+
UID int
16+
GID int
17+
Hostname string
18+
}
19+
20+
var Client *nfs.NFSClient
21+
22+
func init() {
23+
NFSCommand.PersistentFlags().StringVarP(&Opts.Server, "server", "s", "", "nfs server")
24+
NFSCommand.PersistentFlags().StringVarP(&Opts.BasePath, "base-path", "b", "/", "base mount path")
25+
NFSCommand.PersistentFlags().IntVarP(&Opts.UID, "uid", "u", 0, "uid")
26+
NFSCommand.PersistentFlags().IntVarP(&Opts.GID, "gid", "g", 0, "gid")
27+
NFSCommand.PersistentFlags().StringVarP(&Opts.Hostname, "hostname", "H", "localhost", "hostname")
28+
cmd.RootCmd.AddCommand(NFSCommand)
29+
}
30+
31+
var NFSCommand = &cobra.Command{
32+
Use: "nfs",
33+
Short: "nfs is a nfs client command",
34+
Long: "nfs is a nfs client command",
35+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
36+
var err error
37+
Client, err = nfs.NewNFSClient(Opts.Server, Opts.BasePath, nfs.CustomAuth(Opts.Hostname, Opts.UID, Opts.GID))
38+
return err
39+
},
40+
Run: func(cmd *cobra.Command, args []string) {
41+
42+
},
43+
}
44+
45+
func NotInit(cmd *cobra.Command, args []string) error {
46+
if Client == nil {
47+
return errors.New("nfs client not initialized")
48+
}
49+
return nil
50+
}

cmd/nfs/rm.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package nfs
2+
3+
import (
4+
log "github.com/sirupsen/logrus"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var rmOpts struct {
9+
Force bool
10+
}
11+
12+
func init() {
13+
RemoveCommand.Flags().BoolVar(&rmOpts.Force, "force", false, "force remove")
14+
NFSCommand.AddCommand(RemoveCommand, RemoveDirCommand)
15+
}
16+
17+
var RemoveCommand = &cobra.Command{
18+
Use: "rm [f1] [f2] ...",
19+
Short: "remove nfs file",
20+
Long: "remove nfs file",
21+
Aliases: []string{"del", "delete"},
22+
PreRunE: NotInit,
23+
Run: func(cmd *cobra.Command, args []string) {
24+
if len(args) == 0 {
25+
log.Errorf("rm: missing arguments")
26+
return
27+
}
28+
for _, arg := range args {
29+
var err error
30+
if rmOpts.Force {
31+
err = Client.RemoveAll(arg)
32+
} else {
33+
err = Client.Remove(arg)
34+
}
35+
if err != nil {
36+
log.Error(err)
37+
continue
38+
}
39+
log.Infof("remove %s success\n", arg)
40+
}
41+
},
42+
}
43+
44+
var RemoveDirCommand = &cobra.Command{
45+
Use: "rmdir [dir1] [dir2] ...",
46+
Short: "remove nfs directory",
47+
Long: "remove nfs directory",
48+
Aliases: []string{"rmdir"},
49+
PreRunE: NotInit,
50+
Run: func(cmd *cobra.Command, args []string) {
51+
if len(args) == 0 {
52+
log.Errorf("rmdir: missing arguments")
53+
return
54+
}
55+
for _, arg := range args {
56+
err := Client.RemoveDir(arg)
57+
if err != nil {
58+
log.Error(err)
59+
continue
60+
}
61+
log.Infof("rmdir %s success\n", arg)
62+
}
63+
},
64+
}

cmd/nfs/upload.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package nfs
2+
3+
import (
4+
"path/filepath"
5+
6+
log "github.com/sirupsen/logrus"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
func init() {
11+
NFSCommand.AddCommand(UploadCommand)
12+
NFSCommand.AddCommand(DownloadCommand)
13+
}
14+
15+
var UploadCommand = &cobra.Command{
16+
Use: "upload localfile remotepath",
17+
Aliases: []string{"put"},
18+
Short: "upload file to nfs",
19+
Long: "upload file to nfs",
20+
PreRunE: NotInit,
21+
Run: func(cmd *cobra.Command, args []string) {
22+
var localfile, remotepath string
23+
switch len(args) {
24+
case 2:
25+
remotepath = args[1]
26+
fallthrough
27+
case 1:
28+
localfile = filepath.Clean(args[0])
29+
if remotepath == "" {
30+
remotepath = localfile
31+
}
32+
default:
33+
log.Errorf("usage: nfs upload localfile [remotepath]")
34+
}
35+
if err := Client.Upload(localfile, remotepath); err != nil {
36+
log.Errorf("upload %s to %s failed: %v", localfile, remotepath, err)
37+
return
38+
}
39+
log.Infof("upload %s to %s success", localfile, remotepath)
40+
},
41+
}
42+
43+
var DownloadCommand = &cobra.Command{
44+
Use: "download remotefile localpath",
45+
Aliases: []string{"get"},
46+
Short: "download file from nfs",
47+
Long: "download file from nfs",
48+
PreRunE: NotInit,
49+
Run: func(cmd *cobra.Command, args []string) {
50+
var remotefile, localpath string
51+
switch len(args) {
52+
case 2:
53+
localpath = args[1]
54+
fallthrough
55+
case 1:
56+
remotefile = filepath.Clean(args[0])
57+
if localpath == "" {
58+
localpath = filepath.Base(remotefile)
59+
}
60+
default:
61+
log.Errorf("usage: nfs download remotefile [localpath]")
62+
}
63+
if err := Client.Download(remotefile, localpath); err != nil {
64+
log.Errorf("download %s to %s failed: %v", remotefile, localpath, err)
65+
return
66+
}
67+
log.Infof("download %s to %s success", remotefile, localpath)
68+
},
69+
}

cmd/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ func init() {
7777
RootCmd.PersistentFlags().StringSliceVarP(&Opts.FilterStrings, "filter-strings", "f", []string{}, "filter contained strings")
7878

7979
RootCmd.PersistentFlags().IntVarP(&Opts.Latency, "latency", "l", 0, "Latency control while each dns query in ms, default 0ms")
80-
// Set Log Levels
81-
SetLogLevel(Opts.Verbose)
80+
// Don't sort the flag order
81+
RootCmd.PersistentFlags().SortFlags = false
8282
}
8383

8484
var RootCmd = &cobra.Command{
8585
Use: "k8spider",
8686
Short: "k8spider is a tool to discover k8s services",
8787
Long: "k8spider is Powerful+Fast+Low Privilege Kubernetes service discovery tools via kubernetes DNS service. Currently supported service ip-port BruteForcing / AXFR Domain Transfer Dump / Coredns WildCard Dump / Pod Verified IP discovery\n\nTopics\n",
8888
PersistentPreRun: func(cmd *cobra.Command, args []string) {
89+
SetLogLevel(Opts.Verbose)
8990
// Set pkg global config
9091
pkg.Zone = Opts.Zone
9192

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ toolchain go1.23.4
77
require (
88
github.com/elastic/go-grok v0.3.1
99
github.com/guonaihong/gout v0.3.10
10+
github.com/go-nfs/nfsv3 v0.0.3
1011
github.com/miekg/dns v1.1.58
1112
github.com/sirupsen/logrus v1.9.0
1213
github.com/spf13/cobra v1.5.0
@@ -38,6 +39,7 @@ require (
3839
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3940
github.com/modern-go/reflect2 v1.0.2 // indirect
4041
github.com/pkg/errors v0.9.1 // indirect
42+
github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93 // indirect
4143
github.com/spf13/pflag v1.0.5 // indirect
4244
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
4345
github.com/x448/float16 v0.8.4 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4646
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
4747
github.com/guonaihong/gout v0.3.10 h1:1rKx/adBzoiw70jr9Wm2YiIxYtrffKDE6Oux49dBS74=
4848
github.com/guonaihong/gout v0.3.10/go.mod h1:wDXeuyeZR6MtaHbytO9RLcKW4iCDrWD6/KF1QwDtbRc=
49+
github.com/go-nfs/nfsv3 v0.0.3 h1:YOBa1PHAEzpQ26lXbTy8yHlvmr3VnQtKb9BwKfNtjU4=
50+
github.com/go-nfs/nfsv3 v0.0.3/go.mod h1:ofJyXGrEZwQlMB1lR+1daUzR/5jl6jdWlzFmnAcBWQc=
4951
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
5052
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
5153
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
@@ -78,6 +80,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
7880
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7981
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
8082
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
83+
github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93 h1:UVArwN/wkKjMVhh2EQGC0tEc1+FqiLlvYXY5mQ2f8Wg=
84+
github.com/rasky/go-xdr v0.0.0-20170124162913-1a41d1a06c93/go.mod h1:Nfe4efndBz4TibWycNE+lqyJZiMX4ycx+QKV8Ta0f/o=
8185
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
8286
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
8387
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=

0 commit comments

Comments
 (0)