-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add rego-antora-extension
- Loading branch information
Showing
18 changed files
with
433 additions
and
7 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
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 @@ | ||
include::partial$main_nav.adoc[] | ||
include::partial$cli_nav.adoc[] | ||
include::partial$tasks_nav.adoc[] | ||
include::partial$tasks_nav.adoc[] | ||
include::partial$rego_nav.adoc[] |
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,6 @@ | ||
= ec rego functions reference documentation | ||
|
||
The EC CLI provides custom rego builtin functions in addition to the | ||
https://www.openpolicyagent.org/docs/latest/policy-reference/#built-in-functions[default ones]. | ||
|
||
Use the navigation bar to view the documenation for each function. |
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,4 @@ | ||
* xref:rego.adoc[Rego Reference] | ||
{{#each reference}} | ||
** xref:{{ path }}[{{ name }}] | ||
{{/each}} |
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 @@ | ||
= {{ name }} | ||
|
||
{{{ description}}} | ||
|
||
== Usage | ||
|
||
{{ decl.result.name }} = {{ name }}({{pluck decl.args 'name' ', '}}) | ||
|
||
== Parameters | ||
|
||
{{#each decl.args}} | ||
* ``{{ name }}`` (``{{ type }}``): {{ description }} | ||
{{/each}} | ||
|
||
== Return | ||
|
||
``{{ decl.result.name }}`` (``{{ decl.result.type }}``): {{ decl.result.description }} | ||
|
||
{{#if decl.result.static}} | ||
The object contains the following attributes: | ||
|
||
{{{ describe decl.result 1 }}} | ||
|
||
{{/if}} |
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
77 changes: 77 additions & 0 deletions
77
internal/evaluator/documentation/__snapshots__/documentation_test.snap
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,77 @@ | ||
|
||
[TestWriteBuiltinsToYAML - 1] | ||
decl: | ||
args: | ||
- description: OCI blob reference | ||
name: ref | ||
type: string | ||
result: | ||
description: the OCI blob | ||
name: blob | ||
type: string | ||
type: function | ||
description: Fetch a blob from an OCI registry. | ||
name: ec.oci.blob | ||
nondeterministic: true | ||
|
||
--- | ||
|
||
[TestWriteBuiltinsToYAML - 2] | ||
decl: | ||
args: | ||
- description: the PURL | ||
name: purl | ||
type: string | ||
result: | ||
description: PURL validity | ||
name: result | ||
type: string | ||
type: function | ||
description: Determine whether or not a given PURL is valid. | ||
name: ec.purl.is_valid | ||
|
||
--- | ||
|
||
[TestWriteBuiltinsToYAML - 3] | ||
decl: | ||
args: | ||
- description: the PURL | ||
name: purl | ||
type: string | ||
result: | ||
description: the parsed PURL object | ||
name: object | ||
static: | ||
- key: name | ||
value: | ||
type: string | ||
- key: namespace | ||
value: | ||
type: string | ||
- key: qualifiers | ||
value: | ||
dynamic: | ||
static: | ||
- key: key | ||
value: | ||
type: string | ||
- key: value | ||
value: | ||
type: string | ||
type: object | ||
type: array | ||
- key: subpath | ||
value: | ||
type: string | ||
- key: type | ||
value: | ||
type: string | ||
- key: version | ||
value: | ||
type: string | ||
type: object | ||
type: function | ||
description: Parse a valid PURL into an object. | ||
name: ec.purl.parse | ||
|
||
--- |
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,71 @@ | ||
// Copyright The Enterprise Contract Contributors | ||
// | ||
// 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. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"path" | ||
"strings" | ||
|
||
"github.com/open-policy-agent/opa/ast" | ||
"sigs.k8s.io/yaml" | ||
|
||
_ "github.com/enterprise-contract/ec-cli/internal/evaluator" // imports EC OPA builtins | ||
) | ||
|
||
const directoryPermissions = 0755 | ||
const filePermissions = 0644 | ||
|
||
var yamlDir = flag.String("yaml", "", "Location of the generated YAML files") | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
if err := writeBultinsToYAML(*yamlDir); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func writeBultinsToYAML(dir string) error { | ||
if (dir) == "" { | ||
dir = "rego-docs" | ||
} | ||
|
||
if err := os.MkdirAll(dir, directoryPermissions); err != nil { | ||
return err | ||
} | ||
|
||
for _, builtin := range ast.Builtins { | ||
// We only care about the builtins provided by EC. | ||
if !strings.HasPrefix(builtin.Name, "ec.") { | ||
continue | ||
} | ||
data, err := yaml.Marshal(builtin) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
filename := path.Join(dir, fmt.Sprintf("%s.yaml", builtin.Name)) | ||
if err := os.WriteFile(filename, data, filePermissions); err != nil { | ||
return err | ||
} | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright The Enterprise Contract Contributors | ||
// | ||
// 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. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build unit | ||
|
||
package main | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/gkampitakis/go-snaps/snaps" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWriteBuiltinsToYAML(t *testing.T) { | ||
dir := t.TempDir() | ||
err := writeBultinsToYAML(dir) | ||
require.NoError(t, err) | ||
err = filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { | ||
require.NoError(t, err) | ||
if d.IsDir() { | ||
return nil | ||
} | ||
contents, err := os.ReadFile(path) | ||
require.NoError(t, err) | ||
snaps.MatchSnapshot(t, string(contents)) | ||
return nil | ||
}) | ||
require.NoError(t, 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
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 @@ | ||
//registry.npmjs.org/:_authToken=${NPM_TOKEN} |
Oops, something went wrong.