mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
docs: explain how to use the SDK without a initialising a server (#8248)
It's possible to read in policies from the filesystem, but there's no detail on how to do this in the current documentation. Adding this provides more information for use cases where features of the server (e.g. dynamic bundle loading) are not important to the user. Signed-off-by: Andrew Sims <andrew@flip.com.au>
This commit is contained in:
@@ -269,6 +269,34 @@ Setting an `ID` in `sdk.Options` is optional, but recommended. If you do not set
|
||||
for the system. While this is fine for testing, it makes it difficult to monitor the system over time, as a new ID will
|
||||
be created each time the SDK is initialized, such as when the process is restarted.
|
||||
|
||||
#### Using the SDK client without a server
|
||||
|
||||
You might want to use the high-level SDK to load policy from the filesystem instead of a bundle server.
|
||||
This can be useful if you do not have a bundle server, or you ship policy with the application using the SDK.
|
||||
In that case, you can use the SDK as normal, but modify the configuration to use a file scheme and path, instead of a HTTP server resource path.
|
||||
You will also not need to include any services in the configuration:
|
||||
|
||||
```go
|
||||
bundleFilePath, err := filepath.Abs("./policy")
|
||||
if err != nil {
|
||||
// handle error
|
||||
}
|
||||
|
||||
// provide an absolute path to the location of the policy files
|
||||
config := []byte(fmt.Sprintf(`{
|
||||
"bundles": {
|
||||
"test": {
|
||||
"resource": "file://%s"
|
||||
}
|
||||
},
|
||||
"decision_logs": {
|
||||
"console": true
|
||||
}
|
||||
}`, bundleFilePath))
|
||||
|
||||
// create an instance of the OPA object and use it to get policy decisions as normal.
|
||||
```
|
||||
|
||||
#### Manually Triggering Bundle Reloads
|
||||
|
||||
Users of the SDK can
|
||||
|
||||
Reference in New Issue
Block a user