forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Introduced new run command that lets users start an instance of OPA. - Added basic REPL as first mode that can be run, server mode coming soon. - Extended Storage to support a JSON Patch like interface.
- Loading branch information
Showing
422 changed files
with
64,506 additions
and
125,988 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,3 +1,4 @@ | ||
.DS_Store | ||
.vscode | ||
opa | ||
opalog/parser.go | ||
|
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,65 @@ | ||
// Copyright 2016 The OPA Authors. All rights reserved. | ||
// Use of this source code is governed by an Apache2 | ||
// license that can be found in the LICENSE file. | ||
|
||
package cmd | ||
|
||
import ( | ||
"os" | ||
"path" | ||
|
||
"github.com/open-policy-agent/opa/runtime" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// default filename for the interactive shell's history | ||
var defaultHistoryFile = ".opa_history" | ||
|
||
func init() { | ||
|
||
params := &runtime.Params{} | ||
|
||
runCommand := &cobra.Command{ | ||
Use: "run", | ||
Short: "Start OPA in interative or server mode", | ||
Long: `Start an instance of the Open Policy Agent (OPA). | ||
The 'run' command starts an instance of the OPA runtime. The OPA | ||
runtime can be started as an interactive shell or a server. | ||
When the runtime is started as a shell, users can define rules and | ||
evaluate expressions interactively. When the runtime is started as | ||
a server, users can access OPA's APIs via HTTP. | ||
The runtime can be initialized with one or more JSON files that | ||
represent base documents. | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
params.BaseDocPaths = args | ||
rt := &runtime.Runtime{} | ||
rt.Start(params) | ||
}, | ||
} | ||
|
||
runCommand.Flags().BoolVarP(¶ms.Server, "server", "s", false, "start the runtime in server mode") | ||
runCommand.Flags().StringVarP(¶ms.HistoryPath, "history", "H", historyPath(), "set path of history file") | ||
|
||
usageTemplate := `Usage: | ||
{{.UseLine}} [flags] [files] | ||
Flags: | ||
{{.LocalFlags.FlagUsages | trimRightSpace}} | ||
` | ||
|
||
runCommand.SetUsageTemplate(usageTemplate) | ||
|
||
RootCommand.AddCommand(runCommand) | ||
} | ||
|
||
func historyPath() string { | ||
home := os.Getenv("HOME") | ||
if len(home) == 0 { | ||
return defaultHistoryFile | ||
} | ||
return path.Join(home, defaultHistoryFile) | ||
} |
Oops, something went wrong.