Skip to content

Commit

Permalink
Update JSON schemas for all plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
pkosiec committed Dec 4, 2023
1 parent aec0dd9 commit 4758e19
Show file tree
Hide file tree
Showing 30 changed files with 831 additions and 504 deletions.
41 changes: 3 additions & 38 deletions cmd/executor/exec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ func (*XExecutor) Metadata(context.Context) (api.MetadataOutput, error) {
Version: version,
Description: "Install and run CLIs directly from chat window without hassle. All magic included.",
Dependencies: x.GetPluginDependencies(),
JSONSchema: jsonSchema(),
JSONSchema: api.JSONSchema{
Value: heredoc.Docf(x.ConfigJSONSchemaFmt, getDefaultTemplateSource()),
},
}, nil
}

Expand Down Expand Up @@ -205,43 +207,6 @@ func main() {
})
}

// jsonSchema returns JSON schema for the executor.
func jsonSchema() api.JSONSchema {
return api.JSONSchema{
Value: heredoc.Docf(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "exec",
"description": "Install and run CLIs directly from the chat window without hassle. All magic included.",
"type": "object",
"properties": {
"templates": {
"type": "array",
"title": "List of templates",
"description": "An array of templates that define how to convert the command output into an interactive message.",
"items": {
"type": "object",
"properties": {
"ref": {
"title": "Link to templates source",
"description": "It uses the go-getter library, which supports multiple URL formats (such as HTTP, Git repositories, or S3) and is able to unpack archives. For more details, see the documentation at https://github.com/hashicorp/go-getter.",
"type": "string",
"default": "%s"
}
},
"required": [
"ref"
],
"additionalProperties": false
}
}
},
"required": [
"templates"
]
}`, getDefaultTemplateSource()),
}
}

func getDefaultTemplateSource() string {
ver := version
if ver == "dev" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/executor/thread-mate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (*ThreadMateExecutor) Metadata(context.Context) (api.MetadataOutput, error)
Version: version,
Description: "Streamlines managing assignment for incidents or user support",
JSONSchema: api.JSONSchema{
Value: thmate.JSONSchema,
Value: thmate.ConfigJSONSchema,
},
}, nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "doctor",
"title": "Doctor",
"description": "Doctor is a ChatGPT integration project that knows how to diagnose Kubernetes problems and suggest solutions.",
"type": "object",
"uiSchema": {
"apiKey": {
"ui:widget": "password"
}
},
"properties": {
"apiKey": {
"description": "OpenAI Secret API Key",
Expand Down Expand Up @@ -85,5 +90,6 @@
},
"required": [
"apiKey"
]
],
"additionalProperties": false
}
2 changes: 1 addition & 1 deletion internal/executor/doctor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
)

var (
//go:embed config-jsonschema.json
//go:embed config_schema.json
configJSONSchema string
k8sPromptRegex = regexp.MustCompile(`--(\w+)=([^\s]+)`)
)
Expand Down
4 changes: 3 additions & 1 deletion internal/executor/flux/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
// Config holds Flux executor configuration.
type Config struct {
Logger config.Logger `yaml:"log"`
TmpDir plugin.TmpDir `yaml:"tmpDir"`
GitHub struct {
Auth struct {
// The GitHub access token.
Expand All @@ -17,4 +16,7 @@ type Config struct {
AccessToken string `yaml:"accessToken"`
} `yaml:"auth"`
} `yaml:"github"`

// Fields not exposed to the user in the JSON schema
TmpDir plugin.TmpDir `yaml:"tmpDir"`
}
85 changes: 85 additions & 0 deletions internal/executor/flux/config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Flux",
"description": "Run the Flux CLI commands directly from your favorite communication platform.",
"type": "object",
"uiSchema": {
"github": {
"auth": {
"accessToken": {
"ui:widget": "password"
}
}
}
},
"properties": {
"github": {
"title": "GitHub",
"type": "object",
"properties": {
"auth": {
"title": "Auth",
"type": "object",
"properties": {
"accessToken": {
"title": "Access Token",
"description": "Instructions for token creation: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/#creating-a-token. When not provided some functionality may not work, e.g., adding comments to pull requests or approving them.",
"type": "string"
}
}
}
}
},
"log": {
"title": "Logging",
"description": "Logging configuration for the plugin.",
"type": "object",
"properties": {
"level": {
"title": "Log Level",
"description": "Define log level for the plugin. Ensure that Botkube has plugin logging enabled for standard output.",
"type": "string",
"default": "info",
"oneOf": [
{
"const": "panic",
"title": "Panic"
},
{
"const": "fatal",
"title": "Fatal"
},
{
"const": "error",
"title": "Error"
},
{
"const": "warn",
"title": "Warning"
},
{
"const": "info",
"title": "Info"
},
{
"const": "debug",
"title": "Debug"
},
{
"const": "trace",
"title": "Trace"
}
]
},
"disableColors": {
"type": "boolean",
"default": false,
"description": "If enabled, disables color logging output.",
"title": "Disable Colors"
}
}
}
},
"required": [],
"additionalProperties": true
}
9 changes: 6 additions & 3 deletions internal/executor/flux/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ import (
"github.com/kubeshop/botkube/pkg/pluginx"
)

//go:embed jsonschema.json
var jsonschema string
var (
//go:embed config_schema.json
// some of the fields are not exposed, so "additionalProperties" is set to true
configJSONSchema string
)

const (
PluginName = "flux"
Expand Down Expand Up @@ -48,7 +51,7 @@ func (d *Executor) Metadata(context.Context) (api.MetadataOutput, error) {
DocumentationURL: "https://docs.botkube.io/configuration/executor/flux",
Dependencies: getPluginDependencies(),
JSONSchema: api.JSONSchema{
Value: jsonschema,
Value: configJSONSchema,
},
}, nil
}
Expand Down
35 changes: 0 additions & 35 deletions internal/executor/flux/jsonschema.json

This file was deleted.

8 changes: 5 additions & 3 deletions internal/executor/helm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ const defaultNamespace = "default"

// Config holds Helm plugin configuration parameters.
type Config struct {
HelmDriver string `yaml:"helmDriver,omitempty"`
HelmCacheDir string `yaml:"helmCacheDir,omitempty"`
HelmConfigDir string `yaml:"helmConfigDir,omitempty"`
DefaultNamespace string `yaml:"defaultNamespace,omitempty"`
HelmDriver string `yaml:"helmDriver,omitempty"`

// Fields not exposed to the user in the JSON schema
HelmCacheDir string `yaml:"helmCacheDir,omitempty"`
HelmConfigDir string `yaml:"helmConfigDir,omitempty"`
}

// Validate validates the Helm configuration parameters.
Expand Down
36 changes: 36 additions & 0 deletions internal/executor/helm/config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Helm",
"description": "Run the Helm CLI commands directly from your favorite communication platform.",
"type": "object",
"properties": {
"defaultNamespace": {
"title": "Default Kubernetes Namespace",
"description": "Namespace used if not explicitly specified during command execution.",
"type": "string",
"default": "default"
},
"helmDriver": {
"title": "Storage driver",
"description": "Storage driver for Helm.",
"type": "string",
"default": "secret",
"oneOf": [
{
"const": "configmap",
"title": "ConfigMap"
},
{
"const": "secret",
"title": "Secret"
},
{
"const": "memory",
"title": "Memory"
}
]
}
},
"required": [],
"additionalProperties": true
}
Loading

0 comments on commit 4758e19

Please sign in to comment.