mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-01-20 21:08:04 -05:00
Compare commits
3 Commits
dgraph-doc
...
config-pre
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70f5550910 | ||
|
|
348c9fde08 | ||
|
|
aef539bcf3 |
@@ -92,11 +92,11 @@ implementation](https://github.com/googleapis/genai-toolbox/blob/main/internal/s
|
|||||||
`newdb.go`. Create a `Config` struct to include all the necessary parameters
|
`newdb.go`. Create a `Config` struct to include all the necessary parameters
|
||||||
for connecting to the database (e.g., host, port, username, password, database
|
for connecting to the database (e.g., host, port, username, password, database
|
||||||
name) and a `Source` struct to store necessary parameters for tools (e.g.,
|
name) and a `Source` struct to store necessary parameters for tools (e.g.,
|
||||||
Name, Kind, connection object, additional config).
|
Name, Type, connection object, additional config).
|
||||||
* **Implement the
|
* **Implement the
|
||||||
[`SourceConfig`](https://github.com/googleapis/genai-toolbox/blob/fd300dc606d88bf9f7bba689e2cee4e3565537dd/internal/sources/sources.go#L57)
|
[`SourceConfig`](https://github.com/googleapis/genai-toolbox/blob/fd300dc606d88bf9f7bba689e2cee4e3565537dd/internal/sources/sources.go#L57)
|
||||||
interface**. This interface requires two methods:
|
interface**. This interface requires two methods:
|
||||||
* `SourceConfigKind() string`: Returns a unique string identifier for your
|
* `SourceConfigType() string`: Returns a unique string identifier for your
|
||||||
data source (e.g., `"newdb"`).
|
data source (e.g., `"newdb"`).
|
||||||
* `Initialize(ctx context.Context, tracer trace.Tracer) (Source, error)`:
|
* `Initialize(ctx context.Context, tracer trace.Tracer) (Source, error)`:
|
||||||
Creates a new instance of your data source and establishes a connection to
|
Creates a new instance of your data source and establishes a connection to
|
||||||
@@ -104,7 +104,7 @@ implementation](https://github.com/googleapis/genai-toolbox/blob/main/internal/s
|
|||||||
* **Implement the
|
* **Implement the
|
||||||
[`Source`](https://github.com/googleapis/genai-toolbox/blob/fd300dc606d88bf9f7bba689e2cee4e3565537dd/internal/sources/sources.go#L63)
|
[`Source`](https://github.com/googleapis/genai-toolbox/blob/fd300dc606d88bf9f7bba689e2cee4e3565537dd/internal/sources/sources.go#L63)
|
||||||
interface**. This interface requires one method:
|
interface**. This interface requires one method:
|
||||||
* `SourceKind() string`: Returns the same string identifier as `SourceConfigKind()`.
|
* `SourceType() string`: Returns the same string identifier as `SourceConfigType()`.
|
||||||
* **Implement `init()`** to register the new Source.
|
* **Implement `init()`** to register the new Source.
|
||||||
* **Implement Unit Tests** in a file named `newdb_test.go`.
|
* **Implement Unit Tests** in a file named `newdb_test.go`.
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ tools.
|
|||||||
* **Implement the
|
* **Implement the
|
||||||
[`ToolConfig`](https://github.com/googleapis/genai-toolbox/blob/fd300dc606d88bf9f7bba689e2cee4e3565537dd/internal/tools/tools.go#L61)
|
[`ToolConfig`](https://github.com/googleapis/genai-toolbox/blob/fd300dc606d88bf9f7bba689e2cee4e3565537dd/internal/tools/tools.go#L61)
|
||||||
interface**. This interface requires one method:
|
interface**. This interface requires one method:
|
||||||
* `ToolConfigKind() string`: Returns a unique string identifier for your tool
|
* `ToolConfigType() string`: Returns a unique string identifier for your tool
|
||||||
(e.g., `"newdb-tool"`).
|
(e.g., `"newdb-tool"`).
|
||||||
* `Initialize(sources map[string]Source) (Tool, error)`: Creates a new
|
* `Initialize(sources map[string]Source) (Tool, error)`: Creates a new
|
||||||
instance of your tool and validates that it can connect to the specified
|
instance of your tool and validates that it can connect to the specified
|
||||||
@@ -243,7 +243,7 @@ resources.
|
|||||||
| style | Update src code, with only formatting and whitespace updates (e.g. code formatter or linter changes). |
|
| style | Update src code, with only formatting and whitespace updates (e.g. code formatter or linter changes). |
|
||||||
|
|
||||||
Pull requests should always add scope whenever possible. The scope is
|
Pull requests should always add scope whenever possible. The scope is
|
||||||
formatted as `<scope-type>/<scope-kind>` (e.g., `sources/postgres`, or
|
formatted as `<scope-resource>/<scope-type>` (e.g., `sources/postgres`, or
|
||||||
`tools/mssql-sql`).
|
`tools/mssql-sql`).
|
||||||
|
|
||||||
Ideally, **each PR covers only one scope**, if this is
|
Ideally, **each PR covers only one scope**, if this is
|
||||||
|
|||||||
@@ -954,7 +954,7 @@ For more details on configuring different types of sources, see the
|
|||||||
### Tools
|
### Tools
|
||||||
|
|
||||||
The `tools` section of a `tools.yaml` define the actions an agent can take: what
|
The `tools` section of a `tools.yaml` define the actions an agent can take: what
|
||||||
kind of tool it is, which source(s) it affects, what parameters it uses, etc.
|
type of tool it is, which source(s) it affects, what parameters it uses, etc.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
tools:
|
tools:
|
||||||
|
|||||||
102
cmd/root.go
102
cmd/root.go
@@ -15,6 +15,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -98,7 +99,6 @@ import (
|
|||||||
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqlgetinstances"
|
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqlgetinstances"
|
||||||
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqllistdatabases"
|
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqllistdatabases"
|
||||||
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqllistinstances"
|
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqllistinstances"
|
||||||
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqlrestorebackup"
|
|
||||||
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqlwaitforoperation"
|
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsql/cloudsqlwaitforoperation"
|
||||||
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsqlmssql/cloudsqlmssqlcreateinstance"
|
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsqlmssql/cloudsqlmssqlcreateinstance"
|
||||||
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance"
|
_ "github.com/googleapis/genai-toolbox/internal/tools/cloudsqlmysql/cloudsqlmysqlcreateinstance"
|
||||||
@@ -426,6 +426,106 @@ func parseEnv(input string) (string, error) {
|
|||||||
return output, err
|
return output, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertToolsFile(ctx context.Context, raw []byte) ([]byte, error) {
|
||||||
|
var input yaml.MapSlice
|
||||||
|
decoder := yaml.NewDecoder(bytes.NewReader(raw), yaml.UseOrderedMap())
|
||||||
|
if err := decoder.Decode(&input); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert raw MapSlice to a helper map for quick lookup
|
||||||
|
// while keeping the values as MapSlices to preserve internal order
|
||||||
|
resourceOrder := []string{}
|
||||||
|
lookup := make(map[string]yaml.MapSlice)
|
||||||
|
for _, item := range input {
|
||||||
|
key, ok := item.Key.(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected non-string key in input: %v", item.Key)
|
||||||
|
}
|
||||||
|
if slice, ok := item.Value.(yaml.MapSlice); ok {
|
||||||
|
// convert authSources to authServices
|
||||||
|
if key == "authSources" {
|
||||||
|
key = "authServices"
|
||||||
|
}
|
||||||
|
// works even if lookup[key] is nil
|
||||||
|
lookup[key] = append(lookup[key], slice...)
|
||||||
|
// preserving the resource's order of original toolsFile
|
||||||
|
if !slices.Contains(resourceOrder, key) {
|
||||||
|
resourceOrder = append(resourceOrder, key)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// toolsfile is already v2
|
||||||
|
if key == "kind" {
|
||||||
|
return raw, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("'%s' is not a map", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// convert to tools file v2
|
||||||
|
var buf bytes.Buffer
|
||||||
|
encoder := yaml.NewEncoder(&buf)
|
||||||
|
for _, kind := range resourceOrder {
|
||||||
|
data, exists := lookup[kind]
|
||||||
|
if !exists {
|
||||||
|
// if this is skipped for all keys, the tools file is in v2
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Transform each entry
|
||||||
|
for _, entry := range data {
|
||||||
|
entryName, ok := entry.Key.(string)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected non-string key for entry in '%s': %v", kind, entry.Key)
|
||||||
|
}
|
||||||
|
entryBody := ProcessValue(entry.Value, kind == "toolsets")
|
||||||
|
|
||||||
|
transformed := yaml.MapSlice{
|
||||||
|
{Key: "kind", Value: kind},
|
||||||
|
{Key: "name", Value: entryName},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge the transformed body into our result
|
||||||
|
if bodySlice, ok := entryBody.(yaml.MapSlice); ok {
|
||||||
|
transformed = append(transformed, bodySlice...)
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("unable to convert entryBody to MapSlice")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := encoder.Encode(transformed); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buf.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProcessValue recursively looks for MapSlices to rename 'kind' -> 'type'
|
||||||
|
func ProcessValue(v any, isToolset bool) any {
|
||||||
|
switch val := v.(type) {
|
||||||
|
case yaml.MapSlice:
|
||||||
|
for i := range val {
|
||||||
|
// Perform renaming
|
||||||
|
if val[i].Key == "kind" {
|
||||||
|
val[i].Key = "type"
|
||||||
|
}
|
||||||
|
// Recursive call for nested values (e.g., nested objects or lists)
|
||||||
|
val[i].Value = ProcessValue(val[i].Value, false)
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
case []any:
|
||||||
|
// Process lists: If it's a toolset top-level list, wrap it.
|
||||||
|
if isToolset {
|
||||||
|
return yaml.MapSlice{{Key: "tools", Value: val}}
|
||||||
|
}
|
||||||
|
// Otherwise, recurse into list items (to catch nested objects)
|
||||||
|
for i := range val {
|
||||||
|
val[i] = ProcessValue(val[i], false)
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
default:
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// parseToolsFile parses the provided yaml into appropriate configs.
|
// parseToolsFile parses the provided yaml into appropriate configs.
|
||||||
func parseToolsFile(ctx context.Context, raw []byte) (ToolsFile, error) {
|
func parseToolsFile(ctx context.Context, raw []byte) (ToolsFile, error) {
|
||||||
var toolsFile ToolsFile
|
var toolsFile ToolsFile
|
||||||
|
|||||||
347
cmd/root_test.go
347
cmd/root_test.go
@@ -23,12 +23,14 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
yaml "github.com/goccy/go-yaml"
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"github.com/googleapis/genai-toolbox/internal/auth/google"
|
"github.com/googleapis/genai-toolbox/internal/auth/google"
|
||||||
@@ -494,6 +496,309 @@ func TestDefaultLogLevel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConvertToolsFile(t *testing.T) {
|
||||||
|
ctx, cancelCtx := context.WithTimeout(context.Background(), time.Minute)
|
||||||
|
defer cancelCtx()
|
||||||
|
pr, pw := io.Pipe()
|
||||||
|
defer pw.Close()
|
||||||
|
defer pr.Close()
|
||||||
|
|
||||||
|
logger, err := log.NewStdLogger(pw, pw, "DEBUG")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to setup logger %s", err)
|
||||||
|
}
|
||||||
|
ctx = util.WithLogger(ctx, logger)
|
||||||
|
|
||||||
|
tcs := []struct {
|
||||||
|
desc string
|
||||||
|
in string
|
||||||
|
want string
|
||||||
|
isErr bool
|
||||||
|
errStr string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "basic convert",
|
||||||
|
in: `
|
||||||
|
sources:
|
||||||
|
my-pg-instance:
|
||||||
|
kind: cloud-sql-postgres
|
||||||
|
project: my-project
|
||||||
|
region: my-region
|
||||||
|
instance: my-instance
|
||||||
|
database: my_db
|
||||||
|
user: my_user
|
||||||
|
password: my_pass
|
||||||
|
authServices:
|
||||||
|
my-google-auth:
|
||||||
|
kind: google
|
||||||
|
clientId: testing-id
|
||||||
|
tools:
|
||||||
|
example_tool:
|
||||||
|
kind: postgres-sql
|
||||||
|
source: my-pg-instance
|
||||||
|
description: some description
|
||||||
|
statement: |
|
||||||
|
SELECT * FROM SQL_STATEMENT;
|
||||||
|
parameters:
|
||||||
|
- name: country
|
||||||
|
type: string
|
||||||
|
description: some description
|
||||||
|
toolsets:
|
||||||
|
example_toolset:
|
||||||
|
- example_tool
|
||||||
|
prompts:
|
||||||
|
code_review:
|
||||||
|
description: ask llm to analyze code quality
|
||||||
|
messages:
|
||||||
|
- content: "please review the following code for quality: {{.code}}"
|
||||||
|
arguments:
|
||||||
|
- name: code
|
||||||
|
description: the code to review
|
||||||
|
embeddingModels:
|
||||||
|
gemini-model:
|
||||||
|
kind: gemini
|
||||||
|
model: gemini-embedding-001
|
||||||
|
apiKey: some-key
|
||||||
|
dimension: 768`,
|
||||||
|
want: `
|
||||||
|
kind: sources
|
||||||
|
name: my-pg-instance
|
||||||
|
type: cloud-sql-postgres
|
||||||
|
project: my-project
|
||||||
|
region: my-region
|
||||||
|
instance: my-instance
|
||||||
|
database: my_db
|
||||||
|
user: my_user
|
||||||
|
password: my_pass
|
||||||
|
---
|
||||||
|
kind: authServices
|
||||||
|
name: my-google-auth
|
||||||
|
type: google
|
||||||
|
clientId: testing-id
|
||||||
|
---
|
||||||
|
kind: tools
|
||||||
|
name: example_tool
|
||||||
|
type: postgres-sql
|
||||||
|
source: my-pg-instance
|
||||||
|
description: some description
|
||||||
|
statement: |
|
||||||
|
SELECT * FROM SQL_STATEMENT;
|
||||||
|
parameters:
|
||||||
|
- name: country
|
||||||
|
type: string
|
||||||
|
description: some description
|
||||||
|
---
|
||||||
|
kind: toolsets
|
||||||
|
name: example_toolset
|
||||||
|
tools:
|
||||||
|
- example_tool
|
||||||
|
---
|
||||||
|
kind: prompts
|
||||||
|
name: code_review
|
||||||
|
description: ask llm to analyze code quality
|
||||||
|
messages:
|
||||||
|
- content: "please review the following code for quality: {{.code}}"
|
||||||
|
arguments:
|
||||||
|
- name: code
|
||||||
|
description: the code to review
|
||||||
|
---
|
||||||
|
kind: embeddingModels
|
||||||
|
name: gemini-model
|
||||||
|
type: gemini
|
||||||
|
model: gemini-embedding-001
|
||||||
|
apiKey: some-key
|
||||||
|
dimension: 768`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "preserve resource order with grouping",
|
||||||
|
in: `
|
||||||
|
tools:
|
||||||
|
example_tool:
|
||||||
|
kind: postgres-sql
|
||||||
|
source: my-pg-instance
|
||||||
|
description: some description
|
||||||
|
statement: |
|
||||||
|
SELECT * FROM SQL_STATEMENT;
|
||||||
|
parameters:
|
||||||
|
- name: country
|
||||||
|
type: string
|
||||||
|
description: some description
|
||||||
|
sources:
|
||||||
|
my-pg-instance:
|
||||||
|
kind: cloud-sql-postgres
|
||||||
|
project: my-project
|
||||||
|
region: my-region
|
||||||
|
instance: my-instance
|
||||||
|
database: my_db
|
||||||
|
user: my_user
|
||||||
|
password: my_pass
|
||||||
|
authServices:
|
||||||
|
my-google-auth:
|
||||||
|
kind: google
|
||||||
|
clientId: testing-id
|
||||||
|
toolsets:
|
||||||
|
example_toolset:
|
||||||
|
- example_tool
|
||||||
|
authSources:
|
||||||
|
my-google-auth:
|
||||||
|
kind: google
|
||||||
|
clientId: testing-id`,
|
||||||
|
want: `
|
||||||
|
kind: tools
|
||||||
|
name: example_tool
|
||||||
|
type: postgres-sql
|
||||||
|
source: my-pg-instance
|
||||||
|
description: some description
|
||||||
|
statement: |
|
||||||
|
SELECT * FROM SQL_STATEMENT;
|
||||||
|
parameters:
|
||||||
|
- name: country
|
||||||
|
type: string
|
||||||
|
description: some description
|
||||||
|
---
|
||||||
|
kind: sources
|
||||||
|
name: my-pg-instance
|
||||||
|
type: cloud-sql-postgres
|
||||||
|
project: my-project
|
||||||
|
region: my-region
|
||||||
|
instance: my-instance
|
||||||
|
database: my_db
|
||||||
|
user: my_user
|
||||||
|
password: my_pass
|
||||||
|
---
|
||||||
|
kind: authServices
|
||||||
|
name: my-google-auth
|
||||||
|
type: google
|
||||||
|
clientId: testing-id
|
||||||
|
---
|
||||||
|
kind: authServices
|
||||||
|
name: my-google-auth
|
||||||
|
type: google
|
||||||
|
clientId: testing-id
|
||||||
|
---
|
||||||
|
kind: toolsets
|
||||||
|
name: example_toolset
|
||||||
|
tools:
|
||||||
|
- example_tool`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no convertion needed",
|
||||||
|
in: `
|
||||||
|
kind: sources
|
||||||
|
name: my-pg-instance
|
||||||
|
type: cloud-sql-postgres
|
||||||
|
project: my-project
|
||||||
|
region: my-region
|
||||||
|
instance: my-instance
|
||||||
|
database: my_db
|
||||||
|
user: my_user
|
||||||
|
password: my_pass
|
||||||
|
---
|
||||||
|
kind: tools
|
||||||
|
name: example_tool
|
||||||
|
type: postgres-sql
|
||||||
|
source: my-pg-instance
|
||||||
|
description: some description
|
||||||
|
statement: |
|
||||||
|
SELECT * FROM SQL_STATEMENT;
|
||||||
|
parameters:
|
||||||
|
- name: country
|
||||||
|
type: string
|
||||||
|
description: some description
|
||||||
|
---
|
||||||
|
kind: toolsets
|
||||||
|
name: example_toolset
|
||||||
|
tools:
|
||||||
|
- example_tool`,
|
||||||
|
want: `
|
||||||
|
kind: sources
|
||||||
|
name: my-pg-instance
|
||||||
|
type: cloud-sql-postgres
|
||||||
|
project: my-project
|
||||||
|
region: my-region
|
||||||
|
instance: my-instance
|
||||||
|
database: my_db
|
||||||
|
user: my_user
|
||||||
|
password: my_pass
|
||||||
|
---
|
||||||
|
kind: tools
|
||||||
|
name: example_tool
|
||||||
|
type: postgres-sql
|
||||||
|
source: my-pg-instance
|
||||||
|
description: some description
|
||||||
|
statement: |
|
||||||
|
SELECT * FROM SQL_STATEMENT;
|
||||||
|
parameters:
|
||||||
|
- name: country
|
||||||
|
type: string
|
||||||
|
description: some description
|
||||||
|
---
|
||||||
|
kind: toolsets
|
||||||
|
name: example_toolset
|
||||||
|
tools:
|
||||||
|
- example_tool`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "invalid source",
|
||||||
|
in: `sources: invalid`,
|
||||||
|
isErr: true,
|
||||||
|
errStr: "'sources' is not a map",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "invalid toolset",
|
||||||
|
in: `toolsets: invalid`,
|
||||||
|
isErr: true,
|
||||||
|
errStr: "'toolsets' is not a map",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range tcs {
|
||||||
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
|
output, err := convertToolsFile(ctx, []byte(tc.in))
|
||||||
|
if tc.isErr {
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("missing error: %s", tc.errStr)
|
||||||
|
}
|
||||||
|
if err.Error() != tc.errStr {
|
||||||
|
t.Fatalf("invalid error string: got %s, want %s", err, tc.errStr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var docs1, docs2 []yaml.MapSlice
|
||||||
|
if docs1, err = decodeToMapSlice(string(output)); err != nil {
|
||||||
|
t.Fatalf("error decoding output: %s", err)
|
||||||
|
}
|
||||||
|
if docs2, err = decodeToMapSlice(tc.want); err != nil {
|
||||||
|
t.Fatalf("Error decoding want: %s", err)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(docs1, docs2) {
|
||||||
|
t.Fatalf("incorrect output: got %s, want %s", string(output), tc.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeToMapSlice(data string) ([]yaml.MapSlice, error) {
|
||||||
|
// ensures that the order is correct
|
||||||
|
var docs []yaml.MapSlice
|
||||||
|
decoder := yaml.NewDecoder(strings.NewReader(data))
|
||||||
|
for {
|
||||||
|
var doc yaml.MapSlice
|
||||||
|
err := decoder.Decode(&doc)
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
docs = append(docs, doc)
|
||||||
|
}
|
||||||
|
return docs, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseToolFile(t *testing.T) {
|
func TestParseToolFile(t *testing.T) {
|
||||||
ctx, err := testutils.ContextWithNewLogger()
|
ctx, err := testutils.ContextWithNewLogger()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -535,7 +840,7 @@ func TestParseToolFile(t *testing.T) {
|
|||||||
Sources: server.SourceConfigs{
|
Sources: server.SourceConfigs{
|
||||||
"my-pg-instance": cloudsqlpgsrc.Config{
|
"my-pg-instance": cloudsqlpgsrc.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: cloudsqlpgsrc.SourceKind,
|
Type: cloudsqlpgsrc.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -548,7 +853,7 @@ func TestParseToolFile(t *testing.T) {
|
|||||||
Tools: server.ToolConfigs{
|
Tools: server.ToolConfigs{
|
||||||
"example_tool": postgressql.Config{
|
"example_tool": postgressql.Config{
|
||||||
Name: "example_tool",
|
Name: "example_tool",
|
||||||
Kind: "postgres-sql",
|
Type: "postgres-sql",
|
||||||
Source: "my-pg-instance",
|
Source: "my-pg-instance",
|
||||||
Description: "some description",
|
Description: "some description",
|
||||||
Statement: "SELECT * FROM SQL_STATEMENT;\n",
|
Statement: "SELECT * FROM SQL_STATEMENT;\n",
|
||||||
@@ -689,7 +994,7 @@ func TestParseToolFileWithAuth(t *testing.T) {
|
|||||||
Sources: server.SourceConfigs{
|
Sources: server.SourceConfigs{
|
||||||
"my-pg-instance": cloudsqlpgsrc.Config{
|
"my-pg-instance": cloudsqlpgsrc.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: cloudsqlpgsrc.SourceKind,
|
Type: cloudsqlpgsrc.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -702,19 +1007,19 @@ func TestParseToolFileWithAuth(t *testing.T) {
|
|||||||
AuthServices: server.AuthServiceConfigs{
|
AuthServices: server.AuthServiceConfigs{
|
||||||
"my-google-service": google.Config{
|
"my-google-service": google.Config{
|
||||||
Name: "my-google-service",
|
Name: "my-google-service",
|
||||||
Kind: google.AuthServiceKind,
|
Type: google.AuthServiceType,
|
||||||
ClientID: "my-client-id",
|
ClientID: "my-client-id",
|
||||||
},
|
},
|
||||||
"other-google-service": google.Config{
|
"other-google-service": google.Config{
|
||||||
Name: "other-google-service",
|
Name: "other-google-service",
|
||||||
Kind: google.AuthServiceKind,
|
Type: google.AuthServiceType,
|
||||||
ClientID: "other-client-id",
|
ClientID: "other-client-id",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Tools: server.ToolConfigs{
|
Tools: server.ToolConfigs{
|
||||||
"example_tool": postgressql.Config{
|
"example_tool": postgressql.Config{
|
||||||
Name: "example_tool",
|
Name: "example_tool",
|
||||||
Kind: "postgres-sql",
|
Type: "postgres-sql",
|
||||||
Source: "my-pg-instance",
|
Source: "my-pg-instance",
|
||||||
Description: "some description",
|
Description: "some description",
|
||||||
Statement: "SELECT * FROM SQL_STATEMENT;\n",
|
Statement: "SELECT * FROM SQL_STATEMENT;\n",
|
||||||
@@ -789,7 +1094,7 @@ func TestParseToolFileWithAuth(t *testing.T) {
|
|||||||
Sources: server.SourceConfigs{
|
Sources: server.SourceConfigs{
|
||||||
"my-pg-instance": cloudsqlpgsrc.Config{
|
"my-pg-instance": cloudsqlpgsrc.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: cloudsqlpgsrc.SourceKind,
|
Type: cloudsqlpgsrc.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -802,19 +1107,19 @@ func TestParseToolFileWithAuth(t *testing.T) {
|
|||||||
AuthSources: server.AuthServiceConfigs{
|
AuthSources: server.AuthServiceConfigs{
|
||||||
"my-google-service": google.Config{
|
"my-google-service": google.Config{
|
||||||
Name: "my-google-service",
|
Name: "my-google-service",
|
||||||
Kind: google.AuthServiceKind,
|
Type: google.AuthServiceType,
|
||||||
ClientID: "my-client-id",
|
ClientID: "my-client-id",
|
||||||
},
|
},
|
||||||
"other-google-service": google.Config{
|
"other-google-service": google.Config{
|
||||||
Name: "other-google-service",
|
Name: "other-google-service",
|
||||||
Kind: google.AuthServiceKind,
|
Type: google.AuthServiceType,
|
||||||
ClientID: "other-client-id",
|
ClientID: "other-client-id",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Tools: server.ToolConfigs{
|
Tools: server.ToolConfigs{
|
||||||
"example_tool": postgressql.Config{
|
"example_tool": postgressql.Config{
|
||||||
Name: "example_tool",
|
Name: "example_tool",
|
||||||
Kind: "postgres-sql",
|
Type: "postgres-sql",
|
||||||
Source: "my-pg-instance",
|
Source: "my-pg-instance",
|
||||||
Description: "some description",
|
Description: "some description",
|
||||||
Statement: "SELECT * FROM SQL_STATEMENT;\n",
|
Statement: "SELECT * FROM SQL_STATEMENT;\n",
|
||||||
@@ -891,7 +1196,7 @@ func TestParseToolFileWithAuth(t *testing.T) {
|
|||||||
Sources: server.SourceConfigs{
|
Sources: server.SourceConfigs{
|
||||||
"my-pg-instance": cloudsqlpgsrc.Config{
|
"my-pg-instance": cloudsqlpgsrc.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: cloudsqlpgsrc.SourceKind,
|
Type: cloudsqlpgsrc.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -904,19 +1209,19 @@ func TestParseToolFileWithAuth(t *testing.T) {
|
|||||||
AuthServices: server.AuthServiceConfigs{
|
AuthServices: server.AuthServiceConfigs{
|
||||||
"my-google-service": google.Config{
|
"my-google-service": google.Config{
|
||||||
Name: "my-google-service",
|
Name: "my-google-service",
|
||||||
Kind: google.AuthServiceKind,
|
Type: google.AuthServiceType,
|
||||||
ClientID: "my-client-id",
|
ClientID: "my-client-id",
|
||||||
},
|
},
|
||||||
"other-google-service": google.Config{
|
"other-google-service": google.Config{
|
||||||
Name: "other-google-service",
|
Name: "other-google-service",
|
||||||
Kind: google.AuthServiceKind,
|
Type: google.AuthServiceType,
|
||||||
ClientID: "other-client-id",
|
ClientID: "other-client-id",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Tools: server.ToolConfigs{
|
Tools: server.ToolConfigs{
|
||||||
"example_tool": postgressql.Config{
|
"example_tool": postgressql.Config{
|
||||||
Name: "example_tool",
|
Name: "example_tool",
|
||||||
Kind: "postgres-sql",
|
Type: "postgres-sql",
|
||||||
Source: "my-pg-instance",
|
Source: "my-pg-instance",
|
||||||
Description: "some description",
|
Description: "some description",
|
||||||
Statement: "SELECT * FROM SQL_STATEMENT;\n",
|
Statement: "SELECT * FROM SQL_STATEMENT;\n",
|
||||||
@@ -1062,7 +1367,7 @@ func TestEnvVarReplacement(t *testing.T) {
|
|||||||
Sources: server.SourceConfigs{
|
Sources: server.SourceConfigs{
|
||||||
"my-http-instance": httpsrc.Config{
|
"my-http-instance": httpsrc.Config{
|
||||||
Name: "my-http-instance",
|
Name: "my-http-instance",
|
||||||
Kind: httpsrc.SourceKind,
|
Type: httpsrc.SourceType,
|
||||||
BaseURL: "http://test_server/",
|
BaseURL: "http://test_server/",
|
||||||
Timeout: "10s",
|
Timeout: "10s",
|
||||||
DefaultHeaders: map[string]string{"Authorization": "ACTUAL_HEADER"},
|
DefaultHeaders: map[string]string{"Authorization": "ACTUAL_HEADER"},
|
||||||
@@ -1072,19 +1377,19 @@ func TestEnvVarReplacement(t *testing.T) {
|
|||||||
AuthServices: server.AuthServiceConfigs{
|
AuthServices: server.AuthServiceConfigs{
|
||||||
"my-google-service": google.Config{
|
"my-google-service": google.Config{
|
||||||
Name: "my-google-service",
|
Name: "my-google-service",
|
||||||
Kind: google.AuthServiceKind,
|
Type: google.AuthServiceType,
|
||||||
ClientID: "ACTUAL_CLIENT_ID",
|
ClientID: "ACTUAL_CLIENT_ID",
|
||||||
},
|
},
|
||||||
"other-google-service": google.Config{
|
"other-google-service": google.Config{
|
||||||
Name: "other-google-service",
|
Name: "other-google-service",
|
||||||
Kind: google.AuthServiceKind,
|
Type: google.AuthServiceType,
|
||||||
ClientID: "ACTUAL_CLIENT_ID_2",
|
ClientID: "ACTUAL_CLIENT_ID_2",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Tools: server.ToolConfigs{
|
Tools: server.ToolConfigs{
|
||||||
"example_tool": http.Config{
|
"example_tool": http.Config{
|
||||||
Name: "example_tool",
|
Name: "example_tool",
|
||||||
Kind: "http",
|
Type: "http",
|
||||||
Source: "my-instance",
|
Source: "my-instance",
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Path: "search?name=alice&pet=cat",
|
Path: "search?name=alice&pet=cat",
|
||||||
@@ -1493,7 +1798,7 @@ func TestPrebuiltTools(t *testing.T) {
|
|||||||
wantToolset: server.ToolsetConfigs{
|
wantToolset: server.ToolsetConfigs{
|
||||||
"cloud_sql_postgres_admin_tools": tools.ToolsetConfig{
|
"cloud_sql_postgres_admin_tools": tools.ToolsetConfig{
|
||||||
Name: "cloud_sql_postgres_admin_tools",
|
Name: "cloud_sql_postgres_admin_tools",
|
||||||
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "postgres_upgrade_precheck", "clone_instance", "create_backup", "restore_backup"},
|
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "postgres_upgrade_precheck", "clone_instance", "create_backup"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1503,7 +1808,7 @@ func TestPrebuiltTools(t *testing.T) {
|
|||||||
wantToolset: server.ToolsetConfigs{
|
wantToolset: server.ToolsetConfigs{
|
||||||
"cloud_sql_mysql_admin_tools": tools.ToolsetConfig{
|
"cloud_sql_mysql_admin_tools": tools.ToolsetConfig{
|
||||||
Name: "cloud_sql_mysql_admin_tools",
|
Name: "cloud_sql_mysql_admin_tools",
|
||||||
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "clone_instance", "create_backup", "restore_backup"},
|
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "clone_instance", "create_backup"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -1513,7 +1818,7 @@ func TestPrebuiltTools(t *testing.T) {
|
|||||||
wantToolset: server.ToolsetConfigs{
|
wantToolset: server.ToolsetConfigs{
|
||||||
"cloud_sql_mssql_admin_tools": tools.ToolsetConfig{
|
"cloud_sql_mssql_admin_tools": tools.ToolsetConfig{
|
||||||
Name: "cloud_sql_mssql_admin_tools",
|
Name: "cloud_sql_mssql_admin_tools",
|
||||||
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "clone_instance", "create_backup", "restore_backup"},
|
ToolNames: []string{"create_instance", "get_instance", "list_instances", "create_database", "list_databases", "create_user", "wait_for_operation", "clone_instance", "create_backup"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
0
cmd/test.db
Normal file
0
cmd/test.db
Normal file
@@ -54,7 +54,6 @@ instance, database and users:
|
|||||||
* `create_instance`
|
* `create_instance`
|
||||||
* `create_user`
|
* `create_user`
|
||||||
* `clone_instance`
|
* `clone_instance`
|
||||||
* `restore_backup`
|
|
||||||
|
|
||||||
## Install MCP Toolbox
|
## Install MCP Toolbox
|
||||||
|
|
||||||
@@ -302,7 +301,6 @@ instances and interacting with your database:
|
|||||||
* **wait_for_operation**: Waits for a Cloud SQL operation to complete.
|
* **wait_for_operation**: Waits for a Cloud SQL operation to complete.
|
||||||
* **clone_instance**: Creates a clone of an existing Cloud SQL for SQL Server instance.
|
* **clone_instance**: Creates a clone of an existing Cloud SQL for SQL Server instance.
|
||||||
* **create_backup**: Creates a backup on a Cloud SQL instance.
|
* **create_backup**: Creates a backup on a Cloud SQL instance.
|
||||||
* **restore_backup**: Restores a backup of a Cloud SQL instance.
|
|
||||||
|
|
||||||
{{< notice note >}}
|
{{< notice note >}}
|
||||||
Prebuilt tools are pre-1.0, so expect some tool changes between versions. LLMs
|
Prebuilt tools are pre-1.0, so expect some tool changes between versions. LLMs
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ database and users:
|
|||||||
* `create_instance`
|
* `create_instance`
|
||||||
* `create_user`
|
* `create_user`
|
||||||
* `clone_instance`
|
* `clone_instance`
|
||||||
* `restore_backup`
|
|
||||||
|
|
||||||
## Install MCP Toolbox
|
## Install MCP Toolbox
|
||||||
|
|
||||||
@@ -302,7 +301,6 @@ instances and interacting with your database:
|
|||||||
* **wait_for_operation**: Waits for a Cloud SQL operation to complete.
|
* **wait_for_operation**: Waits for a Cloud SQL operation to complete.
|
||||||
* **clone_instance**: Creates a clone of an existing Cloud SQL for MySQL instance.
|
* **clone_instance**: Creates a clone of an existing Cloud SQL for MySQL instance.
|
||||||
* **create_backup**: Creates a backup on a Cloud SQL instance.
|
* **create_backup**: Creates a backup on a Cloud SQL instance.
|
||||||
* **restore_backup**: Restores a backup of a Cloud SQL instance.
|
|
||||||
|
|
||||||
{{< notice note >}}
|
{{< notice note >}}
|
||||||
Prebuilt tools are pre-1.0, so expect some tool changes between versions. LLMs
|
Prebuilt tools are pre-1.0, so expect some tool changes between versions. LLMs
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ instance, database and users:
|
|||||||
* `create_instance`
|
* `create_instance`
|
||||||
* `create_user`
|
* `create_user`
|
||||||
* `clone_instance`
|
* `clone_instance`
|
||||||
* `restore_backup`
|
|
||||||
|
|
||||||
## Install MCP Toolbox
|
## Install MCP Toolbox
|
||||||
|
|
||||||
@@ -302,7 +301,6 @@ instances and interacting with your database:
|
|||||||
* **wait_for_operation**: Waits for a Cloud SQL operation to complete.
|
* **wait_for_operation**: Waits for a Cloud SQL operation to complete.
|
||||||
* **clone_instance**: Creates a clone of an existing Cloud SQL for PostgreSQL instance.
|
* **clone_instance**: Creates a clone of an existing Cloud SQL for PostgreSQL instance.
|
||||||
* **create_backup**: Creates a backup on a Cloud SQL instance.
|
* **create_backup**: Creates a backup on a Cloud SQL instance.
|
||||||
* **restore_backup**: Restores a backup of a Cloud SQL instance.
|
|
||||||
|
|
||||||
{{< notice note >}}
|
{{< notice note >}}
|
||||||
Prebuilt tools are pre-1.0, so expect some tool changes between versions. LLMs
|
Prebuilt tools are pre-1.0, so expect some tool changes between versions. LLMs
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ The native SDKs can be combined with MCP clients in many cases.
|
|||||||
|
|
||||||
Toolbox currently supports the following versions of MCP specification:
|
Toolbox currently supports the following versions of MCP specification:
|
||||||
|
|
||||||
* [2025-11-25](https://modelcontextprotocol.io/specification/2025-11-25)
|
|
||||||
* [2025-06-18](https://modelcontextprotocol.io/specification/2025-06-18)
|
* [2025-06-18](https://modelcontextprotocol.io/specification/2025-06-18)
|
||||||
* [2025-03-26](https://modelcontextprotocol.io/specification/2025-03-26)
|
* [2025-03-26](https://modelcontextprotocol.io/specification/2025-03-26)
|
||||||
* [2024-11-05](https://modelcontextprotocol.io/specification/2024-11-05)
|
* [2024-11-05](https://modelcontextprotocol.io/specification/2024-11-05)
|
||||||
|
|||||||
@@ -194,7 +194,6 @@ See [Usage Examples](../reference/cli.md#examples).
|
|||||||
* `create_instance`
|
* `create_instance`
|
||||||
* `create_user`
|
* `create_user`
|
||||||
* `clone_instance`
|
* `clone_instance`
|
||||||
* `restore_backup`
|
|
||||||
|
|
||||||
* **Tools:**
|
* **Tools:**
|
||||||
* `create_instance`: Creates a new Cloud SQL for MySQL instance.
|
* `create_instance`: Creates a new Cloud SQL for MySQL instance.
|
||||||
@@ -206,7 +205,6 @@ See [Usage Examples](../reference/cli.md#examples).
|
|||||||
* `wait_for_operation`: Waits for a Cloud SQL operation to complete.
|
* `wait_for_operation`: Waits for a Cloud SQL operation to complete.
|
||||||
* `clone_instance`: Creates a clone for an existing Cloud SQL for MySQL instance.
|
* `clone_instance`: Creates a clone for an existing Cloud SQL for MySQL instance.
|
||||||
* `create_backup`: Creates a backup on a Cloud SQL instance.
|
* `create_backup`: Creates a backup on a Cloud SQL instance.
|
||||||
* `restore_backup`: Restores a backup of a Cloud SQL instance.
|
|
||||||
|
|
||||||
## Cloud SQL for PostgreSQL
|
## Cloud SQL for PostgreSQL
|
||||||
|
|
||||||
@@ -286,7 +284,6 @@ See [Usage Examples](../reference/cli.md#examples).
|
|||||||
* `create_instance`
|
* `create_instance`
|
||||||
* `create_user`
|
* `create_user`
|
||||||
* `clone_instance`
|
* `clone_instance`
|
||||||
* `restore_backup`
|
|
||||||
* **Tools:**
|
* **Tools:**
|
||||||
* `create_instance`: Creates a new Cloud SQL for PostgreSQL instance.
|
* `create_instance`: Creates a new Cloud SQL for PostgreSQL instance.
|
||||||
* `get_instance`: Gets information about a Cloud SQL instance.
|
* `get_instance`: Gets information about a Cloud SQL instance.
|
||||||
@@ -297,7 +294,6 @@ See [Usage Examples](../reference/cli.md#examples).
|
|||||||
* `wait_for_operation`: Waits for a Cloud SQL operation to complete.
|
* `wait_for_operation`: Waits for a Cloud SQL operation to complete.
|
||||||
* `clone_instance`: Creates a clone for an existing Cloud SQL for PostgreSQL instance.
|
* `clone_instance`: Creates a clone for an existing Cloud SQL for PostgreSQL instance.
|
||||||
* `create_backup`: Creates a backup on a Cloud SQL instance.
|
* `create_backup`: Creates a backup on a Cloud SQL instance.
|
||||||
* `restore_backup`: Restores a backup of a Cloud SQL instance.
|
|
||||||
|
|
||||||
## Cloud SQL for SQL Server
|
## Cloud SQL for SQL Server
|
||||||
|
|
||||||
@@ -351,7 +347,6 @@ See [Usage Examples](../reference/cli.md#examples).
|
|||||||
* `create_instance`
|
* `create_instance`
|
||||||
* `create_user`
|
* `create_user`
|
||||||
* `clone_instance`
|
* `clone_instance`
|
||||||
* `restore_backup`
|
|
||||||
* **Tools:**
|
* **Tools:**
|
||||||
* `create_instance`: Creates a new Cloud SQL for SQL Server instance.
|
* `create_instance`: Creates a new Cloud SQL for SQL Server instance.
|
||||||
* `get_instance`: Gets information about a Cloud SQL instance.
|
* `get_instance`: Gets information about a Cloud SQL instance.
|
||||||
@@ -362,7 +357,6 @@ See [Usage Examples](../reference/cli.md#examples).
|
|||||||
* `wait_for_operation`: Waits for a Cloud SQL operation to complete.
|
* `wait_for_operation`: Waits for a Cloud SQL operation to complete.
|
||||||
* `clone_instance`: Creates a clone for an existing Cloud SQL for SQL Server instance.
|
* `clone_instance`: Creates a clone for an existing Cloud SQL for SQL Server instance.
|
||||||
* `create_backup`: Creates a backup on a Cloud SQL instance.
|
* `create_backup`: Creates a backup on a Cloud SQL instance.
|
||||||
* `restore_backup`: Restores a backup of a Cloud SQL instance.
|
|
||||||
|
|
||||||
## Dataplex
|
## Dataplex
|
||||||
|
|
||||||
|
|||||||
@@ -7,17 +7,6 @@ description: >
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
{{< notice note >}}
|
|
||||||
**⚠️ Best Effort Maintenance**
|
|
||||||
|
|
||||||
This integration is maintained on a best-effort basis by the project
|
|
||||||
team/community. While we strive to address issues and provide workarounds when
|
|
||||||
resources are available, there are no guaranteed response times or code fixes.
|
|
||||||
|
|
||||||
The automated integration tests for this module are currently non-functional or
|
|
||||||
failing.
|
|
||||||
{{< /notice >}}
|
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
[Dgraph][dgraph-docs] is an open-source graph database. It is designed for
|
[Dgraph][dgraph-docs] is an open-source graph database. It is designed for
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ tools:
|
|||||||
|
|
||||||
### Usage Flow
|
### Usage Flow
|
||||||
|
|
||||||
When using this tool, a `query` parameter containing a natural language query is provided to the tool (typically by an agent). The tool then interacts with the Gemini Data Analytics API using the context defined in your configuration.
|
When using this tool, a `prompt` parameter containing a natural language query is provided to the tool (typically by an agent). The tool then interacts with the Gemini Data Analytics API using the context defined in your configuration.
|
||||||
|
|
||||||
The structure of the response depends on the `generationOptions` configured in your tool definition (e.g., enabling `generateQueryResult` will include the SQL query results).
|
The structure of the response depends on the `generationOptions` configured in your tool definition (e.g., enabling `generateQueryResult` will include the SQL query results).
|
||||||
|
|
||||||
See [Data Analytics API REST documentation](https://clouddocs.devsite.corp.google.com/gemini/docs/conversational-analytics-api/reference/rest/v1alpha/projects.locations/queryData?rep_location=global) for details.
|
See [Data Analytics API REST documentation](https://clouddocs.devsite.corp.google.com/gemini/docs/conversational-analytics-api/reference/rest/v1alpha/projects.locations/queryData?rep_location=global) for details.
|
||||||
|
|
||||||
**Example Input Query:**
|
**Example Input Prompt:**
|
||||||
|
|
||||||
```text
|
```text
|
||||||
How many accounts who have region in Prague are eligible for loans? A3 contains the data of region.
|
How many accounts who have region in Prague are eligible for loans? A3 contains the data of region.
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
---
|
|
||||||
title: cloud-sql-restore-backup
|
|
||||||
type: docs
|
|
||||||
weight: 10
|
|
||||||
description: "Restores a backup of a Cloud SQL instance."
|
|
||||||
---
|
|
||||||
|
|
||||||
The `cloud-sql-restore-backup` tool restores a backup on a Cloud SQL instance using the Cloud SQL Admin API.
|
|
||||||
|
|
||||||
{{< notice info dd>}}
|
|
||||||
This tool uses a `source` of kind `cloud-sql-admin`.
|
|
||||||
{{< /notice >}}
|
|
||||||
|
|
||||||
## Examples
|
|
||||||
|
|
||||||
Basic backup restore
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
tools:
|
|
||||||
backup-restore-basic:
|
|
||||||
kind: cloud-sql-restore-backup
|
|
||||||
source: cloud-sql-admin-source
|
|
||||||
description: "Restores a backup onto the given Cloud SQL instance."
|
|
||||||
```
|
|
||||||
|
|
||||||
## Reference
|
|
||||||
|
|
||||||
### Tool Configuration
|
|
||||||
| **field** | **type** | **required** | **description** |
|
|
||||||
| -------------- | :------: | :----------: | ------------------------------------------------ |
|
|
||||||
| kind | string | true | Must be "cloud-sql-restore-backup". |
|
|
||||||
| source | string | true | The name of the `cloud-sql-admin` source to use. |
|
|
||||||
| description | string | false | A description of the tool. |
|
|
||||||
|
|
||||||
### Tool Inputs
|
|
||||||
|
|
||||||
| **parameter** | **type** | **required** | **description** |
|
|
||||||
| ------------------| :------: | :----------: | -----------------------------------------------------------------------------|
|
|
||||||
| target_project | string | true | The project ID of the instance to restore the backup onto. |
|
|
||||||
| target_instance | string | true | The instance to restore the backup onto. Does not include the project ID. |
|
|
||||||
| backup_id | string | true | The identifier of the backup being restored. |
|
|
||||||
| source_project | string | false | (Optional) The project ID of the instance that the backup belongs to. |
|
|
||||||
| source_instance | string | false | (Optional) Cloud SQL instance ID of the instance that the backup belongs to. |
|
|
||||||
|
|
||||||
## Usage Notes
|
|
||||||
|
|
||||||
- The `backup_id` field can be a BackupRun ID (which will be an int64), backup name, or BackupDR backup name.
|
|
||||||
- If the `backup_id` field contains a BackupRun ID (i.e. an int64), the optional fields `source_project` and `source_instance` must also be provided.
|
|
||||||
|
|
||||||
## See Also
|
|
||||||
- [Cloud SQL Admin API documentation](https://cloud.google.com/sql/docs/mysql/admin-api)
|
|
||||||
- [Toolbox Cloud SQL tools documentation](../cloudsql)
|
|
||||||
- [Cloud SQL Restore API documentation](https://cloud.google.com/sql/docs/mysql/backup-recovery/restoring)
|
|
||||||
@@ -9,17 +9,6 @@ aliases:
|
|||||||
- /resources/tools/dgraph-dql
|
- /resources/tools/dgraph-dql
|
||||||
---
|
---
|
||||||
|
|
||||||
{{< notice note >}}
|
|
||||||
**⚠️ Best Effort Maintenance**
|
|
||||||
|
|
||||||
This integration is maintained on a best-effort basis by the project
|
|
||||||
team/community. While we strive to address issues and provide workarounds when
|
|
||||||
resources are available, there are no guaranteed response times or code fixes.
|
|
||||||
|
|
||||||
The automated integration tests for this module are currently non-functional or
|
|
||||||
failing.
|
|
||||||
{{< /notice >}}
|
|
||||||
|
|
||||||
## About
|
## About
|
||||||
|
|
||||||
A `dgraph-dql` tool executes a pre-defined DQL statement against a Dgraph
|
A `dgraph-dql` tool executes a pre-defined DQL statement against a Dgraph
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ import (
|
|||||||
|
|
||||||
// AuthServiceConfig is the interface for configuring authentication services.
|
// AuthServiceConfig is the interface for configuring authentication services.
|
||||||
type AuthServiceConfig interface {
|
type AuthServiceConfig interface {
|
||||||
AuthServiceConfigKind() string
|
AuthServiceConfigType() string
|
||||||
Initialize() (AuthService, error)
|
Initialize() (AuthService, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthService is the interface for authentication services.
|
// AuthService is the interface for authentication services.
|
||||||
type AuthService interface {
|
type AuthService interface {
|
||||||
AuthServiceKind() string
|
AuthServiceType() string
|
||||||
GetName() string
|
GetName() string
|
||||||
GetClaimsFromHeader(context.Context, http.Header) (map[string]any, error)
|
GetClaimsFromHeader(context.Context, http.Header) (map[string]any, error)
|
||||||
ToConfig() AuthServiceConfig
|
ToConfig() AuthServiceConfig
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
"google.golang.org/api/idtoken"
|
"google.golang.org/api/idtoken"
|
||||||
)
|
)
|
||||||
|
|
||||||
const AuthServiceKind string = "google"
|
const AuthServiceType string = "google"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ auth.AuthServiceConfig = Config{}
|
var _ auth.AuthServiceConfig = Config{}
|
||||||
@@ -31,13 +31,13 @@ var _ auth.AuthServiceConfig = Config{}
|
|||||||
// Auth service configuration
|
// Auth service configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
ClientID string `yaml:"clientId" validate:"required"`
|
ClientID string `yaml:"clientId" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the auth service kind
|
// Returns the auth service type
|
||||||
func (cfg Config) AuthServiceConfigKind() string {
|
func (cfg Config) AuthServiceConfigType() string {
|
||||||
return AuthServiceKind
|
return AuthServiceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize a Google auth service
|
// Initialize a Google auth service
|
||||||
@@ -55,9 +55,9 @@ type AuthService struct {
|
|||||||
Config
|
Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the auth service kind
|
// Returns the auth service type
|
||||||
func (a AuthService) AuthServiceKind() string {
|
func (a AuthService) AuthServiceType() string {
|
||||||
return AuthServiceKind
|
return AuthServiceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AuthService) ToConfig() auth.AuthServiceConfig {
|
func (a AuthService) ToConfig() auth.AuthServiceConfig {
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ import (
|
|||||||
|
|
||||||
// EmbeddingModelConfig is the interface for configuring embedding models.
|
// EmbeddingModelConfig is the interface for configuring embedding models.
|
||||||
type EmbeddingModelConfig interface {
|
type EmbeddingModelConfig interface {
|
||||||
EmbeddingModelConfigKind() string
|
EmbeddingModelConfigType() string
|
||||||
Initialize(context.Context) (EmbeddingModel, error)
|
Initialize(context.Context) (EmbeddingModel, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmbeddingModel interface {
|
type EmbeddingModel interface {
|
||||||
EmbeddingModelKind() string
|
EmbeddingModelType() string
|
||||||
ToConfig() EmbeddingModelConfig
|
ToConfig() EmbeddingModelConfig
|
||||||
EmbedParameters(context.Context, []string) ([][]float32, error)
|
EmbedParameters(context.Context, []string) ([][]float32, error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,22 +23,22 @@ import (
|
|||||||
"google.golang.org/genai"
|
"google.golang.org/genai"
|
||||||
)
|
)
|
||||||
|
|
||||||
const EmbeddingModelKind string = "gemini"
|
const EmbeddingModelType string = "gemini"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ embeddingmodels.EmbeddingModelConfig = Config{}
|
var _ embeddingmodels.EmbeddingModelConfig = Config{}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Model string `yaml:"model" validate:"required"`
|
Model string `yaml:"model" validate:"required"`
|
||||||
ApiKey string `yaml:"apiKey"`
|
ApiKey string `yaml:"apiKey"`
|
||||||
Dimension int32 `yaml:"dimension"`
|
Dimension int32 `yaml:"dimension"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the embedding model kind
|
// Returns the embedding model type
|
||||||
func (cfg Config) EmbeddingModelConfigKind() string {
|
func (cfg Config) EmbeddingModelConfigType() string {
|
||||||
return EmbeddingModelKind
|
return EmbeddingModelType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize a Gemini embedding model
|
// Initialize a Gemini embedding model
|
||||||
@@ -69,9 +69,9 @@ type EmbeddingModel struct {
|
|||||||
Config
|
Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the embedding model kind
|
// Returns the embedding model type
|
||||||
func (m EmbeddingModel) EmbeddingModelKind() string {
|
func (m EmbeddingModel) EmbeddingModelType() string {
|
||||||
return EmbeddingModelKind
|
return EmbeddingModelType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m EmbeddingModel) ToConfig() embeddingmodels.EmbeddingModelConfig {
|
func (m EmbeddingModel) ToConfig() embeddingmodels.EmbeddingModelConfig {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func TestParseFromYamlGemini(t *testing.T) {
|
|||||||
want: map[string]embeddingmodels.EmbeddingModelConfig{
|
want: map[string]embeddingmodels.EmbeddingModelConfig{
|
||||||
"my-gemini-model": gemini.Config{
|
"my-gemini-model": gemini.Config{
|
||||||
Name: "my-gemini-model",
|
Name: "my-gemini-model",
|
||||||
Kind: gemini.EmbeddingModelKind,
|
Type: gemini.EmbeddingModelType,
|
||||||
Model: "text-embedding-004",
|
Model: "text-embedding-004",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -60,7 +60,7 @@ func TestParseFromYamlGemini(t *testing.T) {
|
|||||||
want: map[string]embeddingmodels.EmbeddingModelConfig{
|
want: map[string]embeddingmodels.EmbeddingModelConfig{
|
||||||
"complex-gemini": gemini.Config{
|
"complex-gemini": gemini.Config{
|
||||||
Name: "complex-gemini",
|
Name: "complex-gemini",
|
||||||
Kind: gemini.EmbeddingModelKind,
|
Type: gemini.EmbeddingModelType,
|
||||||
Model: "text-embedding-004",
|
Model: "text-embedding-004",
|
||||||
ApiKey: "test-api-key",
|
ApiKey: "test-api-key",
|
||||||
Dimension: 768,
|
Dimension: 768,
|
||||||
|
|||||||
@@ -46,9 +46,6 @@ tools:
|
|||||||
create_backup:
|
create_backup:
|
||||||
kind: cloud-sql-create-backup
|
kind: cloud-sql-create-backup
|
||||||
source: cloud-sql-admin-source
|
source: cloud-sql-admin-source
|
||||||
restore_backup:
|
|
||||||
kind: cloud-sql-restore-backup
|
|
||||||
source: cloud-sql-admin-source
|
|
||||||
|
|
||||||
toolsets:
|
toolsets:
|
||||||
cloud_sql_mssql_admin_tools:
|
cloud_sql_mssql_admin_tools:
|
||||||
@@ -61,4 +58,3 @@ toolsets:
|
|||||||
- wait_for_operation
|
- wait_for_operation
|
||||||
- clone_instance
|
- clone_instance
|
||||||
- create_backup
|
- create_backup
|
||||||
- restore_backup
|
|
||||||
|
|||||||
@@ -46,9 +46,6 @@ tools:
|
|||||||
create_backup:
|
create_backup:
|
||||||
kind: cloud-sql-create-backup
|
kind: cloud-sql-create-backup
|
||||||
source: cloud-sql-admin-source
|
source: cloud-sql-admin-source
|
||||||
restore_backup:
|
|
||||||
kind: cloud-sql-restore-backup
|
|
||||||
source: cloud-sql-admin-source
|
|
||||||
|
|
||||||
toolsets:
|
toolsets:
|
||||||
cloud_sql_mysql_admin_tools:
|
cloud_sql_mysql_admin_tools:
|
||||||
@@ -61,4 +58,3 @@ toolsets:
|
|||||||
- wait_for_operation
|
- wait_for_operation
|
||||||
- clone_instance
|
- clone_instance
|
||||||
- create_backup
|
- create_backup
|
||||||
- restore_backup
|
|
||||||
|
|||||||
@@ -49,9 +49,6 @@ tools:
|
|||||||
create_backup:
|
create_backup:
|
||||||
kind: cloud-sql-create-backup
|
kind: cloud-sql-create-backup
|
||||||
source: cloud-sql-admin-source
|
source: cloud-sql-admin-source
|
||||||
restore_backup:
|
|
||||||
kind: cloud-sql-restore-backup
|
|
||||||
source: cloud-sql-admin-source
|
|
||||||
|
|
||||||
toolsets:
|
toolsets:
|
||||||
cloud_sql_postgres_admin_tools:
|
cloud_sql_postgres_admin_tools:
|
||||||
@@ -65,4 +62,3 @@ toolsets:
|
|||||||
- postgres_upgrade_precheck
|
- postgres_upgrade_precheck
|
||||||
- clone_instance
|
- clone_instance
|
||||||
- create_backup
|
- create_backup
|
||||||
- restore_backup
|
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ type Message = prompts.Message
|
|||||||
|
|
||||||
const kind = "custom"
|
const kind = "custom"
|
||||||
|
|
||||||
// init registers this prompt kind with the prompt framework.
|
// init registers this prompt type with the prompt framework.
|
||||||
func init() {
|
func init() {
|
||||||
if !prompts.Register(kind, newConfig) {
|
if !prompts.Register(kind, newConfig) {
|
||||||
panic(fmt.Sprintf("prompt kind %q already registered", kind))
|
panic(fmt.Sprintf("prompt type %q already registered", kind))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ type Config struct {
|
|||||||
var _ prompts.PromptConfig = Config{}
|
var _ prompts.PromptConfig = Config{}
|
||||||
var _ prompts.Prompt = Prompt{}
|
var _ prompts.Prompt = Prompt{}
|
||||||
|
|
||||||
func (c Config) PromptConfigKind() string {
|
func (c Config) PromptConfigType() string {
|
||||||
return kind
|
return kind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ func TestConfig(t *testing.T) {
|
|||||||
if p == nil {
|
if p == nil {
|
||||||
t.Fatal("Initialize() returned a nil prompt")
|
t.Fatal("Initialize() returned a nil prompt")
|
||||||
}
|
}
|
||||||
if cfg.PromptConfigKind() != "custom" {
|
if cfg.PromptConfigType() != "custom" {
|
||||||
t.Errorf("PromptConfigKind() = %q, want %q", cfg.PromptConfigKind(), "custom")
|
t.Errorf("PromptConfigType() = %q, want %q", cfg.PromptConfigType(), "custom")
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Manifest", func(t *testing.T) {
|
t.Run("Manifest", func(t *testing.T) {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func DecodeConfig(ctx context.Context, kind, name string, decoder *yaml.Decoder)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
return nil, fmt.Errorf("unknown prompt kind: %q", kind)
|
return nil, fmt.Errorf("unknown prompt type: %q", kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
promptConfig, err := factory(ctx, name, decoder)
|
promptConfig, err := factory(ctx, name, decoder)
|
||||||
@@ -63,7 +63,7 @@ func DecodeConfig(ctx context.Context, kind, name string, decoder *yaml.Decoder)
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PromptConfig interface {
|
type PromptConfig interface {
|
||||||
PromptConfigKind() string
|
PromptConfigType() string
|
||||||
Initialize() (Prompt, error)
|
Initialize() (Prompt, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,16 +29,16 @@ import (
|
|||||||
|
|
||||||
type mockPromptConfig struct {
|
type mockPromptConfig struct {
|
||||||
name string
|
name string
|
||||||
kind string
|
Type string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockPromptConfig) PromptConfigKind() string { return m.kind }
|
func (m *mockPromptConfig) PromptConfigType() string { return m.Type }
|
||||||
func (m *mockPromptConfig) Initialize() (prompts.Prompt, error) { return nil, nil }
|
func (m *mockPromptConfig) Initialize() (prompts.Prompt, error) { return nil, nil }
|
||||||
|
|
||||||
var errMockFactory = errors.New("mock factory error")
|
var errMockFactory = errors.New("mock factory error")
|
||||||
|
|
||||||
func mockFactory(ctx context.Context, name string, decoder *yaml.Decoder) (prompts.PromptConfig, error) {
|
func mockFactory(ctx context.Context, name string, decoder *yaml.Decoder) (prompts.PromptConfig, error) {
|
||||||
return &mockPromptConfig{name: name, kind: "mockKind"}, nil
|
return &mockPromptConfig{name: name, Type: "mockType"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func mockErrorFactory(ctx context.Context, name string, decoder *yaml.Decoder) (prompts.PromptConfig, error) {
|
func mockErrorFactory(ctx context.Context, name string, decoder *yaml.Decoder) (prompts.PromptConfig, error) {
|
||||||
@@ -50,7 +50,7 @@ func TestRegistry(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
t.Run("RegisterAndDecodeSuccess", func(t *testing.T) {
|
t.Run("RegisterAndDecodeSuccess", func(t *testing.T) {
|
||||||
kind := "testKindSuccess"
|
kind := "testTypeSuccess"
|
||||||
if !prompts.Register(kind, mockFactory) {
|
if !prompts.Register(kind, mockFactory) {
|
||||||
t.Fatal("expected registration to succeed")
|
t.Fatal("expected registration to succeed")
|
||||||
}
|
}
|
||||||
@@ -69,19 +69,19 @@ func TestRegistry(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("DecodeUnknownKind", func(t *testing.T) {
|
t.Run("DecodeUnknownType", func(t *testing.T) {
|
||||||
decoder := yaml.NewDecoder(strings.NewReader(""))
|
decoder := yaml.NewDecoder(strings.NewReader(""))
|
||||||
_, err := prompts.DecodeConfig(ctx, "unregisteredKind", "testPrompt", decoder)
|
_, err := prompts.DecodeConfig(ctx, "unregisteredType", "testPrompt", decoder)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected an error for unknown kind, but got nil")
|
t.Fatal("expected an error for unknown kind, but got nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(err.Error(), "unknown prompt kind") {
|
if !strings.Contains(err.Error(), "unknown prompt type") {
|
||||||
t.Errorf("expected error to contain 'unknown prompt kind', but got: %v", err)
|
t.Errorf("expected error to contain 'unknown prompt type', but got: %v", err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("FactoryReturnsError", func(t *testing.T) {
|
t.Run("FactoryReturnsError", func(t *testing.T) {
|
||||||
kind := "testKindError"
|
kind := "testTypeError"
|
||||||
if !prompts.Register(kind, mockErrorFactory) {
|
if !prompts.Register(kind, mockErrorFactory) {
|
||||||
t.Fatal("expected registration to succeed")
|
t.Fatal("expected registration to succeed")
|
||||||
}
|
}
|
||||||
@@ -105,8 +105,8 @@ func TestRegistry(t *testing.T) {
|
|||||||
if config == nil {
|
if config == nil {
|
||||||
t.Fatal("expected a non-nil config for default kind")
|
t.Fatal("expected a non-nil config for default kind")
|
||||||
}
|
}
|
||||||
if config.PromptConfigKind() != "custom" {
|
if config.PromptConfigType() != "custom" {
|
||||||
t.Errorf("expected default kind to be 'custom', but got %q", config.PromptConfigKind())
|
t.Errorf("expected default kind to be 'custom', but got %q", config.PromptConfigType())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ func (c *AuthServiceConfigs) UnmarshalYAML(ctx context.Context, unmarshal func(i
|
|||||||
return fmt.Errorf("error creating decoder: %w", err)
|
return fmt.Errorf("error creating decoder: %w", err)
|
||||||
}
|
}
|
||||||
switch kind {
|
switch kind {
|
||||||
case google.AuthServiceKind:
|
case google.AuthServiceType:
|
||||||
actual := google.Config{Name: name}
|
actual := google.Config{Name: name}
|
||||||
if err := dec.DecodeContext(ctx, &actual); err != nil {
|
if err := dec.DecodeContext(ctx, &actual); err != nil {
|
||||||
return fmt.Errorf("unable to parse as %q: %w", kind, err)
|
return fmt.Errorf("unable to parse as %q: %w", kind, err)
|
||||||
@@ -242,7 +242,7 @@ func (c *EmbeddingModelConfigs) UnmarshalYAML(ctx context.Context, unmarshal fun
|
|||||||
return fmt.Errorf("error creating decoder: %w", err)
|
return fmt.Errorf("error creating decoder: %w", err)
|
||||||
}
|
}
|
||||||
switch kind {
|
switch kind {
|
||||||
case gemini.EmbeddingModelKind:
|
case gemini.EmbeddingModelType:
|
||||||
actual := gemini.Config{Name: name}
|
actual := gemini.Config{Name: name}
|
||||||
if err := dec.DecodeContext(ctx, &actual); err != nil {
|
if err := dec.DecodeContext(ctx, &actual); err != nil {
|
||||||
return fmt.Errorf("unable to parse as %q: %w", kind, err)
|
return fmt.Errorf("unable to parse as %q: %w", kind, err)
|
||||||
|
|||||||
@@ -27,21 +27,19 @@ import (
|
|||||||
v20241105 "github.com/googleapis/genai-toolbox/internal/server/mcp/v20241105"
|
v20241105 "github.com/googleapis/genai-toolbox/internal/server/mcp/v20241105"
|
||||||
v20250326 "github.com/googleapis/genai-toolbox/internal/server/mcp/v20250326"
|
v20250326 "github.com/googleapis/genai-toolbox/internal/server/mcp/v20250326"
|
||||||
v20250618 "github.com/googleapis/genai-toolbox/internal/server/mcp/v20250618"
|
v20250618 "github.com/googleapis/genai-toolbox/internal/server/mcp/v20250618"
|
||||||
v20251125 "github.com/googleapis/genai-toolbox/internal/server/mcp/v20251125"
|
|
||||||
"github.com/googleapis/genai-toolbox/internal/server/resources"
|
"github.com/googleapis/genai-toolbox/internal/server/resources"
|
||||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
"github.com/googleapis/genai-toolbox/internal/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
// LATEST_PROTOCOL_VERSION is the latest version of the MCP protocol supported.
|
// LATEST_PROTOCOL_VERSION is the latest version of the MCP protocol supported.
|
||||||
// Update the version used in InitializeResponse when this value is updated.
|
// Update the version used in InitializeResponse when this value is updated.
|
||||||
const LATEST_PROTOCOL_VERSION = v20251125.PROTOCOL_VERSION
|
const LATEST_PROTOCOL_VERSION = v20250618.PROTOCOL_VERSION
|
||||||
|
|
||||||
// SUPPORTED_PROTOCOL_VERSIONS is the MCP protocol versions that are supported.
|
// SUPPORTED_PROTOCOL_VERSIONS is the MCP protocol versions that are supported.
|
||||||
var SUPPORTED_PROTOCOL_VERSIONS = []string{
|
var SUPPORTED_PROTOCOL_VERSIONS = []string{
|
||||||
v20241105.PROTOCOL_VERSION,
|
v20241105.PROTOCOL_VERSION,
|
||||||
v20250326.PROTOCOL_VERSION,
|
v20250326.PROTOCOL_VERSION,
|
||||||
v20250618.PROTOCOL_VERSION,
|
v20250618.PROTOCOL_VERSION,
|
||||||
v20251125.PROTOCOL_VERSION,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializeResponse runs capability negotiation and protocol version agreement.
|
// InitializeResponse runs capability negotiation and protocol version agreement.
|
||||||
@@ -104,8 +102,6 @@ func NotificationHandler(ctx context.Context, body []byte) error {
|
|||||||
// This is the Operation phase of the lifecycle for MCP client-server connections.
|
// This is the Operation phase of the lifecycle for MCP client-server connections.
|
||||||
func ProcessMethod(ctx context.Context, mcpVersion string, id jsonrpc.RequestId, method string, toolset tools.Toolset, promptset prompts.Promptset, resourceMgr *resources.ResourceManager, body []byte, header http.Header) (any, error) {
|
func ProcessMethod(ctx context.Context, mcpVersion string, id jsonrpc.RequestId, method string, toolset tools.Toolset, promptset prompts.Promptset, resourceMgr *resources.ResourceManager, body []byte, header http.Header) (any, error) {
|
||||||
switch mcpVersion {
|
switch mcpVersion {
|
||||||
case v20251125.PROTOCOL_VERSION:
|
|
||||||
return v20251125.ProcessMethod(ctx, id, method, toolset, promptset, resourceMgr, body, header)
|
|
||||||
case v20250618.PROTOCOL_VERSION:
|
case v20250618.PROTOCOL_VERSION:
|
||||||
return v20250618.ProcessMethod(ctx, id, method, toolset, promptset, resourceMgr, body, header)
|
return v20250618.ProcessMethod(ctx, id, method, toolset, promptset, resourceMgr, body, header)
|
||||||
case v20250326.PROTOCOL_VERSION:
|
case v20250326.PROTOCOL_VERSION:
|
||||||
|
|||||||
@@ -1,326 +0,0 @@
|
|||||||
// Copyright 2026 Google LLC
|
|
||||||
//
|
|
||||||
// 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 v20251125
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/googleapis/genai-toolbox/internal/prompts"
|
|
||||||
"github.com/googleapis/genai-toolbox/internal/server/mcp/jsonrpc"
|
|
||||||
"github.com/googleapis/genai-toolbox/internal/server/resources"
|
|
||||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
|
||||||
"github.com/googleapis/genai-toolbox/internal/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ProcessMethod returns a response for the request.
|
|
||||||
func ProcessMethod(ctx context.Context, id jsonrpc.RequestId, method string, toolset tools.Toolset, promptset prompts.Promptset, resourceMgr *resources.ResourceManager, body []byte, header http.Header) (any, error) {
|
|
||||||
switch method {
|
|
||||||
case PING:
|
|
||||||
return pingHandler(id)
|
|
||||||
case TOOLS_LIST:
|
|
||||||
return toolsListHandler(id, toolset, body)
|
|
||||||
case TOOLS_CALL:
|
|
||||||
return toolsCallHandler(ctx, id, resourceMgr, body, header)
|
|
||||||
case PROMPTS_LIST:
|
|
||||||
return promptsListHandler(ctx, id, promptset, body)
|
|
||||||
case PROMPTS_GET:
|
|
||||||
return promptsGetHandler(ctx, id, resourceMgr, body)
|
|
||||||
default:
|
|
||||||
err := fmt.Errorf("invalid method %s", method)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.METHOD_NOT_FOUND, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// pingHandler handles the "ping" method by returning an empty response.
|
|
||||||
func pingHandler(id jsonrpc.RequestId) (any, error) {
|
|
||||||
return jsonrpc.JSONRPCResponse{
|
|
||||||
Jsonrpc: jsonrpc.JSONRPC_VERSION,
|
|
||||||
Id: id,
|
|
||||||
Result: struct{}{},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func toolsListHandler(id jsonrpc.RequestId, toolset tools.Toolset, body []byte) (any, error) {
|
|
||||||
var req ListToolsRequest
|
|
||||||
if err := json.Unmarshal(body, &req); err != nil {
|
|
||||||
err = fmt.Errorf("invalid mcp tools list request: %w", err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
|
|
||||||
result := ListToolsResult{
|
|
||||||
Tools: toolset.McpManifest,
|
|
||||||
}
|
|
||||||
return jsonrpc.JSONRPCResponse{
|
|
||||||
Jsonrpc: jsonrpc.JSONRPC_VERSION,
|
|
||||||
Id: id,
|
|
||||||
Result: result,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// toolsCallHandler generate a response for tools call.
|
|
||||||
func toolsCallHandler(ctx context.Context, id jsonrpc.RequestId, resourceMgr *resources.ResourceManager, body []byte, header http.Header) (any, error) {
|
|
||||||
authServices := resourceMgr.GetAuthServiceMap()
|
|
||||||
|
|
||||||
// retrieve logger from context
|
|
||||||
logger, err := util.LoggerFromContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
|
|
||||||
var req CallToolRequest
|
|
||||||
if err = json.Unmarshal(body, &req); err != nil {
|
|
||||||
err = fmt.Errorf("invalid mcp tools call request: %w", err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
|
|
||||||
toolName := req.Params.Name
|
|
||||||
toolArgument := req.Params.Arguments
|
|
||||||
logger.DebugContext(ctx, fmt.Sprintf("tool name: %s", toolName))
|
|
||||||
tool, ok := resourceMgr.GetTool(toolName)
|
|
||||||
if !ok {
|
|
||||||
err = fmt.Errorf("invalid tool name: tool with name %q does not exist", toolName)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_PARAMS, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get access token
|
|
||||||
authTokenHeadername, err := tool.GetAuthTokenHeaderName(resourceMgr)
|
|
||||||
if err != nil {
|
|
||||||
errMsg := fmt.Errorf("error during invocation: %w", err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, errMsg.Error(), nil), errMsg
|
|
||||||
}
|
|
||||||
accessToken := tools.AccessToken(header.Get(authTokenHeadername))
|
|
||||||
|
|
||||||
// Check if this specific tool requires the standard authorization header
|
|
||||||
clientAuth, err := tool.RequiresClientAuthorization(resourceMgr)
|
|
||||||
if err != nil {
|
|
||||||
errMsg := fmt.Errorf("error during invocation: %w", err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, errMsg.Error(), nil), errMsg
|
|
||||||
}
|
|
||||||
if clientAuth {
|
|
||||||
if accessToken == "" {
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, "missing access token in the 'Authorization' header", nil), util.ErrUnauthorized
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// marshal arguments and decode it using decodeJSON instead to prevent loss between floats/int.
|
|
||||||
aMarshal, err := json.Marshal(toolArgument)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("unable to marshal tools argument: %w", err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
|
|
||||||
var data map[string]any
|
|
||||||
if err = util.DecodeJSON(bytes.NewBuffer(aMarshal), &data); err != nil {
|
|
||||||
err = fmt.Errorf("unable to decode tools argument: %w", err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tool authentication
|
|
||||||
// claimsFromAuth maps the name of the authservice to the claims retrieved from it.
|
|
||||||
claimsFromAuth := make(map[string]map[string]any)
|
|
||||||
|
|
||||||
// if using stdio, header will be nil and auth will not be supported
|
|
||||||
if header != nil {
|
|
||||||
for _, aS := range authServices {
|
|
||||||
claims, err := aS.GetClaimsFromHeader(ctx, header)
|
|
||||||
if err != nil {
|
|
||||||
logger.DebugContext(ctx, err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if claims == nil {
|
|
||||||
// authService not present in header
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
claimsFromAuth[aS.GetName()] = claims
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tool authorization check
|
|
||||||
verifiedAuthServices := make([]string, len(claimsFromAuth))
|
|
||||||
i := 0
|
|
||||||
for k := range claimsFromAuth {
|
|
||||||
verifiedAuthServices[i] = k
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if any of the specified auth services is verified
|
|
||||||
isAuthorized := tool.Authorized(verifiedAuthServices)
|
|
||||||
if !isAuthorized {
|
|
||||||
err = fmt.Errorf("unauthorized Tool call: Please make sure your specify correct auth headers: %w", util.ErrUnauthorized)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
logger.DebugContext(ctx, "tool invocation authorized")
|
|
||||||
|
|
||||||
params, err := tool.ParseParams(data, claimsFromAuth)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("provided parameters were invalid: %w", err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_PARAMS, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
logger.DebugContext(ctx, fmt.Sprintf("invocation params: %s", params))
|
|
||||||
|
|
||||||
// run tool invocation and generate response.
|
|
||||||
results, err := tool.Invoke(ctx, resourceMgr, params, accessToken)
|
|
||||||
if err != nil {
|
|
||||||
errStr := err.Error()
|
|
||||||
// Missing authService tokens.
|
|
||||||
if errors.Is(err, util.ErrUnauthorized) {
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
// Upstream auth error
|
|
||||||
if strings.Contains(errStr, "Error 401") || strings.Contains(errStr, "Error 403") {
|
|
||||||
if clientAuth {
|
|
||||||
// Error with client credentials should pass down to the client
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
// Auth error with ADC should raise internal 500 error
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
text := TextContent{
|
|
||||||
Type: "text",
|
|
||||||
Text: err.Error(),
|
|
||||||
}
|
|
||||||
return jsonrpc.JSONRPCResponse{
|
|
||||||
Jsonrpc: jsonrpc.JSONRPC_VERSION,
|
|
||||||
Id: id,
|
|
||||||
Result: CallToolResult{Content: []TextContent{text}, IsError: true},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
content := make([]TextContent, 0)
|
|
||||||
|
|
||||||
sliceRes, ok := results.([]any)
|
|
||||||
if !ok {
|
|
||||||
sliceRes = []any{results}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, d := range sliceRes {
|
|
||||||
text := TextContent{Type: "text"}
|
|
||||||
dM, err := json.Marshal(d)
|
|
||||||
if err != nil {
|
|
||||||
text.Text = fmt.Sprintf("fail to marshal: %s, result: %s", err, d)
|
|
||||||
} else {
|
|
||||||
text.Text = string(dM)
|
|
||||||
}
|
|
||||||
content = append(content, text)
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsonrpc.JSONRPCResponse{
|
|
||||||
Jsonrpc: jsonrpc.JSONRPC_VERSION,
|
|
||||||
Id: id,
|
|
||||||
Result: CallToolResult{Content: content},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// promptsListHandler handles the "prompts/list" method.
|
|
||||||
func promptsListHandler(ctx context.Context, id jsonrpc.RequestId, promptset prompts.Promptset, body []byte) (any, error) {
|
|
||||||
// retrieve logger from context
|
|
||||||
logger, err := util.LoggerFromContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
logger.DebugContext(ctx, "handling prompts/list request")
|
|
||||||
|
|
||||||
var req ListPromptsRequest
|
|
||||||
if err := json.Unmarshal(body, &req); err != nil {
|
|
||||||
err = fmt.Errorf("invalid mcp prompts list request: %w", err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
|
|
||||||
result := ListPromptsResult{
|
|
||||||
Prompts: promptset.McpManifest,
|
|
||||||
}
|
|
||||||
logger.DebugContext(ctx, fmt.Sprintf("returning %d prompts", len(promptset.McpManifest)))
|
|
||||||
return jsonrpc.JSONRPCResponse{
|
|
||||||
Jsonrpc: jsonrpc.JSONRPC_VERSION,
|
|
||||||
Id: id,
|
|
||||||
Result: result,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// promptsGetHandler handles the "prompts/get" method.
|
|
||||||
func promptsGetHandler(ctx context.Context, id jsonrpc.RequestId, resourceMgr *resources.ResourceManager, body []byte) (any, error) {
|
|
||||||
// retrieve logger from context
|
|
||||||
logger, err := util.LoggerFromContext(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
logger.DebugContext(ctx, "handling prompts/get request")
|
|
||||||
|
|
||||||
var req GetPromptRequest
|
|
||||||
if err := json.Unmarshal(body, &req); err != nil {
|
|
||||||
err = fmt.Errorf("invalid mcp prompts/get request: %w", err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
|
|
||||||
promptName := req.Params.Name
|
|
||||||
logger.DebugContext(ctx, fmt.Sprintf("prompt name: %s", promptName))
|
|
||||||
prompt, ok := resourceMgr.GetPrompt(promptName)
|
|
||||||
if !ok {
|
|
||||||
err := fmt.Errorf("prompt with name %q does not exist", promptName)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_PARAMS, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the arguments provided in the request.
|
|
||||||
argValues, err := prompt.ParseArgs(req.Params.Arguments, nil)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("invalid arguments for prompt %q: %w", promptName, err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INVALID_PARAMS, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
logger.DebugContext(ctx, fmt.Sprintf("parsed args: %v", argValues))
|
|
||||||
|
|
||||||
// Substitute the argument values into the prompt's messages.
|
|
||||||
substituted, err := prompt.SubstituteParams(argValues)
|
|
||||||
if err != nil {
|
|
||||||
err = fmt.Errorf("error substituting params for prompt %q: %w", promptName, err)
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cast the result to the expected []prompts.Message type.
|
|
||||||
substitutedMessages, ok := substituted.([]prompts.Message)
|
|
||||||
if !ok {
|
|
||||||
err = fmt.Errorf("internal error: SubstituteParams returned unexpected type")
|
|
||||||
return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err
|
|
||||||
}
|
|
||||||
logger.DebugContext(ctx, "substituted params successfully")
|
|
||||||
|
|
||||||
// Format the response messages into the required structure.
|
|
||||||
promptMessages := make([]PromptMessage, len(substitutedMessages))
|
|
||||||
for i, msg := range substitutedMessages {
|
|
||||||
promptMessages[i] = PromptMessage{
|
|
||||||
Role: msg.Role,
|
|
||||||
Content: TextContent{
|
|
||||||
Type: "text",
|
|
||||||
Text: msg.Content,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result := GetPromptResult{
|
|
||||||
Description: prompt.Manifest().Description,
|
|
||||||
Messages: promptMessages,
|
|
||||||
}
|
|
||||||
|
|
||||||
return jsonrpc.JSONRPCResponse{
|
|
||||||
Jsonrpc: jsonrpc.JSONRPC_VERSION,
|
|
||||||
Id: id,
|
|
||||||
Result: result,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
@@ -1,219 +0,0 @@
|
|||||||
// Copyright 2026 Google LLC
|
|
||||||
//
|
|
||||||
// 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 v20251125
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/googleapis/genai-toolbox/internal/prompts"
|
|
||||||
"github.com/googleapis/genai-toolbox/internal/server/mcp/jsonrpc"
|
|
||||||
"github.com/googleapis/genai-toolbox/internal/tools"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SERVER_NAME is the server name used in Implementation.
|
|
||||||
const SERVER_NAME = "Toolbox"
|
|
||||||
|
|
||||||
// PROTOCOL_VERSION is the version of the MCP protocol in this package.
|
|
||||||
const PROTOCOL_VERSION = "2025-11-25"
|
|
||||||
|
|
||||||
// methods that are supported.
|
|
||||||
const (
|
|
||||||
PING = "ping"
|
|
||||||
TOOLS_LIST = "tools/list"
|
|
||||||
TOOLS_CALL = "tools/call"
|
|
||||||
PROMPTS_LIST = "prompts/list"
|
|
||||||
PROMPTS_GET = "prompts/get"
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Empty result */
|
|
||||||
|
|
||||||
// EmptyResult represents a response that indicates success but carries no data.
|
|
||||||
type EmptyResult jsonrpc.Result
|
|
||||||
|
|
||||||
/* Pagination */
|
|
||||||
|
|
||||||
// Cursor is an opaque token used to represent a cursor for pagination.
|
|
||||||
type Cursor string
|
|
||||||
|
|
||||||
type PaginatedRequest struct {
|
|
||||||
jsonrpc.Request
|
|
||||||
Params struct {
|
|
||||||
// An opaque token representing the current pagination position.
|
|
||||||
// If provided, the server should return results starting after this cursor.
|
|
||||||
Cursor Cursor `json:"cursor,omitempty"`
|
|
||||||
} `json:"params,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PaginatedResult struct {
|
|
||||||
jsonrpc.Result
|
|
||||||
// An opaque token representing the pagination position after the last returned result.
|
|
||||||
// If present, there may be more results available.
|
|
||||||
NextCursor Cursor `json:"nextCursor,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Tools */
|
|
||||||
|
|
||||||
// Sent from the client to request a list of tools the server has.
|
|
||||||
type ListToolsRequest struct {
|
|
||||||
PaginatedRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
// The server's response to a tools/list request from the client.
|
|
||||||
type ListToolsResult struct {
|
|
||||||
PaginatedResult
|
|
||||||
Tools []tools.McpManifest `json:"tools"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used by the client to invoke a tool provided by the server.
|
|
||||||
type CallToolRequest struct {
|
|
||||||
jsonrpc.Request
|
|
||||||
Params struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Arguments map[string]any `json:"arguments,omitempty"`
|
|
||||||
} `json:"params,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// The sender or recipient of messages and data in a conversation.
|
|
||||||
type Role string
|
|
||||||
|
|
||||||
const (
|
|
||||||
RoleUser Role = "user"
|
|
||||||
RoleAssistant Role = "assistant"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Base for objects that include optional annotations for the client.
|
|
||||||
// The client can use annotations to inform how objects are used or displayed
|
|
||||||
type Annotated struct {
|
|
||||||
Annotations *struct {
|
|
||||||
// Describes who the intended customer of this object or data is.
|
|
||||||
// It can include multiple entries to indicate content useful for multiple
|
|
||||||
// audiences (e.g., `["user", "assistant"]`).
|
|
||||||
Audience []Role `json:"audience,omitempty"`
|
|
||||||
// Describes how important this data is for operating the server.
|
|
||||||
//
|
|
||||||
// A value of 1 means "most important," and indicates that the data is
|
|
||||||
// effectively required, while 0 means "least important," and indicates that
|
|
||||||
// the data is entirely optional.
|
|
||||||
//
|
|
||||||
// @TJS-type number
|
|
||||||
// @minimum 0
|
|
||||||
// @maximum 1
|
|
||||||
Priority float64 `json:"priority,omitempty"`
|
|
||||||
} `json:"annotations,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TextContent represents text provided to or from an LLM.
|
|
||||||
type TextContent struct {
|
|
||||||
Annotated
|
|
||||||
Type string `json:"type"`
|
|
||||||
// The text content of the message.
|
|
||||||
Text string `json:"text"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// The server's response to a tool call.
|
|
||||||
//
|
|
||||||
// Any errors that originate from the tool SHOULD be reported inside the result
|
|
||||||
// object, with `isError` set to true, _not_ as an MCP protocol-level error
|
|
||||||
// response. Otherwise, the LLM would not be able to see that an error occurred
|
|
||||||
// and self-correct.
|
|
||||||
//
|
|
||||||
// However, any errors in _finding_ the tool, an error indicating that the
|
|
||||||
// server does not support tool calls, or any other exceptional conditions,
|
|
||||||
// should be reported as an MCP error response.
|
|
||||||
type CallToolResult struct {
|
|
||||||
jsonrpc.Result
|
|
||||||
// Could be either a TextContent, ImageContent, or EmbeddedResources
|
|
||||||
// For Toolbox, we will only be sending TextContent
|
|
||||||
Content []TextContent `json:"content"`
|
|
||||||
// Whether the tool call ended in an error.
|
|
||||||
// If not set, this is assumed to be false (the call was successful).
|
|
||||||
//
|
|
||||||
// Any errors that originate from the tool SHOULD be reported inside the result
|
|
||||||
// object, with `isError` set to true, _not_ as an MCP protocol-level error
|
|
||||||
// response. Otherwise, the LLM would not be able to see that an error occurred
|
|
||||||
// and self-correct.
|
|
||||||
//
|
|
||||||
// However, any errors in _finding_ the tool, an error indicating that the
|
|
||||||
// server does not support tool calls, or any other exceptional conditions,
|
|
||||||
// should be reported as an MCP error response.
|
|
||||||
IsError bool `json:"isError,omitempty"`
|
|
||||||
// An optional JSON object that represents the structured result of the tool call.
|
|
||||||
StructuredContent map[string]any `json:"structuredContent,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Additional properties describing a Tool to clients.
|
|
||||||
//
|
|
||||||
// NOTE: all properties in ToolAnnotations are **hints**.
|
|
||||||
// They are not guaranteed to provide a faithful description of
|
|
||||||
// tool behavior (including descriptive properties like `title`).
|
|
||||||
//
|
|
||||||
// Clients should never make tool use decisions based on ToolAnnotations
|
|
||||||
// received from untrusted servers.
|
|
||||||
type ToolAnnotations struct {
|
|
||||||
// A human-readable title for the tool.
|
|
||||||
Title string `json:"title,omitempty"`
|
|
||||||
// If true, the tool does not modify its environment.
|
|
||||||
// Default: false
|
|
||||||
ReadOnlyHint bool `json:"readOnlyHint,omitempty"`
|
|
||||||
// If true, the tool may perform destructive updates to its environment.
|
|
||||||
// If false, the tool performs only additive updates.
|
|
||||||
// (This property is meaningful only when `readOnlyHint == false`)
|
|
||||||
// Default: true
|
|
||||||
DestructiveHint bool `json:"destructiveHint,omitempty"`
|
|
||||||
// If true, calling the tool repeatedly with the same arguments
|
|
||||||
// will have no additional effect on the its environment.
|
|
||||||
// (This property is meaningful only when `readOnlyHint == false`)
|
|
||||||
// Default: false
|
|
||||||
IdempotentHint bool `json:"idempotentHint,omitempty"`
|
|
||||||
// If true, this tool may interact with an "open world" of external
|
|
||||||
// entities. If false, the tool's domain of interaction is closed.
|
|
||||||
// For example, the world of a web search tool is open, whereas that
|
|
||||||
// of a memory tool is not.
|
|
||||||
// Default: true
|
|
||||||
OpenWorldHint bool `json:"openWorldHint,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Prompts */
|
|
||||||
|
|
||||||
// Sent from the client to request a list of prompts the server has.
|
|
||||||
type ListPromptsRequest struct {
|
|
||||||
PaginatedRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
// The server's response to a prompts/list request from the client.
|
|
||||||
type ListPromptsResult struct {
|
|
||||||
PaginatedResult
|
|
||||||
Prompts []prompts.McpManifest `json:"prompts"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used by the client to get a prompt provided by the server.
|
|
||||||
type GetPromptRequest struct {
|
|
||||||
jsonrpc.Request
|
|
||||||
Params struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Arguments map[string]any `json:"arguments,omitempty"`
|
|
||||||
} `json:"params"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// The server's response to a prompts/get request from the client.
|
|
||||||
type GetPromptResult struct {
|
|
||||||
jsonrpc.Result
|
|
||||||
Description string `json:"description,omitempty"`
|
|
||||||
Messages []PromptMessage `json:"messages"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Describes a message returned as part of a prompt.
|
|
||||||
type PromptMessage struct {
|
|
||||||
Role string `json:"role"`
|
|
||||||
Content TextContent `json:"content"`
|
|
||||||
}
|
|
||||||
@@ -37,7 +37,6 @@ const jsonrpcVersion = "2.0"
|
|||||||
const protocolVersion20241105 = "2024-11-05"
|
const protocolVersion20241105 = "2024-11-05"
|
||||||
const protocolVersion20250326 = "2025-03-26"
|
const protocolVersion20250326 = "2025-03-26"
|
||||||
const protocolVersion20250618 = "2025-06-18"
|
const protocolVersion20250618 = "2025-06-18"
|
||||||
const protocolVersion20251125 = "2025-11-25"
|
|
||||||
const serverName = "Toolbox"
|
const serverName = "Toolbox"
|
||||||
|
|
||||||
var basicInputSchema = map[string]any{
|
var basicInputSchema = map[string]any{
|
||||||
@@ -486,23 +485,6 @@ func TestMcpEndpoint(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "version 2025-11-25",
|
|
||||||
protocol: protocolVersion20251125,
|
|
||||||
idHeader: false,
|
|
||||||
initWant: map[string]any{
|
|
||||||
"jsonrpc": "2.0",
|
|
||||||
"id": "mcp-initialize",
|
|
||||||
"result": map[string]any{
|
|
||||||
"protocolVersion": "2025-11-25",
|
|
||||||
"capabilities": map[string]any{
|
|
||||||
"tools": map[string]any{"listChanged": false},
|
|
||||||
"prompts": map[string]any{"listChanged": false},
|
|
||||||
},
|
|
||||||
"serverInfo": map[string]any{"name": serverName, "version": fakeVersionString},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for _, vtc := range versTestCases {
|
for _, vtc := range versTestCases {
|
||||||
t.Run(vtc.name, func(t *testing.T) {
|
t.Run(vtc.name, func(t *testing.T) {
|
||||||
@@ -512,7 +494,8 @@ func TestMcpEndpoint(t *testing.T) {
|
|||||||
if sessionId != "" {
|
if sessionId != "" {
|
||||||
header["Mcp-Session-Id"] = sessionId
|
header["Mcp-Session-Id"] = sessionId
|
||||||
}
|
}
|
||||||
if vtc.protocol != protocolVersion20241105 && vtc.protocol != protocolVersion20250326 {
|
|
||||||
|
if vtc.protocol == protocolVersion20250618 {
|
||||||
header["MCP-Protocol-Version"] = vtc.protocol
|
header["MCP-Protocol-Version"] = vtc.protocol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func TestUpdateServer(t *testing.T) {
|
|||||||
"example-source": &alloydbpg.Source{
|
"example-source": &alloydbpg.Source{
|
||||||
Config: alloydbpg.Config{
|
Config: alloydbpg.Config{
|
||||||
Name: "example-alloydb-source",
|
Name: "example-alloydb-source",
|
||||||
Kind: "alloydb-postgres",
|
Type: "alloydb-postgres",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ func TestUpdateServer(t *testing.T) {
|
|||||||
"example-source2": &alloydbpg.Source{
|
"example-source2": &alloydbpg.Source{
|
||||||
Config: alloydbpg.Config{
|
Config: alloydbpg.Config{
|
||||||
Name: "example-alloydb-source2",
|
Name: "example-alloydb-source2",
|
||||||
Kind: "alloydb-postgres",
|
Type: "alloydb-postgres",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func InitializeConfigs(ctx context.Context, cfg ServerConfig) (
|
|||||||
childCtx, span := instrumentation.Tracer.Start(
|
childCtx, span := instrumentation.Tracer.Start(
|
||||||
ctx,
|
ctx,
|
||||||
"toolbox/server/source/init",
|
"toolbox/server/source/init",
|
||||||
trace.WithAttributes(attribute.String("source_kind", sc.SourceConfigKind())),
|
trace.WithAttributes(attribute.String("source_type", sc.SourceConfigType())),
|
||||||
trace.WithAttributes(attribute.String("source_name", name)),
|
trace.WithAttributes(attribute.String("source_name", name)),
|
||||||
)
|
)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
@@ -110,7 +110,7 @@ func InitializeConfigs(ctx context.Context, cfg ServerConfig) (
|
|||||||
_, span := instrumentation.Tracer.Start(
|
_, span := instrumentation.Tracer.Start(
|
||||||
ctx,
|
ctx,
|
||||||
"toolbox/server/auth/init",
|
"toolbox/server/auth/init",
|
||||||
trace.WithAttributes(attribute.String("auth_kind", sc.AuthServiceConfigKind())),
|
trace.WithAttributes(attribute.String("auth_type", sc.AuthServiceConfigType())),
|
||||||
trace.WithAttributes(attribute.String("auth_name", name)),
|
trace.WithAttributes(attribute.String("auth_name", name)),
|
||||||
)
|
)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
@@ -138,7 +138,7 @@ func InitializeConfigs(ctx context.Context, cfg ServerConfig) (
|
|||||||
_, span := instrumentation.Tracer.Start(
|
_, span := instrumentation.Tracer.Start(
|
||||||
ctx,
|
ctx,
|
||||||
"toolbox/server/embeddingmodel/init",
|
"toolbox/server/embeddingmodel/init",
|
||||||
trace.WithAttributes(attribute.String("model_kind", ec.EmbeddingModelConfigKind())),
|
trace.WithAttributes(attribute.String("model_type", ec.EmbeddingModelConfigType())),
|
||||||
trace.WithAttributes(attribute.String("model_name", name)),
|
trace.WithAttributes(attribute.String("model_name", name)),
|
||||||
)
|
)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
@@ -166,7 +166,7 @@ func InitializeConfigs(ctx context.Context, cfg ServerConfig) (
|
|||||||
_, span := instrumentation.Tracer.Start(
|
_, span := instrumentation.Tracer.Start(
|
||||||
ctx,
|
ctx,
|
||||||
"toolbox/server/tool/init",
|
"toolbox/server/tool/init",
|
||||||
trace.WithAttributes(attribute.String("tool_kind", tc.ToolConfigKind())),
|
trace.WithAttributes(attribute.String("tool_type", tc.ToolConfigType())),
|
||||||
trace.WithAttributes(attribute.String("tool_name", name)),
|
trace.WithAttributes(attribute.String("tool_name", name)),
|
||||||
)
|
)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
@@ -235,7 +235,7 @@ func InitializeConfigs(ctx context.Context, cfg ServerConfig) (
|
|||||||
_, span := instrumentation.Tracer.Start(
|
_, span := instrumentation.Tracer.Start(
|
||||||
ctx,
|
ctx,
|
||||||
"toolbox/server/prompt/init",
|
"toolbox/server/prompt/init",
|
||||||
trace.WithAttributes(attribute.String("prompt_kind", pc.PromptConfigKind())),
|
trace.WithAttributes(attribute.String("prompt_type", pc.PromptConfigType())),
|
||||||
trace.WithAttributes(attribute.String("prompt_name", name)),
|
trace.WithAttributes(attribute.String("prompt_name", name)),
|
||||||
)
|
)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
@@ -304,14 +304,10 @@ func hostCheck(allowedHosts map[string]struct{}) func(http.Handler) http.Handler
|
|||||||
return func(next http.Handler) http.Handler {
|
return func(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
_, hasWildcard := allowedHosts["*"]
|
_, hasWildcard := allowedHosts["*"]
|
||||||
hostname := r.Host
|
_, hostIsAllowed := allowedHosts[r.Host]
|
||||||
if host, _, err := net.SplitHostPort(r.Host); err == nil {
|
|
||||||
hostname = host
|
|
||||||
}
|
|
||||||
_, hostIsAllowed := allowedHosts[hostname]
|
|
||||||
if !hasWildcard && !hostIsAllowed {
|
if !hasWildcard && !hostIsAllowed {
|
||||||
// Return 403 Forbidden to block the attack
|
// Return 400 Bad Request or 403 Forbidden to block the attack
|
||||||
http.Error(w, "Invalid Host header", http.StatusForbidden)
|
http.Error(w, "Invalid Host header", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
@@ -410,11 +406,7 @@ func NewServer(ctx context.Context, cfg ServerConfig) (*Server, error) {
|
|||||||
}
|
}
|
||||||
allowedHostsMap := make(map[string]struct{}, len(cfg.AllowedHosts))
|
allowedHostsMap := make(map[string]struct{}, len(cfg.AllowedHosts))
|
||||||
for _, h := range cfg.AllowedHosts {
|
for _, h := range cfg.AllowedHosts {
|
||||||
hostname := h
|
allowedHostsMap[h] = struct{}{}
|
||||||
if host, _, err := net.SplitHostPort(h); err == nil {
|
|
||||||
hostname = host
|
|
||||||
}
|
|
||||||
allowedHostsMap[hostname] = struct{}{}
|
|
||||||
}
|
}
|
||||||
r.Use(hostCheck(allowedHostsMap))
|
r.Use(hostCheck(allowedHostsMap))
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ func TestUpdateServer(t *testing.T) {
|
|||||||
"example-source": &alloydbpg.Source{
|
"example-source": &alloydbpg.Source{
|
||||||
Config: alloydbpg.Config{
|
Config: alloydbpg.Config{
|
||||||
Name: "example-alloydb-source",
|
Name: "example-alloydb-source",
|
||||||
Kind: "alloydb-postgres",
|
Type: "alloydb-postgres",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ import (
|
|||||||
"google.golang.org/api/option"
|
"google.golang.org/api/option"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "alloydb-admin"
|
const SourceType string = "alloydb-admin"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,13 +53,13 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
DefaultProject string `yaml:"defaultProject"`
|
DefaultProject string `yaml:"defaultProject"`
|
||||||
UseClientOAuth bool `yaml:"useClientOAuth"`
|
UseClientOAuth bool `yaml:"useClientOAuth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -106,8 +106,8 @@ type Source struct {
|
|||||||
Service *alloydbrestapi.Service
|
Service *alloydbrestapi.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func TestParseFromYamlAlloyDBAdmin(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-alloydb-admin-instance": alloydbadmin.Config{
|
"my-alloydb-admin-instance": alloydbadmin.Config{
|
||||||
Name: "my-alloydb-admin-instance",
|
Name: "my-alloydb-admin-instance",
|
||||||
Kind: alloydbadmin.SourceKind,
|
Type: alloydbadmin.SourceType,
|
||||||
UseClientOAuth: false,
|
UseClientOAuth: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -57,7 +57,7 @@ func TestParseFromYamlAlloyDBAdmin(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-alloydb-admin-instance": alloydbadmin.Config{
|
"my-alloydb-admin-instance": alloydbadmin.Config{
|
||||||
Name: "my-alloydb-admin-instance",
|
Name: "my-alloydb-admin-instance",
|
||||||
Kind: alloydbadmin.SourceKind,
|
Type: alloydbadmin.SourceType,
|
||||||
UseClientOAuth: true,
|
UseClientOAuth: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "alloydb-postgres"
|
const SourceType string = "alloydb-postgres"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Project string `yaml:"project" validate:"required"`
|
Project string `yaml:"project" validate:"required"`
|
||||||
Region string `yaml:"region" validate:"required"`
|
Region string `yaml:"region" validate:"required"`
|
||||||
Cluster string `yaml:"cluster" validate:"required"`
|
Cluster string `yaml:"cluster" validate:"required"`
|
||||||
@@ -61,8 +61,8 @@ type Config struct {
|
|||||||
Database string `yaml:"database" validate:"required"`
|
Database string `yaml:"database" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -90,8 +90,8 @@ type Source struct {
|
|||||||
Pool *pgxpool.Pool
|
Pool *pgxpool.Pool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -183,7 +183,7 @@ func getConnectionConfig(ctx context.Context, user, pass, dbname string) (string
|
|||||||
|
|
||||||
func initAlloyDBPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, cluster, instance, ipType, user, pass, dbname string) (*pgxpool.Pool, error) {
|
func initAlloyDBPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, cluster, instance, ipType, user, pass, dbname string) (*pgxpool.Pool, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
dsn, useIAM, err := getConnectionConfig(ctx, user, pass, dbname)
|
dsn, useIAM, err := getConnectionConfig(ctx, user, pass, dbname)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-pg-instance": alloydbpg.Config{
|
"my-pg-instance": alloydbpg.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: alloydbpg.SourceKind,
|
Type: alloydbpg.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Cluster: "my-cluster",
|
Cluster: "my-cluster",
|
||||||
@@ -78,7 +78,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-pg-instance": alloydbpg.Config{
|
"my-pg-instance": alloydbpg.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: alloydbpg.SourceKind,
|
Type: alloydbpg.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Cluster: "my-cluster",
|
Cluster: "my-cluster",
|
||||||
@@ -108,7 +108,7 @@ func TestParseFromYamlAlloyDBPg(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-pg-instance": alloydbpg.Config{
|
"my-pg-instance": alloydbpg.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: alloydbpg.SourceKind,
|
Type: alloydbpg.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Cluster: "my-cluster",
|
Cluster: "my-cluster",
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import (
|
|||||||
"google.golang.org/api/option"
|
"google.golang.org/api/option"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "bigquery"
|
const SourceType string = "bigquery"
|
||||||
|
|
||||||
// CloudPlatformScope is a broad scope for Google Cloud Platform services.
|
// CloudPlatformScope is a broad scope for Google Cloud Platform services.
|
||||||
const CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
|
const CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
|
||||||
@@ -65,8 +65,8 @@ type BigQuerySessionProvider func(ctx context.Context) (*Session, error)
|
|||||||
type DataplexClientCreator func(tokenString string) (*dataplexapi.CatalogClient, error)
|
type DataplexClientCreator func(tokenString string) (*dataplexapi.CatalogClient, error)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
// BigQuery configs
|
// BigQuery configs
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Project string `yaml:"project" validate:"required"`
|
Project string `yaml:"project" validate:"required"`
|
||||||
Location string `yaml:"location"`
|
Location string `yaml:"location"`
|
||||||
WriteMode string `yaml:"writeMode"`
|
WriteMode string `yaml:"writeMode"`
|
||||||
@@ -119,9 +119,9 @@ func (s *StringOrStringSlice) UnmarshalYAML(unmarshal func(any) error) error {
|
|||||||
return fmt.Errorf("cannot unmarshal %T into StringOrStringSlice", v)
|
return fmt.Errorf("cannot unmarshal %T into StringOrStringSlice", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
// Returns BigQuery source kind
|
// Returns BigQuery source kind
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
if r.WriteMode == "" {
|
if r.WriteMode == "" {
|
||||||
@@ -302,9 +302,9 @@ type Session struct {
|
|||||||
LastUsed time.Time
|
LastUsed time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
// Returns BigQuery Google SQL source kind
|
// Returns BigQuery Google SQL source kind
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -665,7 +665,7 @@ func initBigQueryConnection(
|
|||||||
impersonateServiceAccount string,
|
impersonateServiceAccount string,
|
||||||
scopes []string,
|
scopes []string,
|
||||||
) (*bigqueryapi.Client, *bigqueryrestapi.Service, oauth2.TokenSource, error) {
|
) (*bigqueryapi.Client, *bigqueryrestapi.Service, oauth2.TokenSource, error) {
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
userAgent, err := util.UserAgentFromContext(ctx)
|
userAgent, err := util.UserAgentFromContext(ctx)
|
||||||
@@ -741,7 +741,7 @@ func initBigQueryConnectionWithOAuthToken(
|
|||||||
tokenString string,
|
tokenString string,
|
||||||
wantRestService bool,
|
wantRestService bool,
|
||||||
) (*bigqueryapi.Client, *bigqueryrestapi.Service, error) {
|
) (*bigqueryapi.Client, *bigqueryrestapi.Service, error) {
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
// Construct token source
|
// Construct token source
|
||||||
token := &oauth2.Token{
|
token := &oauth2.Token{
|
||||||
@@ -801,7 +801,7 @@ func initDataplexConnection(
|
|||||||
var clientCreator DataplexClientCreator
|
var clientCreator DataplexClientCreator
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
userAgent, err := util.UserAgentFromContext(ctx)
|
userAgent, err := util.UserAgentFromContext(ctx)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func TestParseFromYamlBigQuery(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": bigquery.Config{
|
"my-instance": bigquery.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: bigquery.SourceKind,
|
Type: bigquery.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Location: "",
|
Location: "",
|
||||||
WriteMode: "",
|
WriteMode: "",
|
||||||
@@ -66,7 +66,7 @@ func TestParseFromYamlBigQuery(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": bigquery.Config{
|
"my-instance": bigquery.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: bigquery.SourceKind,
|
Type: bigquery.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Location: "asia",
|
Location: "asia",
|
||||||
WriteMode: "blocked",
|
WriteMode: "blocked",
|
||||||
@@ -87,7 +87,7 @@ func TestParseFromYamlBigQuery(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": bigquery.Config{
|
"my-instance": bigquery.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: bigquery.SourceKind,
|
Type: bigquery.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Location: "us",
|
Location: "us",
|
||||||
UseClientOAuth: true,
|
UseClientOAuth: true,
|
||||||
@@ -108,7 +108,7 @@ func TestParseFromYamlBigQuery(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": bigquery.Config{
|
"my-instance": bigquery.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: bigquery.SourceKind,
|
Type: bigquery.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Location: "us",
|
Location: "us",
|
||||||
AllowedDatasets: []string{"my_dataset"},
|
AllowedDatasets: []string{"my_dataset"},
|
||||||
@@ -128,7 +128,7 @@ func TestParseFromYamlBigQuery(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": bigquery.Config{
|
"my-instance": bigquery.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: bigquery.SourceKind,
|
Type: bigquery.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Location: "us",
|
Location: "us",
|
||||||
ImpersonateServiceAccount: "service-account@my-project.iam.gserviceaccount.com",
|
ImpersonateServiceAccount: "service-account@my-project.iam.gserviceaccount.com",
|
||||||
@@ -150,7 +150,7 @@ func TestParseFromYamlBigQuery(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": bigquery.Config{
|
"my-instance": bigquery.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: bigquery.SourceKind,
|
Type: bigquery.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Location: "us",
|
Location: "us",
|
||||||
Scopes: []string{"https://www.googleapis.com/auth/bigquery", "https://www.googleapis.com/auth/cloud-platform"},
|
Scopes: []string{"https://www.googleapis.com/auth/bigquery", "https://www.googleapis.com/auth/cloud-platform"},
|
||||||
@@ -170,7 +170,7 @@ func TestParseFromYamlBigQuery(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": bigquery.Config{
|
"my-instance": bigquery.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: bigquery.SourceKind,
|
Type: bigquery.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Location: "us",
|
Location: "us",
|
||||||
MaxQueryResultRows: 10,
|
MaxQueryResultRows: 10,
|
||||||
@@ -260,7 +260,7 @@ func TestInitialize_MaxQueryResultRows(t *testing.T) {
|
|||||||
desc: "default value",
|
desc: "default value",
|
||||||
cfg: bigquery.Config{
|
cfg: bigquery.Config{
|
||||||
Name: "test-default",
|
Name: "test-default",
|
||||||
Kind: bigquery.SourceKind,
|
Type: bigquery.SourceType,
|
||||||
Project: "test-project",
|
Project: "test-project",
|
||||||
UseClientOAuth: true,
|
UseClientOAuth: true,
|
||||||
},
|
},
|
||||||
@@ -270,7 +270,7 @@ func TestInitialize_MaxQueryResultRows(t *testing.T) {
|
|||||||
desc: "configured value",
|
desc: "configured value",
|
||||||
cfg: bigquery.Config{
|
cfg: bigquery.Config{
|
||||||
Name: "test-configured",
|
Name: "test-configured",
|
||||||
Kind: bigquery.SourceKind,
|
Type: bigquery.SourceType,
|
||||||
Project: "test-project",
|
Project: "test-project",
|
||||||
UseClientOAuth: true,
|
UseClientOAuth: true,
|
||||||
MaxQueryResultRows: 100,
|
MaxQueryResultRows: 100,
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ import (
|
|||||||
"google.golang.org/api/option"
|
"google.golang.org/api/option"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "bigtable"
|
const SourceType string = "bigtable"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,13 +48,13 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Project string `yaml:"project" validate:"required"`
|
Project string `yaml:"project" validate:"required"`
|
||||||
Instance string `yaml:"instance" validate:"required"`
|
Instance string `yaml:"instance" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -77,8 +77,8 @@ type Source struct {
|
|||||||
Client *bigtable.Client
|
Client *bigtable.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -179,7 +179,7 @@ func (s *Source) RunSQL(ctx context.Context, statement string, configParam param
|
|||||||
|
|
||||||
func initBigtableClient(ctx context.Context, tracer trace.Tracer, name, project, instance string) (*bigtable.Client, error) {
|
func initBigtableClient(ctx context.Context, tracer trace.Tracer, name, project, instance string) (*bigtable.Client, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
// Set up Bigtable data operations client.
|
// Set up Bigtable data operations client.
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func TestParseFromYamlBigtableDb(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-bigtable-instance": bigtable.Config{
|
"my-bigtable-instance": bigtable.Config{
|
||||||
Name: "my-bigtable-instance",
|
Name: "my-bigtable-instance",
|
||||||
Kind: bigtable.SourceKind,
|
Type: bigtable.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "cassandra"
|
const SourceType string = "cassandra"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Hosts []string `yaml:"hosts" validate:"required"`
|
Hosts []string `yaml:"hosts" validate:"required"`
|
||||||
Keyspace string `yaml:"keyspace"`
|
Keyspace string `yaml:"keyspace"`
|
||||||
ProtoVersion int `yaml:"protoVersion"`
|
ProtoVersion int `yaml:"protoVersion"`
|
||||||
@@ -68,9 +68,9 @@ func (c Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.So
|
|||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourceConfigKind implements sources.SourceConfig.
|
// SourceConfigType implements sources.SourceConfig.
|
||||||
func (c Config) SourceConfigKind() string {
|
func (c Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
@@ -89,9 +89,9 @@ func (s *Source) ToConfig() sources.SourceConfig {
|
|||||||
return s.Config
|
return s.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourceKind implements sources.Source.
|
// SourceType implements sources.Source.
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) RunSQL(ctx context.Context, statement string, params parameters.ParamValues) (any, error) {
|
func (s *Source) RunSQL(ctx context.Context, statement string, params parameters.ParamValues) (any, error) {
|
||||||
@@ -120,7 +120,7 @@ var _ sources.Source = &Source{}
|
|||||||
|
|
||||||
func initCassandraSession(ctx context.Context, tracer trace.Tracer, c Config) (*gocql.Session, error) {
|
func initCassandraSession(ctx context.Context, tracer trace.Tracer, c Config) (*gocql.Session, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, c.Name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, c.Name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
// Validate authentication configuration
|
// Validate authentication configuration
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func TestParseFromYamlCassandra(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-cassandra-instance": cassandra.Config{
|
"my-cassandra-instance": cassandra.Config{
|
||||||
Name: "my-cassandra-instance",
|
Name: "my-cassandra-instance",
|
||||||
Kind: cassandra.SourceKind,
|
Type: cassandra.SourceType,
|
||||||
Hosts: []string{"my-host1", "my-host2"},
|
Hosts: []string{"my-host1", "my-host2"},
|
||||||
Username: "",
|
Username: "",
|
||||||
Password: "",
|
Password: "",
|
||||||
@@ -77,7 +77,7 @@ func TestParseFromYamlCassandra(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-cassandra-instance": cassandra.Config{
|
"my-cassandra-instance": cassandra.Config{
|
||||||
Name: "my-cassandra-instance",
|
Name: "my-cassandra-instance",
|
||||||
Kind: cassandra.SourceKind,
|
Type: cassandra.SourceType,
|
||||||
Hosts: []string{"my-host1", "my-host2"},
|
Hosts: []string{"my-host1", "my-host2"},
|
||||||
Username: "user",
|
Username: "user",
|
||||||
Password: "pass",
|
Password: "pass",
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "clickhouse"
|
const SourceType string = "clickhouse"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Host string `yaml:"host" validate:"required"`
|
Host string `yaml:"host" validate:"required"`
|
||||||
Port string `yaml:"port" validate:"required"`
|
Port string `yaml:"port" validate:"required"`
|
||||||
Database string `yaml:"database" validate:"required"`
|
Database string `yaml:"database" validate:"required"`
|
||||||
@@ -59,8 +59,8 @@ type Config struct {
|
|||||||
Secure bool `yaml:"secure"`
|
Secure bool `yaml:"secure"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -88,8 +88,8 @@ type Source struct {
|
|||||||
Pool *sql.DB
|
Pool *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -174,7 +174,7 @@ func validateConfig(protocol string) error {
|
|||||||
|
|
||||||
func initClickHouseConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, protocol string, secure bool) (*sql.DB, error) {
|
func initClickHouseConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, protocol string, secure bool) (*sql.DB, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
if protocol == "" {
|
if protocol == "" {
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ import (
|
|||||||
"go.opentelemetry.io/otel"
|
"go.opentelemetry.io/otel"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConfigSourceConfigKind(t *testing.T) {
|
func TestConfigSourceConfigType(t *testing.T) {
|
||||||
config := Config{}
|
config := Config{}
|
||||||
if config.SourceConfigKind() != SourceKind {
|
if config.SourceConfigType() != SourceType {
|
||||||
t.Errorf("Expected %s, got %s", SourceKind, config.SourceConfigKind())
|
t.Errorf("Expected %s, got %s", SourceType, config.SourceConfigType())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ func TestNewConfig(t *testing.T) {
|
|||||||
`,
|
`,
|
||||||
expected: Config{
|
expected: Config{
|
||||||
Name: "test-clickhouse",
|
Name: "test-clickhouse",
|
||||||
Kind: "clickhouse",
|
Type: "clickhouse",
|
||||||
Host: "localhost",
|
Host: "localhost",
|
||||||
Port: "8443",
|
Port: "8443",
|
||||||
User: "default",
|
User: "default",
|
||||||
@@ -75,7 +75,7 @@ func TestNewConfig(t *testing.T) {
|
|||||||
`,
|
`,
|
||||||
expected: Config{
|
expected: Config{
|
||||||
Name: "minimal-clickhouse",
|
Name: "minimal-clickhouse",
|
||||||
Kind: "clickhouse",
|
Type: "clickhouse",
|
||||||
Host: "127.0.0.1",
|
Host: "127.0.0.1",
|
||||||
Port: "8123",
|
Port: "8123",
|
||||||
User: "testuser",
|
User: "testuser",
|
||||||
@@ -100,7 +100,7 @@ func TestNewConfig(t *testing.T) {
|
|||||||
`,
|
`,
|
||||||
expected: Config{
|
expected: Config{
|
||||||
Name: "http-clickhouse",
|
Name: "http-clickhouse",
|
||||||
Kind: "clickhouse",
|
Type: "clickhouse",
|
||||||
Host: "clickhouse.example.com",
|
Host: "clickhouse.example.com",
|
||||||
Port: "8123",
|
Port: "8123",
|
||||||
User: "analytics",
|
User: "analytics",
|
||||||
@@ -125,7 +125,7 @@ func TestNewConfig(t *testing.T) {
|
|||||||
`,
|
`,
|
||||||
expected: Config{
|
expected: Config{
|
||||||
Name: "secure-clickhouse",
|
Name: "secure-clickhouse",
|
||||||
Kind: "clickhouse",
|
Type: "clickhouse",
|
||||||
Host: "secure.clickhouse.io",
|
Host: "secure.clickhouse.io",
|
||||||
Port: "8443",
|
Port: "8443",
|
||||||
User: "secureuser",
|
User: "secureuser",
|
||||||
@@ -196,10 +196,10 @@ func TestNewConfigInvalidYAML(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSource_SourceKind(t *testing.T) {
|
func TestSource_SourceType(t *testing.T) {
|
||||||
source := &Source{}
|
source := &Source{}
|
||||||
if source.SourceKind() != SourceKind {
|
if source.SourceType() != SourceType {
|
||||||
t.Errorf("Expected %s, got %s", SourceKind, source.SourceKind())
|
t.Errorf("Expected %s, got %s", SourceType, source.SourceType())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,15 +29,15 @@ import (
|
|||||||
"golang.org/x/oauth2/google"
|
"golang.org/x/oauth2/google"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "cloud-gemini-data-analytics"
|
const SourceType string = "cloud-gemini-data-analytics"
|
||||||
const Endpoint string = "https://geminidataanalytics.googleapis.com"
|
const Endpoint string = "https://geminidataanalytics.googleapis.com"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,13 +51,13 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
ProjectID string `yaml:"projectId" validate:"required"`
|
ProjectID string `yaml:"projectId" validate:"required"`
|
||||||
UseClientOAuth bool `yaml:"useClientOAuth"`
|
UseClientOAuth bool `yaml:"useClientOAuth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize initializes a Gemini Data Analytics Source instance.
|
// Initialize initializes a Gemini Data Analytics Source instance.
|
||||||
@@ -102,8 +102,8 @@ type Source struct {
|
|||||||
userAgent string
|
userAgent string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func TestParseFromYamlCloudGDA(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-gda-instance": cloudgda.Config{
|
"my-gda-instance": cloudgda.Config{
|
||||||
Name: "my-gda-instance",
|
Name: "my-gda-instance",
|
||||||
Kind: cloudgda.SourceKind,
|
Type: cloudgda.SourceType,
|
||||||
ProjectID: "test-project-id",
|
ProjectID: "test-project-id",
|
||||||
UseClientOAuth: false,
|
UseClientOAuth: false,
|
||||||
},
|
},
|
||||||
@@ -65,7 +65,7 @@ func TestParseFromYamlCloudGDA(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-gda-instance": cloudgda.Config{
|
"my-gda-instance": cloudgda.Config{
|
||||||
Name: "my-gda-instance",
|
Name: "my-gda-instance",
|
||||||
Kind: cloudgda.SourceKind,
|
Type: cloudgda.SourceType,
|
||||||
ProjectID: "another-project",
|
ProjectID: "another-project",
|
||||||
UseClientOAuth: true,
|
UseClientOAuth: true,
|
||||||
},
|
},
|
||||||
@@ -153,12 +153,12 @@ func TestInitialize(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "initialize with ADC",
|
desc: "initialize with ADC",
|
||||||
cfg: cloudgda.Config{Name: "test-gda", Kind: cloudgda.SourceKind, ProjectID: "test-proj"},
|
cfg: cloudgda.Config{Name: "test-gda", Type: cloudgda.SourceType, ProjectID: "test-proj"},
|
||||||
wantClientOAuth: false,
|
wantClientOAuth: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "initialize with client OAuth",
|
desc: "initialize with client OAuth",
|
||||||
cfg: cloudgda.Config{Name: "test-gda-oauth", Kind: cloudgda.SourceKind, ProjectID: "test-proj", UseClientOAuth: true},
|
cfg: cloudgda.Config{Name: "test-gda-oauth", Type: cloudgda.SourceType, ProjectID: "test-proj", UseClientOAuth: true},
|
||||||
wantClientOAuth: true,
|
wantClientOAuth: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import (
|
|||||||
"google.golang.org/api/option"
|
"google.golang.org/api/option"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "cloud-healthcare"
|
const SourceType string = "cloud-healthcare"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
@@ -42,8 +42,8 @@ var _ sources.SourceConfig = Config{}
|
|||||||
type HealthcareServiceCreator func(tokenString string) (*healthcare.Service, error)
|
type HealthcareServiceCreator func(tokenString string) (*healthcare.Service, error)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
// Healthcare configs
|
// Healthcare configs
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Project string `yaml:"project" validate:"required"`
|
Project string `yaml:"project" validate:"required"`
|
||||||
Region string `yaml:"region" validate:"required"`
|
Region string `yaml:"region" validate:"required"`
|
||||||
Dataset string `yaml:"dataset" validate:"required"`
|
Dataset string `yaml:"dataset" validate:"required"`
|
||||||
@@ -67,8 +67,8 @@ type Config struct {
|
|||||||
UseClientOAuth bool `yaml:"useClientOAuth"`
|
UseClientOAuth bool `yaml:"useClientOAuth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) SourceConfigKind() string {
|
func (c Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (c Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -144,7 +144,7 @@ func newHealthcareServiceCreator(ctx context.Context, tracer trace.Tracer, name
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initHealthcareConnectionWithOAuthToken(ctx context.Context, tracer trace.Tracer, name string, userAgent string, tokenString string) (*healthcare.Service, error) {
|
func initHealthcareConnectionWithOAuthToken(ctx context.Context, tracer trace.Tracer, name string, userAgent string, tokenString string) (*healthcare.Service, error) {
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
// Construct token source
|
// Construct token source
|
||||||
token := &oauth2.Token{
|
token := &oauth2.Token{
|
||||||
@@ -162,7 +162,7 @@ func initHealthcareConnectionWithOAuthToken(ctx context.Context, tracer trace.Tr
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initHealthcareConnection(ctx context.Context, tracer trace.Tracer, name string) (*healthcare.Service, oauth2.TokenSource, error) {
|
func initHealthcareConnection(ctx context.Context, tracer trace.Tracer, name string) (*healthcare.Service, oauth2.TokenSource, error) {
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
cred, err := google.FindDefaultCredentials(ctx, healthcare.CloudHealthcareScope)
|
cred, err := google.FindDefaultCredentials(ctx, healthcare.CloudHealthcareScope)
|
||||||
@@ -194,8 +194,8 @@ type Source struct {
|
|||||||
allowedDICOMStores map[string]struct{}
|
allowedDICOMStores map[string]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -517,14 +517,14 @@ func (s *Source) RetrieveRenderedDICOMInstance(storeID, study, series, sop strin
|
|||||||
return base64String, nil
|
return base64String, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SearchDICOM(toolKind, storeID, dicomWebPath, tokenStr string, opts []googleapi.CallOption) (any, error) {
|
func (s *Source) SearchDICOM(toolType, storeID, dicomWebPath, tokenStr string, opts []googleapi.CallOption) (any, error) {
|
||||||
svc, err := s.getService(tokenStr)
|
svc, err := s.getService(tokenStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/dicomStores/%s", s.Project(), s.Region(), s.DatasetID(), storeID)
|
name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/dicomStores/%s", s.Project(), s.Region(), s.DatasetID(), storeID)
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
switch toolKind {
|
switch toolType {
|
||||||
case "cloud-healthcare-search-dicom-instances":
|
case "cloud-healthcare-search-dicom-instances":
|
||||||
resp, err = svc.Projects.Locations.Datasets.DicomStores.SearchForInstances(name, dicomWebPath).Do(opts...)
|
resp, err = svc.Projects.Locations.Datasets.DicomStores.SearchForInstances(name, dicomWebPath).Do(opts...)
|
||||||
case "cloud-healthcare-search-dicom-series":
|
case "cloud-healthcare-search-dicom-series":
|
||||||
@@ -532,7 +532,7 @@ func (s *Source) SearchDICOM(toolKind, storeID, dicomWebPath, tokenStr string, o
|
|||||||
case "cloud-healthcare-search-dicom-studies":
|
case "cloud-healthcare-search-dicom-studies":
|
||||||
resp, err = svc.Projects.Locations.Datasets.DicomStores.SearchForStudies(name, dicomWebPath).Do(opts...)
|
resp, err = svc.Projects.Locations.Datasets.DicomStores.SearchForStudies(name, dicomWebPath).Do(opts...)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("incompatible tool kind: %s", toolKind)
|
return nil, fmt.Errorf("incompatible tool type: %s", toolType)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to search dicom series: %w", err)
|
return nil, fmt.Errorf("failed to search dicom series: %w", err)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func TestParseFromYamlCloudHealthcare(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": cloudhealthcare.Config{
|
"my-instance": cloudhealthcare.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: cloudhealthcare.SourceKind,
|
Type: cloudhealthcare.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "us-central1",
|
Region: "us-central1",
|
||||||
Dataset: "my-dataset",
|
Dataset: "my-dataset",
|
||||||
@@ -65,7 +65,7 @@ func TestParseFromYamlCloudHealthcare(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": cloudhealthcare.Config{
|
"my-instance": cloudhealthcare.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: cloudhealthcare.SourceKind,
|
Type: cloudhealthcare.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "us",
|
Region: "us",
|
||||||
Dataset: "my-dataset",
|
Dataset: "my-dataset",
|
||||||
@@ -91,7 +91,7 @@ func TestParseFromYamlCloudHealthcare(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": cloudhealthcare.Config{
|
"my-instance": cloudhealthcare.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: cloudhealthcare.SourceKind,
|
Type: cloudhealthcare.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "us",
|
Region: "us",
|
||||||
Dataset: "my-dataset",
|
Dataset: "my-dataset",
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ import (
|
|||||||
monitoring "google.golang.org/api/monitoring/v3"
|
monitoring "google.golang.org/api/monitoring/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "cloud-monitoring"
|
const SourceType string = "cloud-monitoring"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +50,12 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
UseClientOAuth bool `yaml:"useClientOAuth"`
|
UseClientOAuth bool `yaml:"useClientOAuth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize initializes a Cloud Monitoring Source instance.
|
// Initialize initializes a Cloud Monitoring Source instance.
|
||||||
@@ -99,8 +99,8 @@ type Source struct {
|
|||||||
userAgent string
|
userAgent string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func TestParseFromYamlCloudMonitoring(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-cloud-monitoring-instance": cloudmonitoring.Config{
|
"my-cloud-monitoring-instance": cloudmonitoring.Config{
|
||||||
Name: "my-cloud-monitoring-instance",
|
Name: "my-cloud-monitoring-instance",
|
||||||
Kind: cloudmonitoring.SourceKind,
|
Type: cloudmonitoring.SourceType,
|
||||||
UseClientOAuth: false,
|
UseClientOAuth: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -58,7 +58,7 @@ func TestParseFromYamlCloudMonitoring(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-cloud-monitoring-instance": cloudmonitoring.Config{
|
"my-cloud-monitoring-instance": cloudmonitoring.Config{
|
||||||
Name: "my-cloud-monitoring-instance",
|
Name: "my-cloud-monitoring-instance",
|
||||||
Kind: cloudmonitoring.SourceKind,
|
Type: cloudmonitoring.SourceType,
|
||||||
UseClientOAuth: true,
|
UseClientOAuth: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
@@ -35,19 +34,16 @@ import (
|
|||||||
sqladmin "google.golang.org/api/sqladmin/v1"
|
sqladmin "google.golang.org/api/sqladmin/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "cloud-sql-admin"
|
const SourceType string = "cloud-sql-admin"
|
||||||
|
|
||||||
var (
|
var targetLinkRegex = regexp.MustCompile(`/projects/([^/]+)/instances/([^/]+)/databases/([^/]+)`)
|
||||||
targetLinkRegex = regexp.MustCompile(`/projects/([^/]+)/instances/([^/]+)/databases/([^/]+)`)
|
|
||||||
backupDRRegex = regexp.MustCompile(`^projects/([^/]+)/locations/([^/]+)/backupVaults/([^/]+)/dataSources/([^/]+)/backups/([^/]+)$`)
|
|
||||||
)
|
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,13 +57,13 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
DefaultProject string `yaml:"defaultProject"`
|
DefaultProject string `yaml:"defaultProject"`
|
||||||
UseClientOAuth bool `yaml:"useClientOAuth"`
|
UseClientOAuth bool `yaml:"useClientOAuth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize initializes a CloudSQL Admin Source instance.
|
// Initialize initializes a CloudSQL Admin Source instance.
|
||||||
@@ -114,8 +110,8 @@ type Source struct {
|
|||||||
Service *sqladmin.Service
|
Service *sqladmin.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -378,48 +374,6 @@ func (s *Source) InsertBackupRun(ctx context.Context, project, instance, locatio
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) RestoreBackup(ctx context.Context, targetProject, targetInstance, sourceProject, sourceInstance, backupID, accessToken string) (any, error) {
|
|
||||||
request := &sqladmin.InstancesRestoreBackupRequest{}
|
|
||||||
|
|
||||||
// There are 3 scenarios for the backup identifier:
|
|
||||||
// 1. The identifier is an int64 containing the timestamp of the BackupRun.
|
|
||||||
// This is used to restore standard backups, and the RestoreBackupContext
|
|
||||||
// field should be populated with the backup ID and source instance info.
|
|
||||||
// 2. The identifier is a string of the format
|
|
||||||
// 'projects/{project-id}/locations/{location}/backupVaults/{backupvault}/dataSources/{datasource}/backups/{backup-uid}'.
|
|
||||||
// This is used to restore BackupDR backups, and the BackupdrBackup field
|
|
||||||
// should be populated.
|
|
||||||
// 3. The identifer is a string of the format
|
|
||||||
// 'projects/{project-id}/backups/{backup-uid}'. In this case, the Backup
|
|
||||||
// field should be populated.
|
|
||||||
if backupRunID, err := strconv.ParseInt(backupID, 10, 64); err == nil {
|
|
||||||
if sourceProject == "" || targetInstance == "" {
|
|
||||||
return nil, fmt.Errorf("source project and instance are required when restoring via backup ID")
|
|
||||||
}
|
|
||||||
request.RestoreBackupContext = &sqladmin.RestoreBackupContext{
|
|
||||||
Project: sourceProject,
|
|
||||||
InstanceId: sourceInstance,
|
|
||||||
BackupRunId: backupRunID,
|
|
||||||
}
|
|
||||||
} else if backupDRRegex.MatchString(backupID) {
|
|
||||||
request.BackupdrBackup = backupID
|
|
||||||
} else {
|
|
||||||
request.Backup = backupID
|
|
||||||
}
|
|
||||||
|
|
||||||
service, err := s.GetService(ctx, string(accessToken))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := service.Instances.RestoreBackup(targetProject, targetInstance, request).Do()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error restoring backup: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateCloudSQLConnectionMessage(ctx context.Context, source *Source, logger log.Logger, opResponse map[string]any, connectionMessageTemplate string) (string, bool) {
|
func generateCloudSQLConnectionMessage(ctx context.Context, source *Source, logger log.Logger, opResponse map[string]any, connectionMessageTemplate string) (string, bool) {
|
||||||
operationType, ok := opResponse["operationType"].(string)
|
operationType, ok := opResponse["operationType"].(string)
|
||||||
if !ok || operationType != "CREATE_DATABASE" {
|
if !ok || operationType != "CREATE_DATABASE" {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func TestParseFromYamlCloudSQLAdmin(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-cloud-sql-admin-instance": cloudsqladmin.Config{
|
"my-cloud-sql-admin-instance": cloudsqladmin.Config{
|
||||||
Name: "my-cloud-sql-admin-instance",
|
Name: "my-cloud-sql-admin-instance",
|
||||||
Kind: cloudsqladmin.SourceKind,
|
Type: cloudsqladmin.SourceType,
|
||||||
UseClientOAuth: false,
|
UseClientOAuth: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -58,7 +58,7 @@ func TestParseFromYamlCloudSQLAdmin(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-cloud-sql-admin-instance": cloudsqladmin.Config{
|
"my-cloud-sql-admin-instance": cloudsqladmin.Config{
|
||||||
Name: "my-cloud-sql-admin-instance",
|
Name: "my-cloud-sql-admin-instance",
|
||||||
Kind: cloudsqladmin.SourceKind,
|
Type: cloudsqladmin.SourceType,
|
||||||
UseClientOAuth: true,
|
UseClientOAuth: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "cloud-sql-mssql"
|
const SourceType string = "cloud-sql-mssql"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
// Cloud SQL MSSQL configs
|
// Cloud SQL MSSQL configs
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Project string `yaml:"project" validate:"required"`
|
Project string `yaml:"project" validate:"required"`
|
||||||
Region string `yaml:"region" validate:"required"`
|
Region string `yaml:"region" validate:"required"`
|
||||||
Instance string `yaml:"instance" validate:"required"`
|
Instance string `yaml:"instance" validate:"required"`
|
||||||
@@ -62,9 +62,9 @@ type Config struct {
|
|||||||
Database string `yaml:"database" validate:"required"`
|
Database string `yaml:"database" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
// Returns Cloud SQL MSSQL source kind
|
// Returns Cloud SQL MSSQL source kind
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -94,9 +94,9 @@ type Source struct {
|
|||||||
Db *sql.DB
|
Db *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
// Returns Cloud SQL MSSQL source kind
|
// Returns Cloud SQL MSSQL source kind
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -152,7 +152,7 @@ func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (an
|
|||||||
|
|
||||||
func initCloudSQLMssqlConnection(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string) (*sql.DB, error) {
|
func initCloudSQLMssqlConnection(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string) (*sql.DB, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
userAgent, err := util.UserAgentFromContext(ctx)
|
userAgent, err := util.UserAgentFromContext(ctx)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func TestParseFromYamlCloudSQLMssql(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": cloudsqlmssql.Config{
|
"my-instance": cloudsqlmssql.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: cloudsqlmssql.SourceKind,
|
Type: cloudsqlmssql.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -74,7 +74,7 @@ func TestParseFromYamlCloudSQLMssql(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": cloudsqlmssql.Config{
|
"my-instance": cloudsqlmssql.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: cloudsqlmssql.SourceKind,
|
Type: cloudsqlmssql.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -102,7 +102,7 @@ func TestParseFromYamlCloudSQLMssql(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": cloudsqlmssql.Config{
|
"my-instance": cloudsqlmssql.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: cloudsqlmssql.SourceKind,
|
Type: cloudsqlmssql.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
|
|||||||
@@ -30,14 +30,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "cloud-sql-mysql"
|
const SourceType string = "cloud-sql-mysql"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Project string `yaml:"project" validate:"required"`
|
Project string `yaml:"project" validate:"required"`
|
||||||
Region string `yaml:"region" validate:"required"`
|
Region string `yaml:"region" validate:"required"`
|
||||||
Instance string `yaml:"instance" validate:"required"`
|
Instance string `yaml:"instance" validate:"required"`
|
||||||
@@ -61,8 +61,8 @@ type Config struct {
|
|||||||
Database string `yaml:"database" validate:"required"`
|
Database string `yaml:"database" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -90,8 +90,8 @@ type Source struct {
|
|||||||
Pool *sql.DB
|
Pool *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -184,7 +184,7 @@ func getConnectionConfig(ctx context.Context, user, pass string) (string, string
|
|||||||
|
|
||||||
func initCloudSQLMySQLConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string) (*sql.DB, error) {
|
func initCloudSQLMySQLConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string) (*sql.DB, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
// Configure the driver to connect to the database
|
// Configure the driver to connect to the database
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func TestParseFromYamlCloudSQLMySQL(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mysql-instance": cloudsqlmysql.Config{
|
"my-mysql-instance": cloudsqlmysql.Config{
|
||||||
Name: "my-mysql-instance",
|
Name: "my-mysql-instance",
|
||||||
Kind: cloudsqlmysql.SourceKind,
|
Type: cloudsqlmysql.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -74,7 +74,7 @@ func TestParseFromYamlCloudSQLMySQL(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mysql-instance": cloudsqlmysql.Config{
|
"my-mysql-instance": cloudsqlmysql.Config{
|
||||||
Name: "my-mysql-instance",
|
Name: "my-mysql-instance",
|
||||||
Kind: cloudsqlmysql.SourceKind,
|
Type: cloudsqlmysql.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -102,7 +102,7 @@ func TestParseFromYamlCloudSQLMySQL(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mysql-instance": cloudsqlmysql.Config{
|
"my-mysql-instance": cloudsqlmysql.Config{
|
||||||
Name: "my-mysql-instance",
|
Name: "my-mysql-instance",
|
||||||
Kind: cloudsqlmysql.SourceKind,
|
Type: cloudsqlmysql.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -130,7 +130,7 @@ func TestParseFromYamlCloudSQLMySQL(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mysql-instance": cloudsqlmysql.Config{
|
"my-mysql-instance": cloudsqlmysql.Config{
|
||||||
Name: "my-mysql-instance",
|
Name: "my-mysql-instance",
|
||||||
Kind: cloudsqlmysql.SourceKind,
|
Type: cloudsqlmysql.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "cloud-sql-postgres"
|
const SourceType string = "cloud-sql-postgres"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Project string `yaml:"project" validate:"required"`
|
Project string `yaml:"project" validate:"required"`
|
||||||
Region string `yaml:"region" validate:"required"`
|
Region string `yaml:"region" validate:"required"`
|
||||||
Instance string `yaml:"instance" validate:"required"`
|
Instance string `yaml:"instance" validate:"required"`
|
||||||
@@ -59,8 +59,8 @@ type Config struct {
|
|||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -88,8 +88,8 @@ type Source struct {
|
|||||||
Pool *pgxpool.Pool
|
Pool *pgxpool.Pool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -162,7 +162,7 @@ func getConnectionConfig(ctx context.Context, user, pass, dbname string) (string
|
|||||||
|
|
||||||
func initCloudSQLPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string) (*pgxpool.Pool, error) {
|
func initCloudSQLPgConnectionPool(ctx context.Context, tracer trace.Tracer, name, project, region, instance, ipType, user, pass, dbname string) (*pgxpool.Pool, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
// Configure the driver to connect to the database
|
// Configure the driver to connect to the database
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func TestParseFromYamlCloudSQLPg(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-pg-instance": cloudsqlpg.Config{
|
"my-pg-instance": cloudsqlpg.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: cloudsqlpg.SourceKind,
|
Type: cloudsqlpg.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -74,7 +74,7 @@ func TestParseFromYamlCloudSQLPg(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-pg-instance": cloudsqlpg.Config{
|
"my-pg-instance": cloudsqlpg.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: cloudsqlpg.SourceKind,
|
Type: cloudsqlpg.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -102,7 +102,7 @@ func TestParseFromYamlCloudSQLPg(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-pg-instance": cloudsqlpg.Config{
|
"my-pg-instance": cloudsqlpg.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: cloudsqlpg.SourceKind,
|
Type: cloudsqlpg.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
@@ -130,7 +130,7 @@ func TestParseFromYamlCloudSQLPg(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-pg-instance": cloudsqlpg.Config{
|
"my-pg-instance": cloudsqlpg.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: cloudsqlpg.SourceKind,
|
Type: cloudsqlpg.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Region: "my-region",
|
Region: "my-region",
|
||||||
Instance: "my-instance",
|
Instance: "my-instance",
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "couchbase"
|
const SourceType string = "couchbase"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
ConnectionString string `yaml:"connectionString" validate:"required"`
|
ConnectionString string `yaml:"connectionString" validate:"required"`
|
||||||
Bucket string `yaml:"bucket" validate:"required"`
|
Bucket string `yaml:"bucket" validate:"required"`
|
||||||
Scope string `yaml:"scope" validate:"required"`
|
Scope string `yaml:"scope" validate:"required"`
|
||||||
@@ -66,8 +66,8 @@ type Config struct {
|
|||||||
QueryScanConsistency uint `yaml:"queryScanConsistency"`
|
QueryScanConsistency uint `yaml:"queryScanConsistency"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -96,8 +96,8 @@ type Source struct {
|
|||||||
Scope *gocb.Scope
|
Scope *gocb.Scope
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func TestParseFromYamlCouchbase(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-couchbase-instance": couchbase.Config{
|
"my-couchbase-instance": couchbase.Config{
|
||||||
Name: "my-couchbase-instance",
|
Name: "my-couchbase-instance",
|
||||||
Kind: couchbase.SourceKind,
|
Type: couchbase.SourceType,
|
||||||
ConnectionString: "localhost",
|
ConnectionString: "localhost",
|
||||||
Username: "Administrator",
|
Username: "Administrator",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
@@ -74,7 +74,7 @@ func TestParseFromYamlCouchbase(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-couchbase-instance": couchbase.Config{
|
"my-couchbase-instance": couchbase.Config{
|
||||||
Name: "my-couchbase-instance",
|
Name: "my-couchbase-instance",
|
||||||
Kind: couchbase.SourceKind,
|
Type: couchbase.SourceType,
|
||||||
ConnectionString: "couchbases://localhost",
|
ConnectionString: "couchbases://localhost",
|
||||||
Bucket: "travel-sample",
|
Bucket: "travel-sample",
|
||||||
Scope: "inventory",
|
Scope: "inventory",
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ import (
|
|||||||
"google.golang.org/api/option"
|
"google.golang.org/api/option"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "dataplex"
|
const SourceType string = "dataplex"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,13 +51,13 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
// Dataplex configs
|
// Dataplex configs
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Project string `yaml:"project" validate:"required"`
|
Project string `yaml:"project" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
// Returns Dataplex source kind
|
// Returns Dataplex source kind
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -81,9 +81,9 @@ type Source struct {
|
|||||||
Client *dataplexapi.CatalogClient
|
Client *dataplexapi.CatalogClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
// Returns Dataplex source kind
|
// Returns Dataplex source kind
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -104,7 +104,7 @@ func initDataplexConnection(
|
|||||||
name string,
|
name string,
|
||||||
project string,
|
project string,
|
||||||
) (*dataplexapi.CatalogClient, error) {
|
) (*dataplexapi.CatalogClient, error) {
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
cred, err := google.FindDefaultCredentials(ctx)
|
cred, err := google.FindDefaultCredentials(ctx)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func TestParseFromYamlDataplex(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": dataplex.Config{
|
"my-instance": dataplex.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: dataplex.SourceKind,
|
Type: dataplex.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -30,14 +30,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "dgraph"
|
const SourceType string = "dgraph"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ type DgraphClient struct {
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
DgraphUrl string `yaml:"dgraphUrl" validate:"required"`
|
DgraphUrl string `yaml:"dgraphUrl" validate:"required"`
|
||||||
User string `yaml:"user"`
|
User string `yaml:"user"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
@@ -75,8 +75,8 @@ type Config struct {
|
|||||||
ApiKey string `yaml:"apiKey"`
|
ApiKey string `yaml:"apiKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -103,8 +103,8 @@ type Source struct {
|
|||||||
Client *DgraphClient `yaml:"client"`
|
Client *DgraphClient `yaml:"client"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -139,7 +139,7 @@ func (s *Source) RunSQL(statement string, params parameters.ParamValues, isQuery
|
|||||||
|
|
||||||
func initDgraphHttpClient(ctx context.Context, tracer trace.Tracer, r Config) (*DgraphClient, error) {
|
func initDgraphHttpClient(ctx context.Context, tracer trace.Tracer, r Config) (*DgraphClient, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, r.Name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, r.Name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
if r.DgraphUrl == "" {
|
if r.DgraphUrl == "" {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func TestParseFromYamlDgraph(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-dgraph-instance": dgraph.Config{
|
"my-dgraph-instance": dgraph.Config{
|
||||||
Name: "my-dgraph-instance",
|
Name: "my-dgraph-instance",
|
||||||
Kind: dgraph.SourceKind,
|
Type: dgraph.SourceType,
|
||||||
DgraphUrl: "https://localhost:8080",
|
DgraphUrl: "https://localhost:8080",
|
||||||
ApiKey: "abc123",
|
ApiKey: "abc123",
|
||||||
Password: "pass@123",
|
Password: "pass@123",
|
||||||
@@ -65,7 +65,7 @@ func TestParseFromYamlDgraph(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-dgraph-instance": dgraph.Config{
|
"my-dgraph-instance": dgraph.Config{
|
||||||
Name: "my-dgraph-instance",
|
Name: "my-dgraph-instance",
|
||||||
Kind: dgraph.SourceKind,
|
Type: dgraph.SourceType,
|
||||||
DgraphUrl: "https://localhost:8080",
|
DgraphUrl: "https://localhost:8080",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -30,14 +30,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "elasticsearch"
|
const SourceType string = "elasticsearch"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,15 +51,15 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Addresses []string `yaml:"addresses" validate:"required"`
|
Addresses []string `yaml:"addresses" validate:"required"`
|
||||||
Username string `yaml:"username"`
|
Username string `yaml:"username"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
APIKey string `yaml:"apikey"`
|
APIKey string `yaml:"apikey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) SourceConfigKind() string {
|
func (c Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
type EsClient interface {
|
type EsClient interface {
|
||||||
@@ -139,9 +139,9 @@ func (c Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.So
|
|||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourceKind returns the kind string for this source.
|
// SourceType returns the kind string for this source.
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func TestParseFromYamlElasticsearch(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-es-instance": elasticsearch.Config{
|
"my-es-instance": elasticsearch.Config{
|
||||||
Name: "my-es-instance",
|
Name: "my-es-instance",
|
||||||
Kind: elasticsearch.SourceKind,
|
Type: elasticsearch.SourceType,
|
||||||
Addresses: []string{"http://localhost:9200"},
|
Addresses: []string{"http://localhost:9200"},
|
||||||
APIKey: "somekey",
|
APIKey: "somekey",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ import (
|
|||||||
"github.com/googleapis/genai-toolbox/internal/sources"
|
"github.com/googleapis/genai-toolbox/internal/sources"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "firebird"
|
const SourceType string = "firebird"
|
||||||
|
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Host string `yaml:"host" validate:"required"`
|
Host string `yaml:"host" validate:"required"`
|
||||||
Port string `yaml:"port" validate:"required"`
|
Port string `yaml:"port" validate:"required"`
|
||||||
User string `yaml:"user" validate:"required"`
|
User string `yaml:"user" validate:"required"`
|
||||||
@@ -55,8 +55,8 @@ type Config struct {
|
|||||||
Database string `yaml:"database" validate:"required"`
|
Database string `yaml:"database" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -84,8 +84,8 @@ type Source struct {
|
|||||||
Db *sql.DB
|
Db *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -144,7 +144,7 @@ func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (an
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initFirebirdConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname string) (*sql.DB, error) {
|
func initFirebirdConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname string) (*sql.DB, error) {
|
||||||
_, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
_, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
// urlExample := "user:password@host:port/path/to/database.fdb"
|
// urlExample := "user:password@host:port/path/to/database.fdb"
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func TestParseFromYamlFirebird(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-fdb-instance": firebird.Config{
|
"my-fdb-instance": firebird.Config{
|
||||||
Name: "my-fdb-instance",
|
Name: "my-fdb-instance",
|
||||||
Kind: firebird.SourceKind,
|
Type: firebird.SourceType,
|
||||||
Host: "my-host",
|
Host: "my-host",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
|
|||||||
@@ -31,14 +31,14 @@ import (
|
|||||||
"google.golang.org/genproto/googleapis/type/latlng"
|
"google.golang.org/genproto/googleapis/type/latlng"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "firestore"
|
const SourceType string = "firestore"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,14 +53,14 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
// Firestore configs
|
// Firestore configs
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Project string `yaml:"project" validate:"required"`
|
Project string `yaml:"project" validate:"required"`
|
||||||
Database string `yaml:"database"` // Optional, defaults to "(default)"
|
Database string `yaml:"database"` // Optional, defaults to "(default)"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
// Returns Firestore source kind
|
// Returns Firestore source kind
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -92,9 +92,9 @@ type Source struct {
|
|||||||
RulesClient *firebaserules.Service
|
RulesClient *firebaserules.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
// Returns Firestore source kind
|
// Returns Firestore source kind
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -594,7 +594,7 @@ func initFirestoreConnection(
|
|||||||
project string,
|
project string,
|
||||||
database string,
|
database string,
|
||||||
) (*firestore.Client, error) {
|
) (*firestore.Client, error) {
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
userAgent, err := util.UserAgentFromContext(ctx)
|
userAgent, err := util.UserAgentFromContext(ctx)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func TestParseFromYamlFirestore(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-firestore": firestore.Config{
|
"my-firestore": firestore.Config{
|
||||||
Name: "my-firestore",
|
Name: "my-firestore",
|
||||||
Kind: firestore.SourceKind,
|
Type: firestore.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Database: "",
|
Database: "",
|
||||||
},
|
},
|
||||||
@@ -60,7 +60,7 @@ func TestParseFromYamlFirestore(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-firestore": firestore.Config{
|
"my-firestore": firestore.Config{
|
||||||
Name: "my-firestore",
|
Name: "my-firestore",
|
||||||
Kind: firestore.SourceKind,
|
Type: firestore.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Database: "my-database",
|
Database: "my-database",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "http"
|
const SourceType string = "http"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
BaseURL string `yaml:"baseUrl"`
|
BaseURL string `yaml:"baseUrl"`
|
||||||
Timeout string `yaml:"timeout"`
|
Timeout string `yaml:"timeout"`
|
||||||
DefaultHeaders map[string]string `yaml:"headers"`
|
DefaultHeaders map[string]string `yaml:"headers"`
|
||||||
@@ -58,8 +58,8 @@ type Config struct {
|
|||||||
DisableSslVerification bool `yaml:"disableSslVerification"`
|
DisableSslVerification bool `yaml:"disableSslVerification"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize initializes an HTTP Source instance.
|
// Initialize initializes an HTTP Source instance.
|
||||||
@@ -122,8 +122,8 @@ type Source struct {
|
|||||||
client *http.Client
|
client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func TestParseFromYamlHttp(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-http-instance": http.Config{
|
"my-http-instance": http.Config{
|
||||||
Name: "my-http-instance",
|
Name: "my-http-instance",
|
||||||
Kind: http.SourceKind,
|
Type: http.SourceType,
|
||||||
BaseURL: "http://test_server/",
|
BaseURL: "http://test_server/",
|
||||||
Timeout: "30s",
|
Timeout: "30s",
|
||||||
DisableSslVerification: false,
|
DisableSslVerification: false,
|
||||||
@@ -68,7 +68,7 @@ func TestParseFromYamlHttp(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-http-instance": http.Config{
|
"my-http-instance": http.Config{
|
||||||
Name: "my-http-instance",
|
Name: "my-http-instance",
|
||||||
Kind: http.SourceKind,
|
Type: http.SourceType,
|
||||||
BaseURL: "http://test_server/",
|
BaseURL: "http://test_server/",
|
||||||
Timeout: "10s",
|
Timeout: "10s",
|
||||||
DefaultHeaders: map[string]string{"Authorization": "test_header", "Custom-Header": "custom"},
|
DefaultHeaders: map[string]string{"Authorization": "test_header", "Custom-Header": "custom"},
|
||||||
|
|||||||
@@ -33,14 +33,14 @@ import (
|
|||||||
v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4"
|
v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "looker"
|
const SourceType string = "looker"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
BaseURL string `yaml:"base_url" validate:"required"`
|
BaseURL string `yaml:"base_url" validate:"required"`
|
||||||
ClientId string `yaml:"client_id"`
|
ClientId string `yaml:"client_id"`
|
||||||
ClientSecret string `yaml:"client_secret"`
|
ClientSecret string `yaml:"client_secret"`
|
||||||
@@ -79,8 +79,8 @@ type Config struct {
|
|||||||
SessionLength int64 `yaml:"sessionLength"`
|
SessionLength int64 `yaml:"sessionLength"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize initializes a Looker Source instance.
|
// Initialize initializes a Looker Source instance.
|
||||||
@@ -154,8 +154,8 @@ type Source struct {
|
|||||||
AuthTokenHeaderName string
|
AuthTokenHeaderName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func TestParseFromYamlLooker(t *testing.T) {
|
|||||||
want: map[string]sources.SourceConfig{
|
want: map[string]sources.SourceConfig{
|
||||||
"my-looker-instance": looker.Config{
|
"my-looker-instance": looker.Config{
|
||||||
Name: "my-looker-instance",
|
Name: "my-looker-instance",
|
||||||
Kind: looker.SourceKind,
|
Type: looker.SourceType,
|
||||||
BaseURL: "http://example.looker.com/",
|
BaseURL: "http://example.looker.com/",
|
||||||
ClientId: "jasdl;k;tjl",
|
ClientId: "jasdl;k;tjl",
|
||||||
ClientSecret: "sdakl;jgflkasdfkfg",
|
ClientSecret: "sdakl;jgflkasdfkfg",
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "mindsdb"
|
const SourceType string = "mindsdb"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Host string `yaml:"host" validate:"required"`
|
Host string `yaml:"host" validate:"required"`
|
||||||
Port string `yaml:"port" validate:"required"`
|
Port string `yaml:"port" validate:"required"`
|
||||||
User string `yaml:"user" validate:"required"`
|
User string `yaml:"user" validate:"required"`
|
||||||
@@ -57,8 +57,8 @@ type Config struct {
|
|||||||
QueryTimeout string `yaml:"queryTimeout"`
|
QueryTimeout string `yaml:"queryTimeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -86,8 +86,8 @@ type Source struct {
|
|||||||
Pool *sql.DB
|
Pool *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -159,7 +159,7 @@ func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (an
|
|||||||
|
|
||||||
func initMindsDBConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string) (*sql.DB, error) {
|
func initMindsDBConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string) (*sql.DB, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
// Configure the driver to connect to the database
|
// Configure the driver to connect to the database
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func TestParseFromYamlMindsDB(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mindsdb-instance": mindsdb.Config{
|
"my-mindsdb-instance": mindsdb.Config{
|
||||||
Name: "my-mindsdb-instance",
|
Name: "my-mindsdb-instance",
|
||||||
Kind: mindsdb.SourceKind,
|
Type: mindsdb.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
@@ -70,7 +70,7 @@ func TestParseFromYamlMindsDB(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mindsdb-instance": mindsdb.Config{
|
"my-mindsdb-instance": mindsdb.Config{
|
||||||
Name: "my-mindsdb-instance",
|
Name: "my-mindsdb-instance",
|
||||||
Kind: mindsdb.SourceKind,
|
Type: mindsdb.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "mongodb"
|
const SourceType string = "mongodb"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,12 +50,12 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Uri string `yaml:"uri" validate:"required"` // MongoDB Atlas connection URI
|
Uri string `yaml:"uri" validate:"required"` // MongoDB Atlas connection URI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -84,8 +84,8 @@ type Source struct {
|
|||||||
Client *mongo.Client
|
Client *mongo.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -293,7 +293,7 @@ func (s *Source) DeleteOne(ctx context.Context, filterString, database, collecti
|
|||||||
|
|
||||||
func initMongoDBClient(ctx context.Context, tracer trace.Tracer, name, uri string) (*mongo.Client, error) {
|
func initMongoDBClient(ctx context.Context, tracer trace.Tracer, name, uri string) (*mongo.Client, error) {
|
||||||
// Start a tracing span
|
// Start a tracing span
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
userAgent, err := util.UserAgentFromContext(ctx)
|
userAgent, err := util.UserAgentFromContext(ctx)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func TestParseFromYamlMongoDB(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"mongo-db": mongodb.Config{
|
"mongo-db": mongodb.Config{
|
||||||
Name: "mongo-db",
|
Name: "mongo-db",
|
||||||
Kind: mongodb.SourceKind,
|
Type: mongodb.SourceType,
|
||||||
Uri: "mongodb+srv://username:password@host/dbname",
|
Uri: "mongodb+srv://username:password@host/dbname",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "mssql"
|
const SourceType string = "mssql"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
// Cloud SQL MSSQL configs
|
// Cloud SQL MSSQL configs
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Host string `yaml:"host" validate:"required"`
|
Host string `yaml:"host" validate:"required"`
|
||||||
Port string `yaml:"port" validate:"required"`
|
Port string `yaml:"port" validate:"required"`
|
||||||
User string `yaml:"user" validate:"required"`
|
User string `yaml:"user" validate:"required"`
|
||||||
@@ -59,9 +59,9 @@ type Config struct {
|
|||||||
Encrypt string `yaml:"encrypt"`
|
Encrypt string `yaml:"encrypt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
// Returns Cloud SQL MSSQL source kind
|
// Returns Cloud SQL MSSQL source kind
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -91,9 +91,9 @@ type Source struct {
|
|||||||
Db *sql.DB
|
Db *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
// Returns Cloud SQL MSSQL source kind
|
// Returns Cloud SQL MSSQL source kind
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -156,7 +156,7 @@ func initMssqlConnection(
|
|||||||
error,
|
error,
|
||||||
) {
|
) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
userAgent, err := util.UserAgentFromContext(ctx)
|
userAgent, err := util.UserAgentFromContext(ctx)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func TestParseFromYamlMssql(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mssql-instance": mssql.Config{
|
"my-mssql-instance": mssql.Config{
|
||||||
Name: "my-mssql-instance",
|
Name: "my-mssql-instance",
|
||||||
Kind: mssql.SourceKind,
|
Type: mssql.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
@@ -70,7 +70,7 @@ func TestParseFromYamlMssql(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mssql-instance": mssql.Config{
|
"my-mssql-instance": mssql.Config{
|
||||||
Name: "my-mssql-instance",
|
Name: "my-mssql-instance",
|
||||||
Kind: mssql.SourceKind,
|
Type: mssql.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
|
|||||||
@@ -30,14 +30,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "mysql"
|
const SourceType string = "mysql"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Host string `yaml:"host" validate:"required"`
|
Host string `yaml:"host" validate:"required"`
|
||||||
Port string `yaml:"port" validate:"required"`
|
Port string `yaml:"port" validate:"required"`
|
||||||
User string `yaml:"user" validate:"required"`
|
User string `yaml:"user" validate:"required"`
|
||||||
@@ -61,8 +61,8 @@ type Config struct {
|
|||||||
QueryParams map[string]string `yaml:"queryParams"`
|
QueryParams map[string]string `yaml:"queryParams"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -90,8 +90,8 @@ type Source struct {
|
|||||||
Pool *sql.DB
|
Pool *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -158,7 +158,7 @@ func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (an
|
|||||||
|
|
||||||
func initMySQLConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string, queryParams map[string]string) (*sql.DB, error) {
|
func initMySQLConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string, queryParams map[string]string) (*sql.DB, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
// Build query parameters via url.Values for deterministic order and proper escaping.
|
// Build query parameters via url.Values for deterministic order and proper escaping.
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func TestParseFromYamlCloudSQLMySQL(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mysql-instance": mysql.Config{
|
"my-mysql-instance": mysql.Config{
|
||||||
Name: "my-mysql-instance",
|
Name: "my-mysql-instance",
|
||||||
Kind: mysql.SourceKind,
|
Type: mysql.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
@@ -75,7 +75,7 @@ func TestParseFromYamlCloudSQLMySQL(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mysql-instance": mysql.Config{
|
"my-mysql-instance": mysql.Config{
|
||||||
Name: "my-mysql-instance",
|
Name: "my-mysql-instance",
|
||||||
Kind: mysql.SourceKind,
|
Type: mysql.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
@@ -103,7 +103,7 @@ func TestParseFromYamlCloudSQLMySQL(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-mysql-instance": mysql.Config{
|
"my-mysql-instance": mysql.Config{
|
||||||
Name: "my-mysql-instance",
|
Name: "my-mysql-instance",
|
||||||
Kind: mysql.SourceKind,
|
Type: mysql.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
@@ -211,7 +211,7 @@ func TestFailInitialization(t *testing.T) {
|
|||||||
|
|
||||||
cfg := mysql.Config{
|
cfg := mysql.Config{
|
||||||
Name: "instance",
|
Name: "instance",
|
||||||
Kind: "mysql",
|
Type: "mysql",
|
||||||
Host: "localhost",
|
Host: "localhost",
|
||||||
Port: "3306",
|
Port: "3306",
|
||||||
Database: "db",
|
Database: "db",
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "neo4j"
|
const SourceType string = "neo4j"
|
||||||
|
|
||||||
var sourceClassifier *classifier.QueryClassifier = classifier.NewQueryClassifier()
|
var sourceClassifier *classifier.QueryClassifier = classifier.NewQueryClassifier()
|
||||||
|
|
||||||
@@ -37,8 +37,8 @@ var sourceClassifier *classifier.QueryClassifier = classifier.NewQueryClassifier
|
|||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,15 +52,15 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Uri string `yaml:"uri" validate:"required"`
|
Uri string `yaml:"uri" validate:"required"`
|
||||||
User string `yaml:"user" validate:"required"`
|
User string `yaml:"user" validate:"required"`
|
||||||
Password string `yaml:"password" validate:"required"`
|
Password string `yaml:"password" validate:"required"`
|
||||||
Database string `yaml:"database" validate:"required"`
|
Database string `yaml:"database" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -91,8 +91,8 @@ type Source struct {
|
|||||||
Driver neo4j.DriverWithContext
|
Driver neo4j.DriverWithContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -182,7 +182,7 @@ func addPlanChildren(p neo4j.Plan) []map[string]any {
|
|||||||
|
|
||||||
func initNeo4jDriver(ctx context.Context, tracer trace.Tracer, uri, user, password, name string) (neo4j.DriverWithContext, error) {
|
func initNeo4jDriver(ctx context.Context, tracer trace.Tracer, uri, user, password, name string) (neo4j.DriverWithContext, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
auth := neo4j.BasicAuth(user, password, "")
|
auth := neo4j.BasicAuth(user, password, "")
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func TestParseFromYamlNeo4j(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-neo4j-instance": neo4j.Config{
|
"my-neo4j-instance": neo4j.Config{
|
||||||
Name: "my-neo4j-instance",
|
Name: "my-neo4j-instance",
|
||||||
Kind: neo4j.SourceKind,
|
Type: neo4j.SourceType,
|
||||||
Uri: "neo4j+s://my-host:7687",
|
Uri: "neo4j+s://my-host:7687",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
User: "my_user",
|
User: "my_user",
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "oceanbase"
|
const SourceType string = "oceanbase"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Host string `yaml:"host" validate:"required"`
|
Host string `yaml:"host" validate:"required"`
|
||||||
Port string `yaml:"port" validate:"required"`
|
Port string `yaml:"port" validate:"required"`
|
||||||
User string `yaml:"user" validate:"required"`
|
User string `yaml:"user" validate:"required"`
|
||||||
@@ -57,8 +57,8 @@ type Config struct {
|
|||||||
QueryTimeout string `yaml:"queryTimeout"`
|
QueryTimeout string `yaml:"queryTimeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -86,8 +86,8 @@ type Source struct {
|
|||||||
Pool *sql.DB
|
Pool *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -153,7 +153,7 @@ func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (an
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initOceanBaseConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string) (*sql.DB, error) {
|
func initOceanBaseConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string) (*sql.DB, error) {
|
||||||
_, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
_, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?parseTime=true", user, pass, host, port, dbname)
|
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?parseTime=true", user, pass, host, port, dbname)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func TestParseFromYamlOceanBase(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-oceanbase-instance": oceanbase.Config{
|
"my-oceanbase-instance": oceanbase.Config{
|
||||||
Name: "my-oceanbase-instance",
|
Name: "my-oceanbase-instance",
|
||||||
Kind: oceanbase.SourceKind,
|
Type: oceanbase.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "2881",
|
Port: "2881",
|
||||||
Database: "ob_db",
|
Database: "ob_db",
|
||||||
@@ -71,7 +71,7 @@ func TestParseFromYamlOceanBase(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-oceanbase-instance": oceanbase.Config{
|
"my-oceanbase-instance": oceanbase.Config{
|
||||||
Name: "my-oceanbase-instance",
|
Name: "my-oceanbase-instance",
|
||||||
Kind: oceanbase.SourceKind,
|
Type: oceanbase.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "2881",
|
Port: "2881",
|
||||||
Database: "ob_db",
|
Database: "ob_db",
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "oracle"
|
const SourceType string = "oracle"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
ConnectionString string `yaml:"connectionString,omitempty"`
|
ConnectionString string `yaml:"connectionString,omitempty"`
|
||||||
TnsAlias string `yaml:"tnsAlias,omitempty"`
|
TnsAlias string `yaml:"tnsAlias,omitempty"`
|
||||||
TnsAdmin string `yaml:"tnsAdmin,omitempty"`
|
TnsAdmin string `yaml:"tnsAdmin,omitempty"`
|
||||||
@@ -95,8 +95,8 @@ func (c Config) validate() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -124,8 +124,8 @@ type Source struct {
|
|||||||
DB *sql.DB
|
DB *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -239,7 +239,7 @@ func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (an
|
|||||||
|
|
||||||
func initOracleConnection(ctx context.Context, tracer trace.Tracer, config Config) (*sql.DB, error) {
|
func initOracleConnection(ctx context.Context, tracer trace.Tracer, config Config) (*sql.DB, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, config.Name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, config.Name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
logger, err := util.LoggerFromContext(ctx)
|
logger, err := util.LoggerFromContext(ctx)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func TestParseFromYamlOracle(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-oracle-cs": oracle.Config{
|
"my-oracle-cs": oracle.Config{
|
||||||
Name: "my-oracle-cs",
|
Name: "my-oracle-cs",
|
||||||
Kind: oracle.SourceKind,
|
Type: oracle.SourceType,
|
||||||
ConnectionString: "my-host:1521/XEPDB1",
|
ConnectionString: "my-host:1521/XEPDB1",
|
||||||
User: "my_user",
|
User: "my_user",
|
||||||
Password: "my_pass",
|
Password: "my_pass",
|
||||||
@@ -56,7 +56,7 @@ func TestParseFromYamlOracle(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-oracle-host": oracle.Config{
|
"my-oracle-host": oracle.Config{
|
||||||
Name: "my-oracle-host",
|
Name: "my-oracle-host",
|
||||||
Kind: oracle.SourceKind,
|
Type: oracle.SourceType,
|
||||||
Host: "my-host",
|
Host: "my-host",
|
||||||
Port: 1521,
|
Port: 1521,
|
||||||
ServiceName: "ORCLPDB",
|
ServiceName: "ORCLPDB",
|
||||||
@@ -81,7 +81,7 @@ func TestParseFromYamlOracle(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-oracle-tns-oci": oracle.Config{
|
"my-oracle-tns-oci": oracle.Config{
|
||||||
Name: "my-oracle-tns-oci",
|
Name: "my-oracle-tns-oci",
|
||||||
Kind: oracle.SourceKind,
|
Type: oracle.SourceType,
|
||||||
TnsAlias: "FINANCE_DB",
|
TnsAlias: "FINANCE_DB",
|
||||||
TnsAdmin: "/opt/oracle/network/admin",
|
TnsAdmin: "/opt/oracle/network/admin",
|
||||||
User: "my_user",
|
User: "my_user",
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "postgres"
|
const SourceType string = "postgres"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Host string `yaml:"host" validate:"required"`
|
Host string `yaml:"host" validate:"required"`
|
||||||
Port string `yaml:"port" validate:"required"`
|
Port string `yaml:"port" validate:"required"`
|
||||||
User string `yaml:"user" validate:"required"`
|
User string `yaml:"user" validate:"required"`
|
||||||
@@ -58,8 +58,8 @@ type Config struct {
|
|||||||
QueryParams map[string]string `yaml:"queryParams"`
|
QueryParams map[string]string `yaml:"queryParams"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -87,8 +87,8 @@ type Source struct {
|
|||||||
Pool *pgxpool.Pool
|
Pool *pgxpool.Pool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -128,7 +128,7 @@ func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (an
|
|||||||
|
|
||||||
func initPostgresConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname string, queryParams map[string]string) (*pgxpool.Pool, error) {
|
func initPostgresConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname string, queryParams map[string]string) (*pgxpool.Pool, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
userAgent, err := util.UserAgentFromContext(ctx)
|
userAgent, err := util.UserAgentFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func TestParseFromYamlPostgres(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-pg-instance": postgres.Config{
|
"my-pg-instance": postgres.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: postgres.SourceKind,
|
Type: postgres.SourceType,
|
||||||
Host: "my-host",
|
Host: "my-host",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
@@ -74,7 +74,7 @@ func TestParseFromYamlPostgres(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-pg-instance": postgres.Config{
|
"my-pg-instance": postgres.Config{
|
||||||
Name: "my-pg-instance",
|
Name: "my-pg-instance",
|
||||||
Kind: postgres.SourceKind,
|
Type: postgres.SourceType,
|
||||||
Host: "my-host",
|
Host: "my-host",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "redis"
|
const SourceType string = "redis"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Address []string `yaml:"address" validate:"required"`
|
Address []string `yaml:"address" validate:"required"`
|
||||||
Username string `yaml:"username"`
|
Username string `yaml:"username"`
|
||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
@@ -54,8 +54,8 @@ type Config struct {
|
|||||||
ClusterEnabled bool `yaml:"clusterEnabled"`
|
ClusterEnabled bool `yaml:"clusterEnabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// RedisClient is an interface for `redis.Client` and `redis.ClusterClient
|
// RedisClient is an interface for `redis.Client` and `redis.ClusterClient
|
||||||
@@ -141,8 +141,8 @@ type Source struct {
|
|||||||
Client RedisClient
|
Client RedisClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func TestParseFromYamlRedis(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-redis-instance": redis.Config{
|
"my-redis-instance": redis.Config{
|
||||||
Name: "my-redis-instance",
|
Name: "my-redis-instance",
|
||||||
Kind: redis.SourceKind,
|
Type: redis.SourceType,
|
||||||
Address: []string{"127.0.0.1"},
|
Address: []string{"127.0.0.1"},
|
||||||
ClusterEnabled: false,
|
ClusterEnabled: false,
|
||||||
UseGCPIAM: false,
|
UseGCPIAM: false,
|
||||||
@@ -66,7 +66,7 @@ func TestParseFromYamlRedis(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-redis-instance": redis.Config{
|
"my-redis-instance": redis.Config{
|
||||||
Name: "my-redis-instance",
|
Name: "my-redis-instance",
|
||||||
Kind: redis.SourceKind,
|
Type: redis.SourceType,
|
||||||
Address: []string{"127.0.0.1"},
|
Address: []string{"127.0.0.1"},
|
||||||
Password: "my-pass",
|
Password: "my-pass",
|
||||||
Database: 1,
|
Database: 1,
|
||||||
|
|||||||
@@ -33,14 +33,14 @@ import (
|
|||||||
"google.golang.org/protobuf/encoding/protojson"
|
"google.golang.org/protobuf/encoding/protojson"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "serverless-spark"
|
const SourceType string = "serverless-spark"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,13 +54,13 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Project string `yaml:"project" validate:"required"`
|
Project string `yaml:"project" validate:"required"`
|
||||||
Location string `yaml:"location" validate:"required"`
|
Location string `yaml:"location" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -94,8 +94,8 @@ type Source struct {
|
|||||||
OpsClient *longrunning.OperationsClient
|
OpsClient *longrunning.OperationsClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func TestParseFromYamlServerlessSpark(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-instance": serverlessspark.Config{
|
"my-instance": serverlessspark.Config{
|
||||||
Name: "my-instance",
|
Name: "my-instance",
|
||||||
Kind: serverlessspark.SourceKind,
|
Type: serverlessspark.SourceType,
|
||||||
Project: "my-project",
|
Project: "my-project",
|
||||||
Location: "my-location",
|
Location: "my-location",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -29,15 +29,15 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SourceKind for SingleStore source
|
// SourceType for SingleStore source
|
||||||
const SourceKind string = "singlestore"
|
const SourceType string = "singlestore"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
// Config holds the configuration parameters for connecting to a SingleStore database.
|
// Config holds the configuration parameters for connecting to a SingleStore database.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Host string `yaml:"host" validate:"required"`
|
Host string `yaml:"host" validate:"required"`
|
||||||
Port string `yaml:"port" validate:"required"`
|
Port string `yaml:"port" validate:"required"`
|
||||||
User string `yaml:"user" validate:"required"`
|
User string `yaml:"user" validate:"required"`
|
||||||
@@ -61,9 +61,9 @@ type Config struct {
|
|||||||
QueryTimeout string `yaml:"queryTimeout"`
|
QueryTimeout string `yaml:"queryTimeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourceConfigKind returns the kind of the source configuration.
|
// SourceConfigType returns the kind of the source configuration.
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize sets up the SingleStore connection pool and returns a Source.
|
// Initialize sets up the SingleStore connection pool and returns a Source.
|
||||||
@@ -93,9 +93,9 @@ type Source struct {
|
|||||||
Pool *sql.DB
|
Pool *sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// SourceKind returns the kind of the source configuration.
|
// SourceType returns the kind of the source configuration.
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -162,7 +162,7 @@ func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (an
|
|||||||
|
|
||||||
func initSingleStoreConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string) (*sql.DB, error) {
|
func initSingleStoreConnectionPool(ctx context.Context, tracer trace.Tracer, name, host, port, user, pass, dbname, queryTimeout string) (*sql.DB, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
// Configure the driver to connect to the database
|
// Configure the driver to connect to the database
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func TestParseFromYaml(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-s2-instance": singlestore.Config{
|
"my-s2-instance": singlestore.Config{
|
||||||
Name: "my-s2-instance",
|
Name: "my-s2-instance",
|
||||||
Kind: singlestore.SourceKind,
|
Type: singlestore.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
@@ -70,7 +70,7 @@ func TestParseFromYaml(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-s2-instance": singlestore.Config{
|
"my-s2-instance": singlestore.Config{
|
||||||
Name: "my-s2-instance",
|
Name: "my-s2-instance",
|
||||||
Kind: singlestore.SourceKind,
|
Type: singlestore.SourceType,
|
||||||
Host: "0.0.0.0",
|
Host: "0.0.0.0",
|
||||||
Port: "my-port",
|
Port: "my-port",
|
||||||
Database: "my_db",
|
Database: "my_db",
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SourceKind string = "snowflake"
|
const SourceType string = "snowflake"
|
||||||
|
|
||||||
// validate interface
|
// validate interface
|
||||||
var _ sources.SourceConfig = Config{}
|
var _ sources.SourceConfig = Config{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if !sources.Register(SourceKind, newConfig) {
|
if !sources.Register(SourceType, newConfig) {
|
||||||
panic(fmt.Sprintf("source kind %q already registered", SourceKind))
|
panic(fmt.Sprintf("source type %q already registered", SourceType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (sources
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:"name" validate:"required"`
|
Name string `yaml:"name" validate:"required"`
|
||||||
Kind string `yaml:"kind" validate:"required"`
|
Type string `yaml:"kind" validate:"required"`
|
||||||
Account string `yaml:"account" validate:"required"`
|
Account string `yaml:"account" validate:"required"`
|
||||||
User string `yaml:"user" validate:"required"`
|
User string `yaml:"user" validate:"required"`
|
||||||
Password string `yaml:"password" validate:"required"`
|
Password string `yaml:"password" validate:"required"`
|
||||||
@@ -56,8 +56,8 @@ type Config struct {
|
|||||||
Role string `yaml:"role"`
|
Role string `yaml:"role"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) SourceConfigKind() string {
|
func (r Config) SourceConfigType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.Source, error) {
|
||||||
@@ -85,8 +85,8 @@ type Source struct {
|
|||||||
DB *sqlx.DB
|
DB *sqlx.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) SourceKind() string {
|
func (s *Source) SourceType() string {
|
||||||
return SourceKind
|
return SourceType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) ToConfig() sources.SourceConfig {
|
func (s *Source) ToConfig() sources.SourceConfig {
|
||||||
@@ -137,7 +137,7 @@ func (s *Source) RunSQL(ctx context.Context, statement string, params []any) (an
|
|||||||
|
|
||||||
func initSnowflakeConnection(ctx context.Context, tracer trace.Tracer, name, account, user, password, database, schema, warehouse, role string) (*sqlx.DB, error) {
|
func initSnowflakeConnection(ctx context.Context, tracer trace.Tracer, name, account, user, password, database, schema, warehouse, role string) (*sqlx.DB, error) {
|
||||||
//nolint:all // Reassigned ctx
|
//nolint:all // Reassigned ctx
|
||||||
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceKind, name)
|
ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, name)
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
// Set defaults for optional parameters
|
// Set defaults for optional parameters
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func TestParseFromYamlSnowflake(t *testing.T) {
|
|||||||
want: server.SourceConfigs{
|
want: server.SourceConfigs{
|
||||||
"my-snowflake-instance": snowflake.Config{
|
"my-snowflake-instance": snowflake.Config{
|
||||||
Name: "my-snowflake-instance",
|
Name: "my-snowflake-instance",
|
||||||
Kind: snowflake.SourceKind,
|
Type: snowflake.SourceType,
|
||||||
Account: "my-account",
|
Account: "my-account",
|
||||||
User: "my_user",
|
User: "my_user",
|
||||||
Password: "my_pass",
|
Password: "my_pass",
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user