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

Updated Privateer SDK to v0.0.7 #6

Merged
merged 3 commits into from
Aug 7, 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
19 changes: 13 additions & 6 deletions strikes/antijokes.go → armory/antijokes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package strikes
package armory

import (
"fmt"
Expand All @@ -11,16 +11,23 @@ import (
"github.com/privateerproj/privateer-sdk/utils"
)

// Conforms to the Armory interface type
type Antijokes struct {
Tactics map[string][]raidengine.Strike // Required, allows you to sort which strikes are run for each control
Log hclog.Logger // Recommended, allows you to set the log level for each log message
Results map[string]raidengine.StrikeResult // Optional, allows cross referencing between strikes
}

func (a *Antijokes) SetLogger(loggerName string) {
func (a *Antijokes) SetLogger(loggerName string) hclog.Logger {
a.Log = raidengine.GetLogger(loggerName, false)
return a.Log
}

// KnockKnock is a demo test for dev purposes
func (a *Antijokes) GetTactics() map[string][]raidengine.Strike {
return a.Tactics
}

// KnockKnock conforms to the Strike function type
func (a *Antijokes) KnockKnock() (strikeName string, result raidengine.StrikeResult) {
strikeName = "Knock Knock"
log.Print(strikeName) // Default logs will be set as INFO
Expand Down Expand Up @@ -56,7 +63,7 @@ func (a *Antijokes) KnockKnock() (strikeName string, result raidengine.StrikeRes
return
}

// ChickenCrossedRoad is a demo test for dev purposes
// ChickenCrossedRoad conforms to the Strike function type
func (a *Antijokes) ChickenCrossedRoad() (strikeName string, result raidengine.StrikeResult) {
// If a strike is part of multiple tactics, you can use a map to reference the control ID to the selected tactic
controlIDs := map[string]string{
Expand Down Expand Up @@ -109,7 +116,7 @@ func getJokerName() (result raidengine.MovementResult) {
return
}

// getJokerName is a common movement for the strikes in this raid
// getJokerName is a single movement for common use by the strikes in this raid
func getJokeeName() (result raidengine.MovementResult) {
result = raidengine.MovementResult{
Description: "JokeeName must be found in the runtime configuration.",
Expand All @@ -133,7 +140,7 @@ func RunKnockKnock(jokerName, jokeeName string, result *raidengine.StrikeResult)
Passed: true,
Description: "Joke must be started by the joker.",
Message: fmt.Sprintf("%s: Knock knock.", jokerName),
Function: utils.CallerPath(0),
Function: utils.CallerPath(0), // 0 logs the current function name
}
// say who's there
result.Movements["who's there"] = raidengine.MovementResult{
Expand Down
2 changes: 1 addition & 1 deletion cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
Use: "debug",
Short: "Run the Raid in debug mode",
Run: func(cmd *cobra.Command, args []string) {
err := raidengine.Run(RaidName, AvailableStrikes, Strikes)
err := raidengine.Run(RaidName, Armory)
if err != nil {
log.Fatal(err)
}
Expand Down
42 changes: 21 additions & 21 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,29 @@ import (

"github.com/spf13/cobra"

"github.com/privateerproj/privateer-pack-wireframe/strikes"
"github.com/privateerproj/privateer-pack-wireframe/armory"
"github.com/privateerproj/privateer-sdk/command"
"github.com/privateerproj/privateer-sdk/plugin"
"github.com/privateerproj/privateer-sdk/raidengine"
)

// Raid makes the correlated raidengine struct available to the plugin
type Raid struct {
}

var (
// Build information is added by the Makefile at compile time
buildVersion string
buildGitCommitHash string
buildTime string

RaidName = "Wireframe" // TODO: Change this to the name of your Raid
Strikes = &strikes.Antijokes{}

AvailableStrikes = map[string][]raidengine.Strike{
"CCC-Taxonomy": {
Strikes.KnockKnock,
Strikes.ChickenCrossedRoad,
},
"CCC-Hardening": {
Strikes.ChickenCrossedRoad,
},
"CIS": {
Strikes.ChickenCrossedRoad,
},
}
Armory = &armory.Antijokes{}

// runCmd represents the base command when called without any subcommands
runCmd = &cobra.Command{
Use: RaidName,
Short: "TODO: Addd a brief description of your Raid here",
Short: "TODO: Add a brief description of your Raid here",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
command.InitializeConfig()
},
Expand Down Expand Up @@ -66,11 +57,20 @@ func Execute(version, commitHash, builtAt string) {
}

func init() {
command.SetBase(runCmd) // This initializes the base CLI functionality
}
Armory.Tactics = map[string][]raidengine.Strike{
"CCC-Taxonomy": {
Armory.KnockKnock,
Armory.ChickenCrossedRoad,
},
"CCC-Hardening": {
Armory.ChickenCrossedRoad,
},
"CIS": {
Armory.ChickenCrossedRoad,
},
}

// Raid meets the Privateer Service Pack interface
type Raid struct {
command.SetBase(runCmd) // This initializes the base CLI functionality
}

// cleanupFunc is called when the plugin is stopped
Expand All @@ -83,5 +83,5 @@ func cleanupFunc() error {
// Adding raidengine.SetupCloseHandler(cleanupFunc) will allow you to append custom cleanup behavior
func (r *Raid) Start() error {
raidengine.SetupCloseHandler(cleanupFunc)
return raidengine.Run(RaidName, AvailableStrikes, Strikes)
return raidengine.Run(RaidName, Armory)
}
23 changes: 20 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ module github.com/privateerproj/privateer-pack-wireframe
go 1.14

require (
github.com/hashicorp/go-hclog v1.2.0
github.com/privateerproj/privateer-sdk v0.0.5
github.com/spf13/cobra v1.4.0
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/go-hclog v1.5.0
github.com/jhump/protoreflect v1.15.3 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/privateerproj/privateer-sdk v0.0.7
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.17.0 // indirect
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)

// For Development Only
Expand Down
Loading
Loading