-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support added for configuration of OCSF extensions and profiles throu…
…gh new `config` command.
- Loading branch information
Showing
16 changed files
with
298 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
output | ||
bin | ||
ocsf-schema.json | ||
download/ocsf-tool/ | ||
ocsf-schema-*.json | ||
download/ocsf-tool/ | ||
config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package commands | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/valllabh/ocsf-tool/config" | ||
) | ||
|
||
// Define the setConfig command | ||
var configCmd = &cobra.Command{ | ||
Use: `config <extensions|profiles> values...`, | ||
Short: `Set configuration values for extensions and profiles`, | ||
Example: ` | ||
ocsf-tool config extensions linux win | ||
ocsf-tool config profiles cloud linux/linux_users | ||
`, | ||
Long: ` | ||
Set configuration values for extensions and profiles | ||
Possible values for Extensions https://schema.ocsf.io/1.0.0/ | ||
Possible values for Profiles https://schema.ocsf.io/1.0.0/profiles/ | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Check if the number of args is less than 2 | ||
if len(args) < 2 { | ||
println("Invalid number of arguments") | ||
// print help | ||
cmd.Help() | ||
return | ||
} | ||
|
||
// Extract the variable and values from the args | ||
variable, values := args[0], args[1:] | ||
|
||
// validate variable | ||
if variable != "extensions" && variable != "profiles" { | ||
println("Invalid variable name. Possible values are [extensions, profiles].") | ||
return | ||
} | ||
|
||
// set the config value | ||
viper.Set(variable, values) | ||
|
||
// Write the config file to disk | ||
config.WriteConfig() | ||
}, | ||
} | ||
|
||
func init() { | ||
// Add the setConfig command to the root command | ||
rootCmd.AddCommand(configCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
func getConfigFilePath() string { | ||
return "config.yaml" | ||
} | ||
|
||
// initConfig reads in config file and ENV variables if set. | ||
func InitConfig() { | ||
|
||
viper.SetConfigName("config") | ||
viper.SetConfigType("yaml") | ||
viper.AddConfigPath(".") | ||
|
||
// Read in environment variables that match | ||
err := viper.ReadInConfig() | ||
|
||
// Handle errors reading the config file | ||
if err != nil { | ||
if _, ok := err.(viper.ConfigFileNotFoundError); ok { | ||
// Config file not found; create it with default values | ||
viper.WriteConfigAs(getConfigFilePath()) // handle error | ||
} else { | ||
// Config file was found but another error was produced | ||
panic(fmt.Errorf("fatal error config file: %s", err)) | ||
} | ||
} | ||
} | ||
|
||
// Write config file to disk | ||
func WriteConfig() { | ||
err := viper.WriteConfigAs(getConfigFilePath()) | ||
|
||
// Handle errors writing the config file | ||
if err != nil { | ||
panic(fmt.Errorf("fatal error config file: %s", err)) | ||
} | ||
|
||
println("Config saved.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## ocsf-tool config | ||
|
||
Set configuration values for extensions and profiles | ||
|
||
### Synopsis | ||
|
||
|
||
Set configuration values for extensions and profiles | ||
Possible values for Extensions https://schema.ocsf.io/1.0.0/ | ||
Possible values for Profiles https://schema.ocsf.io/1.0.0/profiles/ | ||
|
||
|
||
``` | ||
ocsf-tool config <extensions|profiles> values... [flags] | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
ocsf-tool config extensions linux win | ||
ocsf-tool config profiles cloud linux/linux_users | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for config | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [ocsf-tool](ocsf-tool.md) - | ||
|
||
###### Auto generated by spf13/cobra on 10-Nov-2023 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.