Skip to content
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
8 changes: 8 additions & 0 deletions cue/common/regexp_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/perses/spec/go/common

package common

// Regexp encapsulates a regexp.Regexp and makes it JSON/YAML marshalable.
#Regexp: _
24 changes: 24 additions & 0 deletions cue/common/regexp_patch.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright The Perses Authors
// 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.

// NB: This file complements the regexp_go_gen.cue file generated by
// `cue get go` to add the missing constraints lost in the translation
// process. This should no longer be needed at some point hopefully, but for
// the moment, because of a technical limitation in the CUE translation
// process, a top-value (= "any") gets generated instead of a proper def for
// any type that defines a custom UnmarshallJSON or UnmarshallYAML.
// For more info see https://github.com/cue-lang/cue/issues/2466.

package common

#Regexp: string
10 changes: 10 additions & 0 deletions cue/common/url_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/perses/spec/go/common

package common

// +kubebuilder:validation:Schemaless
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=uri
#URL: _
21 changes: 21 additions & 0 deletions cue/common/url_patch.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright The Perses Authors
// 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.

// NB: This file complements the url_go_gen.cue file generated by
// `cue get go` to add the missing constraints lost in the translation
// process. Indeed in Go, the URL pattern is not enforced by typing but
// by using a custom unmarshalling process, that doesn't get converted.

package common

#URL: =~"^https?:\/\/[^\\s\/$.?#].[^\\s]*$"
17 changes: 17 additions & 0 deletions cue/datasource/proxy/http/http_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/perses/spec/go/datasource/proxy/http

package http

import "github.com/perses/spec/cue/datasource/proxy"

#AllowedEndpoint: _

#Config: _

// Proxy is the HTTP proxy definition proposed in Perses.
// In case you are defining a datasource that will work with the Perses backend, then you will need to use this definition.
#Proxy: proxy.#Proxy

#ProxyKindName: "httpproxy"
50 changes: 50 additions & 0 deletions cue/datasource/proxy/http/http_patch.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright The Perses Authors
// 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.

// NB: This file complements the http_go_gen.cue file generated by
// `cue get go` to add the missing constraints lost in the translation
// process. This should no longer be needed at some point hopefully, but for
// the moment, because of a technical limitation in the CUE translation
// process, a top-value (= "any") gets generated instead of a proper def for
// any type that defines a custom UnmarshallJSON or UnmarshallYAML.
// For more info see https://github.com/cue-lang/cue/issues/2466.

package http

import (
"github.com/perses/spec/cue/common"
"github.com/perses/spec/cue/datasource/proxy"
)

#AllowedEndpoint: {
endpointPattern: string @go(EndpointPattern)
method: "POST" | "PUT" | "PATCH" | "GET" | "DELETE" @go(Method)
}

#Config: {
// url is the url of the datasource. It is not the url of the proxy.
// The Perses server is the proxy, so it needs to know where to redirect the request.
url: common.#URL @go(URL)
// allowedEndpoints is a list of tuples of http methods and http endpoints that will be accessible.
// Leave it empty if you don't want to restrict the access to the datasource.
allowedEndpoints?: [...#AllowedEndpoint] @go(AllowedEndpoints)
// headers can be used to provide additional headers that need to be forwarded when requesting the datasource
headers?: {[string]: string} @go(Headers)
// secret is the name of the secret that should be used for the proxy or discovery configuration
// It will contain any sensitive information such as password, token, certificate.
secret?: string @go(Secret)
}

#Proxy: proxy.#Proxy & {
kind: "HTTPProxy" @go(Kind)
}
11 changes: 11 additions & 0 deletions cue/datasource/proxy/proxy_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/perses/spec/go/datasource/proxy

package proxy

// Proxy is the generic struct of the proxy definition
#Proxy: {
kind: string @go(Kind)
spec: _ @go(Spec,T)
}
58 changes: 58 additions & 0 deletions cue/datasource/proxy/sql/sql_go_gen.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/perses/spec/go/datasource/proxy/sql

package sql

import (
"github.com/perses/spec/cue/common"
"github.com/perses/spec/cue/datasource/proxy"
)

// Driver the SQL driver to use
#Driver: string // #enumDriver

#enumDriver:
#DriverMySQL |
#DriverMariaDB |
#DriverPostgreSQL

#DriverMySQL: #Driver & "mysql"
#DriverMariaDB: #Driver & "mariadb"
#DriverPostgreSQL: #Driver & "postgres"

// SSLMode postgres ssl modes
#SSLMode: string // #enumSSLMode

#enumSSLMode:
#SSLModeDisable |
#SSLModeAllow |
#SSLModePreferable |
#SSLModeRequire |
#SSLModeVerifyFull |
#SSLModeVerifyCA

#SSLModeDisable: #SSLMode & "disable"
#SSLModeAllow: #SSLMode & "allow"
#SSLModePreferable: #SSLMode & "prefer"
#SSLModeRequire: #SSLMode & "require"
#SSLModeVerifyFull: #SSLMode & "verify-full"
#SSLModeVerifyCA: #SSLMode & "verify-ca"

#MySQLConfig: {
params?: {[string]: string} @go(Params,map[string]string)
maxAllowedPacket?: int @go(MaxAllowedPacket)
timeout?: common.#DurationString @go(Timeout)
readTimeout?: common.#DurationString @go(ReadTimeout)
writeTimeout?: common.#DurationString @go(WriteTimeout)
}

#PostgresConfig: _

#Config: _

// Proxy is the SQL proxy definition proposed in Perses.
// In case you are defining a datasource that will work with the Perses backend, then you will need to use this definition.
#Proxy: proxy.#Proxy

#ProxyKindName: "sqlproxy"
60 changes: 60 additions & 0 deletions cue/datasource/proxy/sql/sql_patch.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright The Perses Authors
// 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.

// NB: This file complements the sql_go_gen.cue file generated by
// `cue get go` to add the missing constraints lost in the translation
// process. This should no longer be needed at some point hopefully, but for
// the moment, because of a technical limitation in the CUE translation
// process, a top-value (= "any") gets generated instead of a proper def for
// any type that defines a custom UnmarshallJSON or UnmarshallYAML.
// For more info see https://github.com/cue-lang/cue/issues/2466.

package sql

import (
"github.com/perses/spec/cue/common"
"github.com/perses/spec/cue/datasource/proxy"
)

#PostgresConfig: {
// options specifies command-line options to send to the server at connection start
options?: string @go(Options,string)
// max_conns is the maximum size of the pool
max_conns?: number @go(MaxConns,int)
// connect_timeout the timeout value used for socket connect operations.
connect_timeout?: common.#DurationString @go(ConnectTimeout)
// prepare_threshold specifies the number of PreparedStatement executions that must occur before the driver begins using server-side prepared statements.
prepare_threshold?: number @go(PrepareThreshold,int)
// ssl_mode to use when connecting to postgres
ssl_mode?: #enumSSLMode @go(SSLMode,int)
}

#Config: {
driver: "mysql" | "postgres" | "mariadb"
// host is the hostname and port of the datasource. It is not the hostname of the proxy.
// The Perses server is the proxy, so it needs to know where to redirect the request.
host: string
// database is the name of the database to connect to
database: string
// secret is the name of the secret that should be used for the proxy or discovery configuration
// It will contain any sensitive information such as username, password, token, certificate.
secret?: string
// mysql specific driver configurations
mysql?: #MySQLConfig
// postgres specific driver configurations
postgres?: #PostgresConfig
}

#Proxy: proxy.#Proxy & {
kind: "SQLProxy" @go(Kind)
}
83 changes: 83 additions & 0 deletions go/common/regexp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright The Perses Authors
// 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.

package common

import (
"encoding/json"
"regexp"
)

// Regexp encapsulates a regexp.Regexp and makes it JSON/YAML marshalable.
type Regexp struct {
*regexp.Regexp
original string
}

// NewRegexp creates a new anchored Regexp and returns an error if the
// passed-in regular expression does not compile.
func NewRegexp(s string) (Regexp, error) {
regex, err := regexp.Compile(s)
return Regexp{
Regexp: regex,
original: s,
}, err
}

// MustNewRegexp works like NewRegexp, but panics if the regular expression does not compile.
func MustNewRegexp(s string) Regexp {
re, err := NewRegexp(s)
if err != nil {
panic(err)
}
return re
}

func (re *Regexp) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
return re.validate(s)
}

func (re *Regexp) UnmarshalYAML(unmarshal func(any) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}
return re.validate(s)
}

func (re Regexp) MarshalJSON() ([]byte, error) {
if len(re.original) > 0 {
return json.Marshal(re.original)
}
return nil, nil
}

func (re Regexp) MarshalYAML() (any, error) {
if len(re.original) > 0 {
return re.original, nil
}
return nil, nil
}

func (re *Regexp) validate(s string) error {
r, err := NewRegexp(s)
if err != nil {
return err
}
*re = r
return nil
}
Loading
Loading