-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
spoc
, the Security Profiles Operator CLI
We discussed in our last sync meeting that it would be helpful to have a slimmer SPO CLI for faster execution in edge scenarios. For that we would need a new binary, which can be used to directly interact with features like the ebpf recorder. Refers to #1482 Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
- Loading branch information
1 parent
c26a139
commit 089652b
Showing
8 changed files
with
153 additions
and
37 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
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,67 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
"sigs.k8s.io/security-profiles-operator/internal/pkg/version" | ||
) | ||
|
||
const jsonFlag string = "json" | ||
|
||
func DefaultApp() (*cli.App, *version.Info) { | ||
app := cli.NewApp() | ||
|
||
info, err := version.Get() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
app.Version = info.Version | ||
|
||
app.Commands = cli.Commands{ | ||
&cli.Command{ | ||
Name: "version", | ||
Aliases: []string{"v"}, | ||
Usage: "display detailed version information", | ||
Flags: []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: jsonFlag, | ||
Aliases: []string{"j"}, | ||
Usage: "print JSON instead of text", | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
res := info.String() | ||
if c.Bool(jsonFlag) { | ||
j, err := info.JSONString() | ||
if err != nil { | ||
return fmt.Errorf("unable to generate JSON from version info: %w", err) | ||
} | ||
res = j | ||
} | ||
print(res) | ||
return nil | ||
}, | ||
}, | ||
} | ||
|
||
return app, info | ||
} |
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,44 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/urfave/cli/v2" | ||
|
||
"sigs.k8s.io/security-profiles-operator/cmd" | ||
) | ||
|
||
func main() { | ||
app, _ := cmd.DefaultApp() | ||
app.Usage = "Security Profiles Operator CLI" | ||
|
||
app.Commands = append(app.Commands, | ||
&cli.Command{ | ||
Name: "record", | ||
Aliases: []string{"r"}, | ||
Usage: "run the recorder", | ||
Action: record, | ||
}, | ||
) | ||
|
||
if err := app.Run(os.Args); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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,24 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import "github.com/urfave/cli/v2" | ||
|
||
// record runs the `spoc record` subcommand. | ||
func record(ctx *cli.Context) error { | ||
return nil | ||
} |
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