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
  • Loading branch information
pkosiec authored Dec 6, 2023
1 parent aec0dd9 commit b920662
Show file tree
Hide file tree
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
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down Expand Up @@ -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
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
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
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
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
Loading

0 comments on commit b920662

Please sign in to comment.