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

Custom promise types: Fixed outdated examples and some syntax / formatting / highlighting (3.21) #3244

Merged
merged 3 commits into from
Mar 1, 2024
Merged
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
24 changes: 12 additions & 12 deletions reference/promise-types/custom.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ from cfengine import PromiseModule, ValidationError


class GitPromiseTypeModule(PromiseModule):
def validate_promise(self, promiser, attributes):
def validate_promise(self, promiser, attributes, metadata):
if not promiser.startswith("/"):
raise ValidationError(f"File path '{promiser}' must be absolute")
for name, value in attributes.items():
Expand All @@ -131,7 +131,7 @@ class GitPromiseTypeModule(PromiseModule):
if name == "repo" and type(value) is not str:
raise ValidationError(f"'repo' must be string for git promise types")

def evaluate_promise(self, promiser, attributes):
def evaluate_promise(self, promiser, attributes, metadata):
if not promiser.startswith("/"):
raise ValidationError("File path must be absolute")

Expand Down Expand Up @@ -402,12 +402,12 @@ This is done so the agent can print the messages while the promise is evaluating
Log messages formatted like this must be before the JSON message, and it is optional.
You can also include log messages in the JSON data:

```
```json
{
"operation": "evaluate_promise",
"promiser": "/opt/cfengine/masterfiles",
"attributes": {
"repo": "https://github.com/cfengine/masterfiles"}
"repo": "https://github.com/cfengine/masterfiles"
},
"log": [
{
Expand All @@ -428,7 +428,7 @@ The JSON based protocol also supports the use of custom bodies.
Custom bodies are sent as JSON objects within the respective attribute.
The following is an example using the members attribute of the custom groups promise type:

```
```cf3
body members foo_members
{
include => { "alice", "bob" };
Expand All @@ -438,16 +438,16 @@ body members foo_members
bundle agent foo_group
{
groups:
"foo"
policy => "present",
members => foo_members;
"foo"
policy => "present",
members => foo_members;
}
```

The attributes from the above example would be sent like this:

```
"attributes": {
```json
{
"policy": "present",
"members": {
"include": ["alice", "bob"],
Expand All @@ -473,7 +473,7 @@ The value may contain anything (including `=` signs) except for newlines and zer

##### Example requests in line based protocol

```conf
```
cf-agent 3.16.0 v1

operation=validate_promise
Expand All @@ -494,7 +494,7 @@ log_level=info

##### Example response in line based protocol

```conf
```
git_promise_module 0.0.1 v1 line_based

operation=validate_promise
Expand Down
Loading