Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export go config types #3162

Open
efitzkiwi opened this issue Feb 19, 2025 · 3 comments
Open

Export go config types #3162

efitzkiwi opened this issue Feb 19, 2025 · 3 comments

Comments

@efitzkiwi
Copy link

Is your feature request related to a problem? Please describe.
I'm trying to use the CLI source code in my Go application to make API calls and config updates to my supabase instance

Describe the solution you'd like
Export the Go fields for auth config, storage config, etc

Describe alternatives you've considered
Manually editing the source code

Additional context
For example

import (
	"context"
	"net/http"
	"time"

	"github.com/supabase/cli/pkg/api"
	"github.com/supabase/cli/pkg/config"
)

func NewApiClient(token string) api.ClientWithResponses {
	header := func(ctx context.Context, req *http.Request) error {
		req.Header.Set("Authorization", "Bearer "+token)
		return nil
	}
	client := api.ClientWithResponses{ClientInterface: &api.Client{
		// Ensure the server URL always has a trailing slash
		Server: "https://api.supabase.com/",
		Client: &http.Client{
			Timeout: 10 * time.Second,
		},
		RequestEditors: []api.RequestEditorFn{header},
	}}
	return client
}

func NewConfigClient(token string) config.ConfigUpdater {
	return config.NewConfigUpdater(NewApiClient(token))
}

func main() {
        // config.auth (among other types) is not exported... impossible to use this
        supabaseClient := NewConfigClient(supabaseToken)
        supabaseClient.UpdateAuthConfig(context.Background(), os.Getenv("SUPABASE_PROJECT_ID"), config.auth{})
}
@sweatybridge
Copy link
Contributor

Hello, this is actually by design to prevent accidentally using uninitialised values. You can use the exposed constructor instead.

func main() {
        c := config.NewConfig()
        supabaseClient := NewConfigClient(supabaseToken)
        supabaseClient.UpdateAuthConfig(context.Background(), os.Getenv("SUPABASE_PROJECT_ID"), c.Auth)
}

@efitzkiwi
Copy link
Author

Is there a recommended way of first fetching the upstream config, so I can merge a new config with our current values? Or would this not be necessary?

@sweatybridge
Copy link
Contributor

Currently we don't have a method for pulling the entire remote config into local. But individual service config can be updated by parsing from the api response. For eg. https://github.com/supabase/cli/blob/develop/internal/link/link.go#L139

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants