Skip to content

Commit

Permalink
Update JSON schemas for all plugins (#1328)
Browse files Browse the repository at this point in the history
- Update JSON schemas for all plugins
   - Add password format for credentials
   - Ensure `log` is exposed everywhere
   - Ensure `additionalProperties` are enabled for plugins with more complex data
- Unify JSON schema definition across all plugins
pkosiec authored Dec 6, 2023
1 parent aec0dd9 commit b920662
Showing 37 changed files with 1,047 additions and 676 deletions.
14 changes: 14 additions & 0 deletions cmd/executor/echo/config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Echo",
"description": "Echo is an example Botkube executor plugin used during e2e tests. It's not meant for production usage.",
"type": "object",
"properties": {
"changeResponseToUpperCase": {
"description": "When changeResponseToUpperCase is true, the echoed string will be in upper case",
"type": "boolean",
"default": false
}
},
"required": []
}
33 changes: 11 additions & 22 deletions cmd/executor/echo/main.go
Original file line number Diff line number Diff line change
@@ -2,20 +2,25 @@ package main

import (
"context"
_ "embed"
"errors"
"fmt"
"strings"

"github.com/MakeNowJust/heredoc"
"github.com/hashicorp/go-plugin"

"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/api/executor"
"github.com/kubeshop/botkube/pkg/pluginx"
)

// version is set via ldflags by GoReleaser.
var version = "dev"
var (
// version is set via ldflags by GoReleaser.
version = "dev"

//go:embed config_schema.json
configJSONSchema string
)

const (
pluginName = "echo"
@@ -37,7 +42,9 @@ func (*EchoExecutor) Metadata(context.Context) (api.MetadataOutput, error) {
return api.MetadataOutput{
Version: version,
Description: description,
JSONSchema: jsonSchema(),
JSONSchema: api.JSONSchema{
Value: configJSONSchema,
},
}, nil
}

@@ -79,21 +86,3 @@ func main() {
},
})
}

func jsonSchema() api.JSONSchema {
return api.JSONSchema{
Value: heredoc.Docf(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "botkube/echo",
"description": "%s",
"type": "object",
"properties": {
"changeResponseToUpperCase": {
"description": "When changeResponseToUpperCase is true, the echoed string will be in upper case",
"type": "boolean"
}
},
"required": []
}`, description),
}
}
41 changes: 3 additions & 38 deletions cmd/executor/exec/main.go
Original file line number Diff line number Diff line change
@@ -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
}

@@ -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" {
102 changes: 102 additions & 0 deletions cmd/executor/gh/config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "GH",
"description": "GH creates an issue on GitHub for a related Kubernetes resource.",
"type": "object",
"additionalProperties": false,
"uiSchema": {
"github": {
"issueTemplate": {
"ui:widget": "textarea"
},
"token": {
"ui:widget": "password"
}
}
},
"properties": {
"github": {
"description": "GitHub-related configuration",
"title": "GitHub configuration",
"type": "object",
"properties": {
"token": {
"description": "GitHub Personal Access Token",
"title": "GitHub Token",
"type": "string",
"minLength": 3,
"default": ""
},
"issueTemplate": {
"description": "Issue template to use. If not specified, the default one will be used.",
"title": "Issue Template",
"type": "string",
"default": ""
},
"repository": {
"type": "string",
"title": "Repository",
"description": "GitHub repository to create issues in. Must be in the format of 'owner/repo'.",
"minLength": 3,
"default": ""
}
},
"required": [
"token",
"repository"
]
},
"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": [
"github"
]
}
124 changes: 15 additions & 109 deletions cmd/executor/gh/main.go
Original file line number Diff line number Diff line change
@@ -3,12 +3,12 @@ package main
import (
"bytes"
"context"
_ "embed"
"fmt"
"text/template"

"github.com/hashicorp/go-plugin"

"github.com/kubeshop/botkube/internal/cli/heredoc"
"github.com/kubeshop/botkube/internal/loggerx"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/api/executor"
@@ -24,8 +24,13 @@ const (
description = "GH creates an issue on GitHub for a related Kubernetes resource."
)

// version is set via ldflags by GoReleaser.
var version = "dev"
var (
// version is set via ldflags by GoReleaser.
version = "dev"

//go:embed config_schema.json
configJSONSchema string
)

// Config holds the GitHub executor configuration.
type Config struct {
@@ -57,10 +62,13 @@ type GHExecutor struct{}
// Metadata returns details about the GitHub plugin.
func (*GHExecutor) Metadata(context.Context) (api.MetadataOutput, error) {
return api.MetadataOutput{
Version: version,
Description: description,
Dependencies: depsDownloadLinks,
JSONSchema: jsonSchema(),
Version: version,
Description: description,
Dependencies: depsDownloadLinks,
DocumentationURL: "https://botkube.io/blog/build-a-github-issues-reporter-for-failing-kubernetes-apps-with-botkube-plugins",
JSONSchema: api.JSONSchema{
Value: configJSONSchema,
},
}, nil
}

@@ -239,105 +247,3 @@ func renderIssueBody(bodyTpl string, data IssueDetails) (string, error) {

return body.String(), nil
}

func jsonSchema() api.JSONSchema {
return api.JSONSchema{
Value: heredoc.Docf(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "botkube/gh",
"description": "%s",
"type": "object",
"additionalProperties": false,
"uiSchema": {
"github": {
"issueTemplate": {
"ui:widget": "textarea"
}
}
},
"properties": {
"github": {
"description": "GitHub-related configuration",
"title": "GitHub configuration",
"type": "object",
"properties": {
"token": {
"description": "GitHub Personal Access Token",
"title": "GitHub Token",
"type": "string",
"minLength": 1
},
"issueTemplate": {
"description": "Issue template to use. If not specified, the default one will be used.",
"title": "Issue Template",
"type": "string",
"default": ""
},
"repository": {
"type": "string",
"title": "Repository",
"description": "GitHub repository to create issues in. Must be in the format of 'owner/repo'.",
"minLength": 1
}
},
"required": [
"token",
"repository"
]
},
"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": [
"github"
]
}`, description),
}
}
2 changes: 1 addition & 1 deletion cmd/executor/thread-mate/main.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions cmd/source/cm-watcher/config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ConfigMap Watcher",
"description": "Kubernetes ConfigMap watcher is an example Botkube source plugin used during e2e tests. It's not meant for production usage.",
"type": "object",
"properties": {},
"required": []
}
52 changes: 17 additions & 35 deletions cmd/source/cm-watcher/main.go
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@ package main

import (
"context"
_ "embed"
"encoding/json"
"fmt"
"log"

"github.com/MakeNowJust/heredoc"
"github.com/hashicorp/go-plugin"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -23,8 +23,16 @@ import (
"github.com/kubeshop/botkube/pkg/pluginx"
)

// version is set via ldflags by GoReleaser.
var version = "dev"
var (
// version is set via ldflags by GoReleaser.
version = "dev"

//go:embed config_schema.json
configJSONSchema string

//go:embed webhook_schema.json
incomingWebhookJSONSchema string
)

const (
pluginName = "cm-watcher"
@@ -60,10 +68,14 @@ func (CMWatcher) Metadata(_ context.Context) (api.MetadataOutput, error) {
return api.MetadataOutput{
Version: version,
Description: description,
JSONSchema: jsonSchema(),
JSONSchema: api.JSONSchema{
Value: configJSONSchema,
},
ExternalRequest: api.ExternalRequestMetadata{
Payload: api.ExternalRequestPayload{
JSONSchema: incomingWebhookJSONSchema(),
JSONSchema: api.JSONSchema{
Value: incomingWebhookJSONSchema,
},
},
},
}, nil
@@ -163,33 +175,3 @@ func exitOnError(err error) {
log.Fatal(err)
}
}

func jsonSchema() api.JSONSchema {
return api.JSONSchema{
Value: heredoc.Docf(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "botkube/cm-watcher",
"description": "%s",
"type": "object",
"properties": {},
"required": []
}`, description),
}
}

func incomingWebhookJSONSchema() api.JSONSchema {
return api.JSONSchema{
Value: heredoc.Doc(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"message": {
"type": "string"
}
},
"required": [
"message"
]
}`),
}
}
12 changes: 12 additions & 0 deletions cmd/source/cm-watcher/webhook_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"message": {
"type": "string"
}
},
"required": [
"message"
]
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
{
"$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",
"type": "string",
"title": "API Key"
"title": "API Key",
"minLength": 3,
"default": ""
},
"apiBaseUrl": {
"description": "OpenAI API Base URL",
@@ -85,5 +92,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
@@ -29,7 +29,7 @@ const (
)

var (
//go:embed config-jsonschema.json
//go:embed config_schema.json
configJSONSchema string
k8sPromptRegex = regexp.MustCompile(`--(\w+)=([^\s]+)`)
)
4 changes: 3 additions & 1 deletion internal/executor/flux/config.go
Original file line number Diff line number Diff line change
@@ -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.
@@ -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"`
}
86 changes: 86 additions & 0 deletions internal/executor/flux/config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"$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",
"default": ""
}
}
}
}
},
"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
@@ -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"
@@ -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
}
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
@@ -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.
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
}
82 changes: 24 additions & 58 deletions internal/executor/helm/executor.go
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@ package helm

import (
"context"
_ "embed"
"fmt"
"os"

"github.com/MakeNowJust/heredoc"
"github.com/alexflint/go-arg"

"github.com/kubeshop/botkube/pkg/api"
@@ -20,20 +20,26 @@ const (
description = "Run the Helm CLI commands directly from your favorite communication platform."
)

// Links source: https://github.com/helm/helm/releases/tag/v3.6.3
// Using go-getter syntax to unwrap the underlying directory structure.
// Read more on https://github.com/hashicorp/go-getter#subdirectories
var helmBinaryDownloadLinks = map[string]string{
"darwin/amd64": "https://get.helm.sh/helm-v3.6.3-darwin-amd64.tar.gz//darwin-amd64",
"darwin/arm64": "https://get.helm.sh/helm-v3.6.3-darwin-arm64.tar.gz//darwin-arm64",
"linux/amd64": "https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz//linux-amd64",
"linux/arm": "https://get.helm.sh/helm-v3.6.3-linux-arm.tar.gz//linux-arm",
"linux/arm64": "https://get.helm.sh/helm-v3.6.3-linux-arm64.tar.gz//linux-arm64",
"linux/386": "https://get.helm.sh/helm-v3.6.3-linux-386.tar.gz//linux-386",
"linux/ppc64le": "https://get.helm.sh/helm-v3.6.3-linux-ppc64le.tar.gz//linux-ppc64le",
"linux/s390x": "https://get.helm.sh/helm-v3.6.3-linux-s390x.tar.gz//linux-s390x",
"windows/amd64": "https://get.helm.sh/helm-v3.6.3-windows-amd64.zip//windows-amd64",
}
var (
// Links source: https://github.com/helm/helm/releases/tag/v3.6.3
// Using go-getter syntax to unwrap the underlying directory structure.
// Read more on https://github.com/hashicorp/go-getter#subdirectories
helmBinaryDownloadLinks = map[string]string{
"darwin/amd64": "https://get.helm.sh/helm-v3.6.3-darwin-amd64.tar.gz//darwin-amd64",
"darwin/arm64": "https://get.helm.sh/helm-v3.6.3-darwin-arm64.tar.gz//darwin-arm64",
"linux/amd64": "https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz//linux-amd64",
"linux/arm": "https://get.helm.sh/helm-v3.6.3-linux-arm.tar.gz//linux-arm",
"linux/arm64": "https://get.helm.sh/helm-v3.6.3-linux-arm64.tar.gz//linux-arm64",
"linux/386": "https://get.helm.sh/helm-v3.6.3-linux-386.tar.gz//linux-386",
"linux/ppc64le": "https://get.helm.sh/helm-v3.6.3-linux-ppc64le.tar.gz//linux-ppc64le",
"linux/s390x": "https://get.helm.sh/helm-v3.6.3-linux-s390x.tar.gz//linux-s390x",
"windows/amd64": "https://get.helm.sh/helm-v3.6.3-windows-amd64.zip//windows-amd64",
}

//go:embed config_schema.json
// helmCacheDir and helmConfigDir were skipped as the options are not user-facing.
configJSONSchema string
)

type command interface {
Validate() error
@@ -62,7 +68,9 @@ func (e *Executor) Metadata(context.Context) (api.MetadataOutput, error) {
Version: e.pluginVersion,
Description: description,
DocumentationURL: "https://docs.botkube.io/configuration/executor/helm/",
JSONSchema: jsonSchema(),
JSONSchema: api.JSONSchema{
Value: configJSONSchema,
},
Dependencies: map[string]api.Dependency{
helmBinaryName: {
URLs: helmBinaryDownloadLinks,
@@ -197,45 +205,3 @@ func (e *Executor) handleHelmCommand(ctx context.Context, cmd command, cfg Confi
Message: api.NewCodeBlockMessage(out.Stdout, true),
}, nil
}

// jsonSchema returns JSON schema for the executor.
// helmCacheDir and helmConfigDir were skipped as the options are not user-facing.
func jsonSchema() api.JSONSchema {
return api.JSONSchema{
Value: heredoc.Docf(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Helm",
"description": "%s",
"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": []
}`, description),
}
}
177 changes: 0 additions & 177 deletions internal/executor/kubectl/config.go
Original file line number Diff line number Diff line change
@@ -3,11 +3,9 @@ package kubectl
import (
"fmt"

"github.com/MakeNowJust/heredoc"
"golang.org/x/exp/slices"

"github.com/kubeshop/botkube/internal/executor/kubectl/builder"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/api/executor"
"github.com/kubeshop/botkube/pkg/config"
"github.com/kubeshop/botkube/pkg/pluginx"
@@ -44,178 +42,3 @@ func MergeConfigs(configs []*executor.Config) (Config, error) {

return out, nil
}

func jsonSchema(description string) api.JSONSchema {
return api.JSONSchema{
Value: heredoc.Docf(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Kubectl",
"description": "%s",
"type": "object",
"additionalProperties": false,
"uiSchema": {
"interactiveBuilder": {
"allowed": {
"verbs": {
"ui:classNames": "non-orderable",
"ui:options": {
"orderable": false
},
"items": {
"ui:options": {
"label": false
}
}
},
"resources": {
"ui:classNames": "non-orderable",
"ui:options": {
"orderable": false
},
"items": {
"ui:options": {
"label": false
}
}
},
"namespaces": {
"ui:classNames": "non-orderable",
"ui:options": {
"orderable": false
},
"items": {
"ui:options": {
"label": false
}
}
}
}
}
},
"properties": {
"defaultNamespace": {
"description": "Namespace used if not explicitly specified during command execution.",
"title": "Default Kubernetes Namespace",
"type": "string",
"default": "default"
},
"interactiveBuilder": {
"title": "Interactive command builder",
"description": "Configuration of the interactive Kubectl command builder.",
"type": "object",
"properties": {
"allowed": {
"title": "",
"type": "object",
"description": "",
"properties": {
"verbs": {
"type": "array",
"title": "Verbs",
"description": "Kubectl verbs enabled for interactive Kubectl builder. At least one verb must be specified.",
"default": [
"api-resources",
"api-versions",
"cluster-info",
"describe",
"explain",
"get",
"logs",
"top"
],
"items": {
"title": "Verb",
"type": "string"
},
"minItems": 1
},
"resources": {
"type": "array",
"title": "Resources",
"description": "List of allowed resources. Each resource must be provided as a plural noun, such as \"deployments\", \"services\" or \"pods\".",
"default": [
"deployments",
"pods",
"namespaces",
"daemonsets",
"statefulsets",
"storageclasses",
"nodes",
"configmaps",
"services",
"ingresses"
],
"minItems": 1,
"items": {
"type": "string",
"title": "Resource"
}
},
"namespaces": {
"type": "array",
"title": "Namespaces",
"description": "List of allowed namespaces. If not specified, builder needs to have proper permissions to list all namespaces in the cluster",
"default": [],
"minItems": 0,
"items": {
"type": "string",
"title": "Namespace"
}
}
}
}
}
},
"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"
}
}
}
}
}`, description),
}
}
170 changes: 170 additions & 0 deletions internal/executor/kubectl/config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Kubectl",
"description": "Run the Kubectl CLI commands directly from your favorite communication platform.",
"type": "object",
"additionalProperties": false,
"uiSchema": {
"interactiveBuilder": {
"allowed": {
"verbs": {
"ui:classNames": "non-orderable",
"ui:options": {
"orderable": false
},
"items": {
"ui:options": {
"label": false
}
}
},
"resources": {
"ui:classNames": "non-orderable",
"ui:options": {
"orderable": false
},
"items": {
"ui:options": {
"label": false
}
}
},
"namespaces": {
"ui:classNames": "non-orderable",
"ui:options": {
"orderable": false
},
"items": {
"ui:options": {
"label": false
}
}
}
}
}
},
"properties": {
"defaultNamespace": {
"description": "Namespace used if not explicitly specified during command execution.",
"title": "Default Kubernetes Namespace",
"type": "string",
"default": "default"
},
"interactiveBuilder": {
"title": "Interactive command builder",
"description": "Configuration of the interactive Kubectl command builder.",
"type": "object",
"properties": {
"allowed": {
"title": "",
"type": "object",
"description": "",
"properties": {
"verbs": {
"type": "array",
"title": "Verbs",
"description": "Kubectl verbs enabled for interactive Kubectl builder. At least one verb must be specified.",
"default": [
"api-resources",
"api-versions",
"cluster-info",
"describe",
"explain",
"get",
"logs",
"top"
],
"items": {
"title": "Verb",
"type": "string"
},
"minItems": 1
},
"resources": {
"type": "array",
"title": "Resources",
"description": "List of allowed resources. Each resource must be provided as a plural noun, such as \"deployments\", \"services\" or \"pods\".",
"default": [
"deployments",
"pods",
"namespaces",
"daemonsets",
"statefulsets",
"storageclasses",
"nodes",
"configmaps",
"services",
"ingresses"
],
"minItems": 1,
"items": {
"type": "string",
"title": "Resource"
}
},
"namespaces": {
"type": "array",
"title": "Namespaces",
"description": "List of allowed namespaces. If not specified, builder needs to have proper permissions to list all namespaces in the cluster",
"default": [],
"minItems": 0,
"items": {
"type": "string",
"title": "Namespace"
}
}
}
}
}
},
"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"
}
}
}
}
}
29 changes: 18 additions & 11 deletions internal/executor/kubectl/executor.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package kubectl

import (
"context"
_ "embed"
"fmt"

"github.com/sirupsen/logrus"
@@ -26,16 +27,20 @@ const (
kubectlVersion = "v1.28.1"
)

var kcBinaryDownloadLinks = map[string]string{
"windows/amd64": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/windows/amd64/kubectl.exe", kubectlVersion),
"darwin/amd64": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/darwin/amd64/kubectl", kubectlVersion),
"darwin/arm64": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/darwin/arm64/kubectl", kubectlVersion),
"linux/amd64": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/linux/amd64/kubectl", kubectlVersion),
"linux/s390x": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/linux/s390x/kubectl", kubectlVersion),
"linux/ppc64le": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/linux/ppc64le/kubectl", kubectlVersion),
"linux/arm64": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/linux/arm64/kubectl", kubectlVersion),
"linux/386": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/linux/386/kubectl", kubectlVersion),
}
var (
//go:embed config_schema.json
configJSONSchema string
kcBinaryDownloadLinks = map[string]string{
"windows/amd64": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/windows/amd64/kubectl.exe", kubectlVersion),
"darwin/amd64": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/darwin/amd64/kubectl", kubectlVersion),
"darwin/arm64": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/darwin/arm64/kubectl", kubectlVersion),
"linux/amd64": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/linux/amd64/kubectl", kubectlVersion),
"linux/s390x": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/linux/s390x/kubectl", kubectlVersion),
"linux/ppc64le": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/linux/ppc64le/kubectl", kubectlVersion),
"linux/arm64": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/linux/arm64/kubectl", kubectlVersion),
"linux/386": fmt.Sprintf("https://dl.k8s.io/release/%s/bin/linux/386/kubectl", kubectlVersion),
}
)

var _ executor.Executor = &Executor{}

@@ -65,7 +70,9 @@ func (e *Executor) Metadata(context.Context) (api.MetadataOutput, error) {
Version: e.pluginVersion,
Description: description,
DocumentationURL: "https://docs.botkube.io/configuration/executor/kubectl",
JSONSchema: jsonSchema(description),
JSONSchema: api.JSONSchema{
Value: configJSONSchema,
},
Dependencies: map[string]api.Dependency{
binaryName: {
URLs: kcBinaryDownloadLinks,
10 changes: 6 additions & 4 deletions internal/executor/thread-mate/config.go
Original file line number Diff line number Diff line change
@@ -12,11 +12,13 @@ import (
"github.com/kubeshop/botkube/pkg/pluginx"
)

//go:embed jsonschema.json
var JSONSchema string
var (
//go:embed config_schema.json
ConfigJSONSchema string

//go:embed messages/round-robin.yaml
var defaultRoundRobinMessage string
//go:embed messages/round-robin.yaml
defaultRoundRobinMessage string
)

// Config holds the executor configuration.
type Config struct {
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "ThreadMate",
"uiSchema": {
"roundRobin": {
"assignees": {
@@ -14,8 +17,6 @@
}
}
},
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"roundRobin": {
"type": "object",
@@ -25,7 +26,9 @@
"type": "array",
"items": {
"type": "string",
"title": "Assignee"
"title": "Assignee",
"minLength": 3,
"default": ""
},
"minItems": 1,
"title": "Assignees",
@@ -73,6 +76,55 @@
"title": "Config Map Namespace"
}
}
},
"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": [
11 changes: 10 additions & 1 deletion internal/executor/x/config.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package x

import (
_ "embed"

"github.com/kubeshop/botkube/internal/executor/x/getter"
"github.com/kubeshop/botkube/internal/plugin"
"github.com/kubeshop/botkube/pkg/api"
"github.com/kubeshop/botkube/pkg/config"
)

var (
//go:embed config_schema_fmt.json
ConfigJSONSchemaFmt string
)

// Config holds exec plugin configuration.
type Config struct {
Templates []getter.Source `yaml:"templates"`
TmpDir plugin.TmpDir `yaml:"tmpDir"`
Logger config.Logger

// Fields not exposed to the user in the JSON schema
TmpDir plugin.TmpDir `yaml:"tmpDir"`
}

// GetPluginDependencies returns exec plugin dependencies.
80 changes: 80 additions & 0 deletions internal/executor/x/config_schema_fmt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"$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
}
},
"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": [
"templates"
]
}
2 changes: 1 addition & 1 deletion internal/source/argocd/argocd.go
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ import (
var _ source.Source = (*Source)(nil)

var (
//go:embed config-jsonschema.json
//go:embed config_schema.json
configJSONSchema string

//go:embed req-jsonschema.json
12 changes: 5 additions & 7 deletions internal/source/argocd/config.go
Original file line number Diff line number Diff line change
@@ -12,17 +12,15 @@ import (

// Config contains configuration for ArgoCD source plugin.
type Config struct {
Log config.Logger `yaml:"log"`

ArgoCD ArgoCD `yaml:"argoCD"`

Log config.Logger `yaml:"log"`
ArgoCD ArgoCD `yaml:"argoCD"`
DefaultSubscriptions DefaultNotificationSubscriptions `yaml:"defaultSubscriptions"`
Webhook Webhook `yaml:"webhook"`

Webhook Webhook `yaml:"webhook"`
// Fields not exposed to the user in the JSON schema
Notifications []Notification `yaml:"notifications"`
Templates []Template `yaml:"templates"`

Interactivity Interactivity `yaml:"interactivity"`
Interactivity Interactivity `yaml:"interactivity"`
}

// Interactivity contains configuration related to interactivity.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "ArgoCD Configuration",
"title": "ArgoCD",
"description": "Argo source plugin is used to get ArgoCD trigger-based notifications.",
"uiSchema": {
"defaultSubscriptions": {
@@ -35,21 +35,29 @@
"properties": {
"name": {
"type": "string",
"title": "Name"
"title": "Name",
"minLength": 3
},
"namespace": {
"type": "string",
"title": "Namespace"
"title": "Namespace",
"minLength": 3
}
},
"default": {
"name": "",
"namespace": ""
},
"required": [
"name",
"namespace"
]
}
}
},
"required": ["applications"]
"required": [
"applications"
]
},
"argoCD": {
"type": "object",
@@ -112,8 +120,58 @@
"name",
"url"
]
},
"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"
}
}
}
},
"additionalProperties": true,
"required": [
"defaultSubscriptions",
"argoCD",
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "GitHub Events Experimental Source Plugin",
"title": "GitHub Events",
"description": "GitHub Events configuration parameters",
"type": "object",
"uiSchema": {
@@ -68,7 +68,8 @@
"properties": {
"accessToken": {
"title": "Access Token",
"type": "string"
"type": "string",
"default": ""
}
}
}
@@ -84,6 +85,7 @@
"title": "Repository Configurations",
"description": "List of configurations for monitored repositories.",
"type": "array",
"minItems": 1,
"items": {
"title": "Repository Configuration",
"description": "Configuration settings for a specific repository.",
@@ -92,17 +94,24 @@
"name": {
"title": "Repository Name",
"description": "The name of the GitHub repository in the form 'owner/repository'.",
"type": "string"
"type": "string",
"default": "",
"minLength": 3
},
"on": {
"title": "Event Matchers",
"description": "Criteria for matching events in the repository.",
"type": "object",
"default": {
"pullRequests": [],
"eventsAPI": []
},
"properties": {
"pullRequests": {
"title": "Pull Request Matchers",
"description": "Criteria for matching pull requests.",
"type": "array",
"minItems": 0,
"items": {
"title": "Pull Request Matcher",
"description": "Matcher settings for pull requests.",
@@ -189,6 +198,7 @@
"title": "Events API Matchers",
"description": "Criteria for matching events from the /events API.",
"type": "array",
"minItems": 0,
"items": {
"title": "Events API Matcher",
"type": "object",
@@ -237,6 +247,59 @@
}
}
}
},
"required": [
"name",
"on"
]
}
},
"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"
}
}
}
8 changes: 5 additions & 3 deletions internal/source/github_events/source_grpc.go
Original file line number Diff line number Diff line change
@@ -13,8 +13,10 @@ import (

var _ source.Source = (*Source)(nil)

//go:embed jsonschema.json
var jsonschema string
var (
//go:embed config_schema.json
configJSONSchema string
)

const (
// PluginName is the name of the GitHub events Botkube plugin.
@@ -71,7 +73,7 @@ func (s *Source) Metadata(_ context.Context) (api.MetadataOutput, error) {
Description: description,
DocumentationURL: "https://docs.botkube.io/configuration/source/github-events",
JSONSchema: api.JSONSchema{
Value: jsonschema,
Value: configJSONSchema,
},
}, nil
}
5 changes: 0 additions & 5 deletions internal/source/keptn/config.go
Original file line number Diff line number Diff line change
@@ -17,11 +17,6 @@ type Config struct {
Log config.Logger `yaml:"log,omitempty"`
}

// Log logging configuration
type Log struct {
Level string `yaml:"level"`
}

// MergeConfigs merges all input configuration.
func MergeConfigs(configs []*source.Config) (Config, error) {
defaults := Config{}
90 changes: 90 additions & 0 deletions internal/source/keptn/config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Keptn",
"description": "Keptn plugin polls events from configured Keptn API endpoint.",
"type": "object",
"uiSchema": {
"token": {
"ui:widget": "password"
}
},
"properties": {
"url": {
"description": "Keptn API Gateway URL",
"type": "string",
"default": "http://api-gateway-nginx.keptn.svc.cluster.local/api",
"title": "Endpoint URL"
},
"token": {
"description": "Keptn API Token to access events through API Gateway",
"type": "string",
"title": "Keptn API Token",
"minLength": 3,
"default": ""
},
"project": {
"description": "Optional Keptn Project",
"type": "string",
"title": "Project",
"default": ""
},
"service": {
"description": "Optional Keptn Service name under the Project",
"type": "string",
"title": "Service",
"default": ""
},
"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": [
"token"
]
}
48 changes: 9 additions & 39 deletions internal/source/keptn/source.go
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@ package keptn

import (
"context"
_ "embed"
"fmt"
"time"

"github.com/MakeNowJust/heredoc"
"github.com/sirupsen/logrus"

"github.com/kubeshop/botkube/internal/loggerx"
@@ -15,6 +15,11 @@ import (

var _ source.Source = (*Source)(nil)

var (
//go:embed config_schema.json
configJSONSchema string
)

const (
// PluginName is the name of the Keptn Botkube plugin.
PluginName = "keptn"
@@ -56,7 +61,9 @@ func (p *Source) Metadata(_ context.Context) (api.MetadataOutput, error) {
Version: p.pluginVersion,
Description: description,
DocumentationURL: "https://docs.botkube.io/configuration/source/keptn",
JSONSchema: jsonSchema(),
JSONSchema: api.JSONSchema{
Value: configJSONSchema,
},
}, nil
}

@@ -120,43 +127,6 @@ func (p *Source) consumeEvents(ctx context.Context, cfg Config, ch chan<- source
}
}

func jsonSchema() api.JSONSchema {
return api.JSONSchema{
Value: heredoc.Docf(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Keptn",
"description": "%s",
"type": "object",
"properties": {
"url": {
"description": "Keptn API Gateway URL",
"type": "string",
"default": "http://api-gateway-nginx.keptn.svc.cluster.local/api",
"title": "Endpoint URL"
},
"token": {
"description": "Keptn API Token to access events through API Gateway",
"type": "string",
"title": "Keptn API Token"
},
"project": {
"description": "Keptn Project",
"type": "string",
"title": "Project"
},
"service": {
"description": "Keptn Service name under the project",
"type": "string",
"title": "Service"
}
},
"required": [
"token"
]
}`, description),
}
}

func exitOnError(err error, log logrus.FieldLogger) {
if err != nil {
log.Fatal(err)
4 changes: 2 additions & 2 deletions internal/source/kubernetes/source.go
Original file line number Diff line number Diff line change
@@ -30,9 +30,9 @@ import (
var _ source.Source = (*Source)(nil)

var (
// configJSONSchema JSON schema with duplications,
// configJSONSchema contains duplications,
// as some UI components (e.g. https://github.com/rjsf-team/react-jsonschema-form) don't support nested defaults for definitions.
//go:embed config-jsonschema.json
//go:embed config_schema.json
configJSONSchema string
)

104 changes: 104 additions & 0 deletions internal/source/prometheus/config_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Prometheus",
"description": "Get notifications about alerts polled from configured Prometheus AlertManager.",
"type": "object",
"properties": {
"url": {
"title": "Endpoint",
"description": "Prometheus endpoint without API version and resource.",
"type": "string",
"format": "uri",
"default": "",
"minLength": 3
},
"ignoreOldAlerts": {
"title": "Ignore old alerts",
"description": "If set to true, Prometheus source plugin will not send alerts that is created before the plugin start time.",
"type": "boolean",
"default": true
},
"alertStates": {
"title": "Alert states",
"description": "Only the alerts that have state provided in this config will be sent as notification. https://pkg.go.dev/github.com/prometheus/prometheus/rules#AlertState",
"type": "array",
"default": [
"firing",
"pending",
"inactive"
],
"items": {
"type": "string",
"title": "Alert state",
"oneOf": [
{
"const": "firing",
"title": "Firing"
},
{
"const": "pending",
"title": "Pending"
},
{
"const": "inactive",
"title": "Inactive"
}
]
},
"uniqueItems": true,
"minItems": 1
},
"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": [
"url"
]
}
116 changes: 9 additions & 107 deletions internal/source/prometheus/source.go
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@ package prometheus

import (
"context"
_ "embed"
"fmt"
"time"

"github.com/MakeNowJust/heredoc"
"github.com/sirupsen/logrus"

"github.com/kubeshop/botkube/internal/loggerx"
@@ -15,6 +15,11 @@ import (

var _ source.Source = (*Source)(nil)

var (
//go:embed config_schema.json
configJSONSchema string
)

const (
// PluginName is the name of the Prometheus Botkube plugin.
PluginName = "prometheus"
@@ -58,7 +63,9 @@ func (p *Source) Metadata(_ context.Context) (api.MetadataOutput, error) {
Version: p.pluginVersion,
Description: description,
DocumentationURL: "https://docs.botkube.io/configuration/source/prometheus",
JSONSchema: jsonSchema(),
JSONSchema: api.JSONSchema{
Value: configJSONSchema,
},
}, nil
}

@@ -108,111 +115,6 @@ func (p *Source) consumeAlerts(ctx context.Context, cfg Config, ch chan<- source
}
}

func jsonSchema() api.JSONSchema {
return api.JSONSchema{
Value: heredoc.Docf(`{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Prometheus",
"description": "%s",
"type": "object",
"properties": {
"url": {
"title": "Endpoint",
"description": "Prometheus endpoint without API version and resource.",
"type": "string",
"format": "uri"
},
"ignoreOldAlerts": {
"title": "Ignore old alerts",
"description": "If set to true, Prometheus source plugin will not send alerts that is created before the plugin start time.",
"type": "boolean",
"default": true
},
"alertStates": {
"title": "Alert states",
"description": "Only the alerts that have state provided in this config will be sent as notification. https://pkg.go.dev/github.com/prometheus/prometheus/rules#AlertState",
"type": "array",
"default": [
"firing",
"pending",
"inactive"
],
"items": {
"type": "string",
"title": "Alert state",
"oneOf": [
{
"const": "firing",
"title": "Firing"
},
{
"const": "pending",
"title": "Pending"
},
{
"const": "inactive",
"title": "Inactive"
}
]
},
"uniqueItems": true,
"minItems": 1
},
"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": ["url"]
}`, description),
}
}

func exitOnError(err error, log logrus.FieldLogger) {
if err != nil {
log.Fatal(err)

0 comments on commit b920662

Please sign in to comment.