2021-01-16 16:34:50 +00:00
|
|
|
package main
|
2021-01-13 20:38:52 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"gitlab.com/inetmock/inetmock/internal/rpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
addFileCmd = &cobra.Command{
|
|
|
|
Use: "addFile",
|
|
|
|
Short: "subscribe events to a file",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: runAddFile,
|
|
|
|
}
|
|
|
|
|
|
|
|
removeFileCmd = &cobra.Command{
|
|
|
|
Use: "removeFile",
|
|
|
|
Short: "remove file subscription",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: runRemoveFile,
|
|
|
|
}
|
2021-01-18 17:35:13 +00:00
|
|
|
|
|
|
|
readFileCmd = &cobra.Command{
|
|
|
|
Use: "readFile",
|
|
|
|
Short: "reads an audit file and prints the events",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
RunE: runReadFile,
|
|
|
|
}
|
2021-01-13 20:38:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func runAddFile(_ *cobra.Command, args []string) (err error) {
|
|
|
|
var conn *grpc.ClientConn
|
|
|
|
|
|
|
|
if conn, err = grpc.Dial(inetMockSocketPath, grpc.WithInsecure()); err != nil {
|
|
|
|
fmt.Printf("Failed to connecto INetMock socket: %v\n", err)
|
|
|
|
os.Exit(10)
|
|
|
|
}
|
|
|
|
|
|
|
|
auditClient := rpc.NewAuditClient(conn)
|
2021-01-18 17:35:13 +00:00
|
|
|
ctx, cancel := context.WithTimeout(cliApp.Context(), grpcTimeout)
|
2021-01-13 20:38:52 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
_, err = auditClient.RegisterFileSink(ctx, &rpc.RegisterFileSinkRequest{TargetPath: args[0]})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func runRemoveFile(_ *cobra.Command, args []string) (err error) {
|
|
|
|
auditClient := rpc.NewAuditClient(conn)
|
2021-01-18 17:35:13 +00:00
|
|
|
ctx, cancel := context.WithTimeout(cliApp.Context(), grpcTimeout)
|
2021-01-13 20:38:52 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
_, err = auditClient.RemoveFileSink(ctx, &rpc.RemoveFileSinkRequest{TargetPath: args[0]})
|
|
|
|
return
|
|
|
|
}
|
2021-01-18 17:35:13 +00:00
|
|
|
|
|
|
|
func runReadFile(_ *cobra.Command, args []string) (err error) {
|
|
|
|
return
|
|
|
|
}
|