mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-05-02 03:00:36 -04:00
This PR introduces a significant update to the Toolbox configuration file format, which is one of the primary **breaking changes** required for the implementation of the Advanced Control Plane. # Summary of Changes The configuration schema has been updated to enforce resource isolation and facilitate atomic, incremental updates. * Resource Isolation: Resource definitions are now separated into individual blocks, using a distinct structure for each resource type (Source, Tool, Toolset, etc.). This improves readability, management, and auditing of configuration files. * Field Name Modification: Internal field names have been modified to align with declarative methodologies. Specifically, the configuration now separates kind (general resource type, e.g., Source) from type (specific implementation, e.g., Postgres). # User Impact Existing tools.yaml configuration files are now in an outdated format. Users must eventually update their files to the new YAML format. # Mitigation & Compatibility Backward compatibility is maintained during this transition to ensure no immediate user action is required for existing files. * Immediate Backward Compatibility: The source code includes a pre-processing layer that automatically detects outdated configuration files (v1 format) and converts them to the new v2 format under the hood. * [COMING SOON] Migration Support: The new toolbox migrate subcommand will be introduced to allow users to automatically convert their old configuration files to the latest format. # Example Example for config file v2: ``` 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: tools name: example_tool_2 type: postgres-sql source: my-pg-instance description: returning the number one statement: SELECT 1; --- kind: toolsets name: example_toolset tools: - example_tool ``` --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Averi Kitsch <akitsch@google.com>
194 lines
5.2 KiB
Go
194 lines
5.2 KiB
Go
// Copyright © 2025, Oracle and/or its affiliates.
|
|
|
|
package oracle_test
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/googleapis/genai-toolbox/internal/server"
|
|
"github.com/googleapis/genai-toolbox/internal/sources"
|
|
"github.com/googleapis/genai-toolbox/internal/sources/oracle"
|
|
"github.com/googleapis/genai-toolbox/internal/testutils"
|
|
)
|
|
|
|
func TestParseFromYamlOracle(t *testing.T) {
|
|
tcs := []struct {
|
|
desc string
|
|
in string
|
|
want server.SourceConfigs
|
|
}{
|
|
{
|
|
desc: "connection string and useOCI=true",
|
|
in: `
|
|
kind: sources
|
|
name: my-oracle-cs
|
|
type: oracle
|
|
connectionString: "my-host:1521/XEPDB1"
|
|
user: my_user
|
|
password: my_pass
|
|
useOCI: true
|
|
`,
|
|
want: map[string]sources.SourceConfig{
|
|
"my-oracle-cs": oracle.Config{
|
|
Name: "my-oracle-cs",
|
|
Type: oracle.SourceType,
|
|
ConnectionString: "my-host:1521/XEPDB1",
|
|
User: "my_user",
|
|
Password: "my_pass",
|
|
UseOCI: true,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
desc: "host/port/serviceName and default useOCI=false",
|
|
in: `
|
|
kind: sources
|
|
name: my-oracle-host
|
|
type: oracle
|
|
host: my-host
|
|
port: 1521
|
|
serviceName: ORCLPDB
|
|
user: my_user
|
|
password: my_pass
|
|
`,
|
|
want: map[string]sources.SourceConfig{
|
|
"my-oracle-host": oracle.Config{
|
|
Name: "my-oracle-host",
|
|
Type: oracle.SourceType,
|
|
Host: "my-host",
|
|
Port: 1521,
|
|
ServiceName: "ORCLPDB",
|
|
User: "my_user",
|
|
Password: "my_pass",
|
|
UseOCI: false,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
desc: "tnsAlias and TnsAdmin specified with explicit useOCI=true",
|
|
in: `
|
|
kind: sources
|
|
name: my-oracle-tns-oci
|
|
type: oracle
|
|
tnsAlias: FINANCE_DB
|
|
tnsAdmin: /opt/oracle/network/admin
|
|
user: my_user
|
|
password: my_pass
|
|
useOCI: true
|
|
`,
|
|
want: map[string]sources.SourceConfig{
|
|
"my-oracle-tns-oci": oracle.Config{
|
|
Name: "my-oracle-tns-oci",
|
|
Type: oracle.SourceType,
|
|
TnsAlias: "FINANCE_DB",
|
|
TnsAdmin: "/opt/oracle/network/admin",
|
|
User: "my_user",
|
|
Password: "my_pass",
|
|
UseOCI: true,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tc := range tcs {
|
|
t.Run(tc.desc, func(t *testing.T) {
|
|
got, _, _, _, _, _, err := server.UnmarshalResourceConfig(context.Background(), testutils.FormatYaml(tc.in))
|
|
if err != nil {
|
|
t.Fatalf("unable to unmarshal: %s", err)
|
|
}
|
|
if !cmp.Equal(tc.want, got) {
|
|
t.Fatalf("incorrect parse:\nwant: %v\ngot: %v\ndiff: %s", tc.want, got, cmp.Diff(tc.want, got))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFailParseFromYaml(t *testing.T) {
|
|
tcs := []struct {
|
|
desc string
|
|
in string
|
|
err string
|
|
}{
|
|
{
|
|
desc: "extra field",
|
|
in: `
|
|
kind: sources
|
|
name: my-oracle-instance
|
|
type: oracle
|
|
host: my-host
|
|
serviceName: ORCL
|
|
user: my_user
|
|
password: my_pass
|
|
extraField: value
|
|
`,
|
|
err: "error unmarshaling sources: unable to parse source \"my-oracle-instance\" as \"oracle\": [1:1] unknown field \"extraField\"\n> 1 | extraField: value\n ^\n 2 | host: my-host\n 3 | name: my-oracle-instance\n 4 | password: my_pass\n 5 | ",
|
|
},
|
|
{
|
|
desc: "missing required password field",
|
|
in: `
|
|
kind: sources
|
|
name: my-oracle-instance
|
|
type: oracle
|
|
host: my-host
|
|
serviceName: ORCL
|
|
user: my_user
|
|
`,
|
|
err: "error unmarshaling sources: unable to parse source \"my-oracle-instance\" as \"oracle\": Key: 'Config.Password' Error:Field validation for 'Password' failed on the 'required' tag",
|
|
},
|
|
{
|
|
desc: "missing connection method fields (validate fails)",
|
|
in: `
|
|
kind: sources
|
|
name: my-oracle-instance
|
|
type: oracle
|
|
user: my_user
|
|
password: my_pass
|
|
`,
|
|
err: "error unmarshaling sources: unable to parse source \"my-oracle-instance\" as \"oracle\": invalid Oracle configuration: must provide one of: 'tns_alias', 'connection_string', or both 'host' and 'service_name'",
|
|
},
|
|
{
|
|
desc: "multiple connection methods provided (validate fails)",
|
|
in: `
|
|
kind: sources
|
|
name: my-oracle-instance
|
|
type: oracle
|
|
host: my-host
|
|
serviceName: ORCL
|
|
connectionString: "my-host:1521/XEPDB1"
|
|
user: my_user
|
|
password: my_pass
|
|
`,
|
|
err: "error unmarshaling sources: unable to parse source \"my-oracle-instance\" as \"oracle\": invalid Oracle configuration: provide only one connection method: 'tns_alias', 'connection_string', or 'host'+'service_name'",
|
|
},
|
|
{
|
|
desc: "fail on tnsAdmin with useOCI=false",
|
|
in: `
|
|
kind: sources
|
|
name: my-oracle-fail
|
|
type: oracle
|
|
tnsAlias: FINANCE_DB
|
|
tnsAdmin: /opt/oracle/network/admin
|
|
user: my_user
|
|
password: my_pass
|
|
useOCI: false
|
|
`,
|
|
err: "error unmarshaling sources: unable to parse source \"my-oracle-fail\" as \"oracle\": invalid Oracle configuration: `tnsAdmin` can only be used when `UseOCI` is true, or use `walletLocation` instead",
|
|
},
|
|
}
|
|
for _, tc := range tcs {
|
|
t.Run(tc.desc, func(t *testing.T) {
|
|
_, _, _, _, _, _, err := server.UnmarshalResourceConfig(context.Background(), testutils.FormatYaml(tc.in))
|
|
if err == nil {
|
|
t.Fatalf("expect parsing to fail")
|
|
}
|
|
errStr := strings.ReplaceAll(err.Error(), "\r", "")
|
|
|
|
if errStr != tc.err {
|
|
t.Fatalf("unexpected error:\ngot:\n%q\nwant:\n%q\n", errStr, tc.err)
|
|
}
|
|
})
|
|
}
|
|
}
|