Cobra scaffold, credentials store, Connect client, device-flow login, whoami/logout, plugin init (creates + adds git remote), publish (tag + push + registry RPC), and status (list scopes/plugins). Proto copied from orchestrator with buf codegen for client stubs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package orchclient
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"connectrpc.com/connect"
|
|
"git.dev.alexdunmow.com/block/core/internal/api/orchestrator/v1/orchestratorv1connect"
|
|
)
|
|
|
|
type Client struct {
|
|
Host string
|
|
Token string
|
|
Auth orchestratorv1connect.PluginAuthServiceClient
|
|
Scope orchestratorv1connect.PluginScopeServiceClient
|
|
Reg orchestratorv1connect.PluginRegistryServiceClient
|
|
Pub orchestratorv1connect.PluginPublishServiceClient
|
|
}
|
|
|
|
func New(host, token string) *Client {
|
|
httpClient := &http.Client{}
|
|
opts := []connect.ClientOption{
|
|
connect.WithInterceptors(bearerInterceptor(token)),
|
|
}
|
|
c := &Client{Host: host, Token: token}
|
|
c.Auth = orchestratorv1connect.NewPluginAuthServiceClient(httpClient, host, opts...)
|
|
c.Scope = orchestratorv1connect.NewPluginScopeServiceClient(httpClient, host, opts...)
|
|
c.Reg = orchestratorv1connect.NewPluginRegistryServiceClient(httpClient, host, opts...)
|
|
c.Pub = orchestratorv1connect.NewPluginPublishServiceClient(httpClient, host, opts...)
|
|
return c
|
|
}
|
|
|
|
func bearerInterceptor(token string) connect.Interceptor {
|
|
return connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
|
|
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
|
|
if token != "" {
|
|
req.Header().Set("Authorization", "Bearer "+token)
|
|
}
|
|
return next(ctx, req)
|
|
}
|
|
})
|
|
}
|