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

update types/spec/client to v1.9.0 #284

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func disableRedirect(c *http.Client) func() {
// chunksSizeByID is the max URL lentgh (2048) minus the endpoint lentgh (around 100) by UUID lentgh (36).
// This makes sure the full URL with the query strings params does not exceed the max URL length.
//
//nolint:gomnd // documented already
//nolint:mnd // documented already
const chunksSizeByID = (2048 - 100) / 36

func makeChunks[T any](ss []T, size int) [][]T {
Expand Down
15 changes: 2 additions & 13 deletions client/config_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,10 @@ package client
import (
"context"
"net/http"
"net/url"

"github.com/calyptia/api/types"
)

// ValidateConfig validates that an already parsed fluentbit or fluentd config is semantically valid.
// To parse the raw agent config take a look at https://github.com/calyptia/fluent-bit-config-parser.
func (c *Client) ValidateConfig(ctx context.Context, agentType types.AgentType, payload types.ValidatingConfig) (types.ValidatedConfig, error) {
var out types.ValidatedConfig
return out, c.do(ctx, http.MethodPost, "/v1/config_validate/"+url.PathEscape(string(agentType)), payload, &out)
}

// ValidateConfigV2 validates that an already parsed fluentbit(only) config to check if semantically valid
// To parse the raw agent config take a look at https://github.com/calyptia/fluent-bit-config-parser.
func (c *Client) ValidateConfigV2(ctx context.Context, payload types.ValidatingConfig) (types.ValidatedConfigV2, error) {
var out types.ValidatedConfigV2
return out, c.do(ctx, http.MethodPost, "/v1/config_validate_v2", payload, &out)
func (c *Client) ValidateFluentbitConfig(ctx context.Context, in types.ValidateFluentbitConfig) error {
return c.do(ctx, http.MethodPost, "/v2/validate_fluentbit_config", in, nil)
}
43 changes: 43 additions & 0 deletions spec/open-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4773,6 +4773,32 @@ components:
definition:
$ref: "#/components/schemas/ProcessingRuleDef"

ConfigFormat:
type: string
enum:
- classic
- yaml
- json
default: classic
example: yaml

ValidateFluentbitConfig:
type: object
properties:
rawConfig:
type: string
example: |-
pipeline:
inputs:
- name: dummy
outputs:
- name: stdout
match: "*"
configFormat:
$ref: "#/components/schemas/ConfigFormat"
required:
- rawConfig

paths:
/v1/verification_email:
get:
Expand Down Expand Up @@ -7413,6 +7439,7 @@ paths:
in: path
required: true
post:
deprecated: true
tags:
- config_validator
summary: Validate configuration
Expand All @@ -7437,6 +7464,7 @@ paths:
$ref: "#/components/schemas/ValidatedConfig"
"/v1/config_validate_v2":
post:
deprecated: true
tags:
- config_validator_v2
summary: Validate configuration on the v2 endpoint of the service
Expand Down Expand Up @@ -9846,3 +9874,18 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/DeletedProcessingRuleTemplate"

/v2/validate_fluentbit_config:
post:
operationId: validateFluentBitConfig
summary: Validate Fluent-bit configuration.
security: []
tags: [config_validator]
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/ValidateFluentbitConfig"
responses:
204:
description: No Content
54 changes: 3 additions & 51 deletions types/config_validator.go
Original file line number Diff line number Diff line change
@@ -1,54 +1,6 @@
package types

// ValidatingConfig request body for validating a config.
type ValidatingConfig struct {
Configs []ValidatingConfigEntry `json:"config"`
}

// ValidatingConfigEntry defines a single config to the validated. See `ValidatingConfig`.
type ValidatingConfigEntry struct {
Command string `json:"command"`
Name string `json:"name"`
Optional map[string]string `json:"optional,omitempty"`
ID string `json:"id"`
}

// ValidatedConfig response body after validating an agent config successfully.
type ValidatedConfig struct {
Errors ConfigValidity `json:"errors"`
}

// ConfigValidity details.
type ConfigValidity struct {
Runtime []string `json:"runtime" `
Input map[string][]string `json:"input"`
Output map[string][]string `json:"output"`
Filter map[string][]string `json:"filter"`
}

// ConfigValidityV2Property property details.
type ConfigValidityV2Property struct {
ID string `json:"id"`
Property string `json:"property"`
Text string `json:"text"`
Errors []string `json:"errors"`
}

// ConfigValidityV2Runtime runtime details.
type ConfigValidityV2Runtime struct {
ID string `json:"id"`
Errors []string `json:"errors"`
}

// ConfigValidityV2 details.
type ConfigValidityV2 struct {
Runtime []ConfigValidityV2Runtime `json:"runtime" `
Input map[string][]ConfigValidityV2Property `json:"input"`
Output map[string][]ConfigValidityV2Property `json:"output"`
Filter map[string][]ConfigValidityV2Property `json:"filter"`
}

// ValidatedConfigV2 response body after validating an agent config successfully against the v2 endpoint.
type ValidatedConfigV2 struct {
Errors ConfigValidityV2 `json:"errors"`
type ValidateFluentbitConfig struct {
RawConfig string `json:"rawConfig"`
ConfigFormat ConfigFormat `json:"configFormat"`
}
54 changes: 54 additions & 0 deletions types/legacy/config_validator_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package legacy

// ValidatingConfig request body for validating a config.
type ValidatingConfig struct {
Configs []ValidatingConfigEntry `json:"config"`
}

// ValidatingConfigEntry defines a single config to the validated. See `ValidatingConfig`.
type ValidatingConfigEntry struct {
Command string `json:"command"`
Name string `json:"name"`
Optional map[string]string `json:"optional,omitempty"`
ID string `json:"id"`
}

// ValidatedConfig response body after validating an agent config successfully.
type ValidatedConfig struct {
Errors ConfigValidity `json:"errors"`
}

// ConfigValidity details.
type ConfigValidity struct {
Runtime []string `json:"runtime" `
Input map[string][]string `json:"input"`
Output map[string][]string `json:"output"`
Filter map[string][]string `json:"filter"`
}

// ConfigValidityV2Property property details.
type ConfigValidityV2Property struct {
ID string `json:"id"`
Property string `json:"property"`
Text string `json:"text"`
Errors []string `json:"errors"`
}

// ConfigValidityV2Runtime runtime details.
type ConfigValidityV2Runtime struct {
ID string `json:"id"`
Errors []string `json:"errors"`
}

// ConfigValidityV2 details.
type ConfigValidityV2 struct {
Runtime []ConfigValidityV2Runtime `json:"runtime" `
Input map[string][]ConfigValidityV2Property `json:"input"`
Output map[string][]ConfigValidityV2Property `json:"output"`
Filter map[string][]ConfigValidityV2Property `json:"filter"`
}

// ValidatedConfigV2 response body after validating an agent config successfully against the v2 endpoint.
type ValidatedConfigV2 struct {
Errors ConfigValidityV2 `json:"errors"`
}
28 changes: 28 additions & 0 deletions types/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ func (m Membership) CanManageMembership(target Membership) bool {
return false
}

func (m Membership) HasPermission(permission string) bool {
// no permissions means all permissions.
if len(m.Permissions) == 0 {
return true
}

for _, p := range m.Permissions {
if p == permission {
return true
}
}
return false
}

func (m Membership) HasAllPermissions(permissions ...string) bool {
// no permissions means all permissions.
if len(m.Permissions) == 0 {
return true
}

for _, p := range permissions {
if !m.HasPermission(p) {
return false
}
}
return true
}

// Memberships paginated list.
type Memberships struct {
Items []Membership
Expand Down
17 changes: 17 additions & 0 deletions types/permission.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package types

const (
PermCreateAll = "create:*"
PermReadAll = "read:*"
PermUpdateAll = "update:*"
PermDeleteAll = "delete:*"
)

func AllPermissions() []string {
return []string{
PermCreateAll,
PermReadAll,
PermUpdateAll,
PermDeleteAll,
}
}
11 changes: 6 additions & 5 deletions types/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import "time"

// Token model.
type Token struct {
ID string `json:"id" yaml:"id"`
Token string `json:"token" yaml:"token"`
Name string `json:"name" yaml:"name"`
Permissions []string `json:"permissions" yaml:"permissions"`
CreatedAt time.Time `json:"createdAt" yaml:"createdAt"`
ID string `json:"id" yaml:"id" db:"id"`
ProjectID string `json:"projectID" yaml:"projectID" db:"project_id"`
Token string `json:"token" yaml:"token" db:"token"`
Name string `json:"name" yaml:"name" db:"name"`
Permissions []string `json:"permissions" yaml:"permissions" db:"permissions"`
CreatedAt time.Time `json:"createdAt" yaml:"createdAt" db:"created_at"`
}

// Tokens paginated list.
Expand Down