Skip to content

Commit ba7b687

Browse files
author
Dimy Jeannot
committed
fix: updating generators for spec clients and clis; adjusting nats and nebula bindings
1 parent 7609821 commit ba7b687

35 files changed

+176
-389
lines changed

go/oeco-sdk/v2beta/bindings/nats/binding.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ func (b *Binding) Validate(_ context.Context, _ *sdkv2betalib.Bindings) error {
5858
return nil
5959
}
6060

61+
func NewNatsBinding(configuration *Configuration) *Binding {
62+
return &Binding{
63+
configuration: configuration,
64+
}
65+
}
66+
6167
// Bind initializes the Binding instance, configures NATS or JetStream connections, and registers the binding in Bindings.
6268
func (b *Binding) Bind(_ context.Context, bindings *sdkv2betalib.Bindings) *sdkv2betalib.Bindings {
6369
if Bound == nil {
@@ -79,6 +85,10 @@ func (b *Binding) Bind(_ context.Context, bindings *sdkv2betalib.Bindings) *sdkv
7985

8086
systemAccount := natsd.NewAccount(natsd.DEFAULT_SYSTEM_ACCOUNT)
8187
connectorAccount := natsd.NewAccount(DEFAULT_CONNECTOR_ACCOUNT)
88+
storeDir := NatsdServerJetstreamStoreDir
89+
if b.configuration.Natsd.StoreDir != "" {
90+
storeDir = b.configuration.Natsd.StoreDir
91+
}
8292

8393
options := natsd.Options{
8494
// Standard client options
@@ -117,7 +127,7 @@ func (b *Binding) Bind(_ context.Context, bindings *sdkv2betalib.Bindings) *sdkv
117127
JetStream: true,
118128
JetStreamMaxMemory: -1,
119129
JetStreamMaxStore: -1,
120-
StoreDir: NatsdServerJetstreamStoreDir,
130+
StoreDir: storeDir,
121131
DisableJetStreamBanner: true,
122132
}
123133

go/oeco-sdk/v2beta/bindings/nats/configurer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type Natsd struct {
5252
Password string
5353
Replicas int
5454
Clustered bool
55+
StoreDir string
5556
Cluster Cluster
5657
}
5758

@@ -73,6 +74,14 @@ type Configuration struct {
7374

7475
// ResolveConfiguration resolves the binding's configuration using the default configuration as a base and assigns it.
7576
func (b *Binding) ResolveConfiguration(opts ...sdkv2betalib.ConfigurationProviderOption) (*sdkv2betalib.Configurer, error) {
77+
if b.configuration != nil {
78+
configurer, err := sdkv2betalib.NewConfigurer(opts...)
79+
if err != nil {
80+
return nil, err
81+
}
82+
return configurer, nil
83+
}
84+
7685
var c Configuration
7786
configurer, err := sdkv2betalib.NewConfigurer(opts...)
7887
if err != nil {

go/oeco-sdk/v2beta/bindings/nebula/binding.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ func (b *Binding) Validate(_ context.Context, _ *sdkv2betalib.Bindings) error {
4747
return nil
4848
}
4949

50+
func NewNebulaBinding(configuration *Configuration) *Binding {
51+
return &Binding{
52+
configuration: configuration,
53+
}
54+
}
55+
5056
// Bind creates a binding by configuring a mesh socket, registers it, and ensures the binding is only initialized once.
5157
func (b *Binding) Bind(_ context.Context, bindings *sdkv2betalib.Bindings) *sdkv2betalib.Bindings {
5258
if Bound == nil {

go/oeco-sdk/v2beta/bindings/nebula/configurer.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ type Configuration struct {
159159

160160
// ResolveConfiguration resolves the binding's configuration using the default configuration as a base and assigns it.
161161
func (b *Binding) ResolveConfiguration(opts ...sdkv2betalib.ConfigurationProviderOption) (*sdkv2betalib.Configurer, error) {
162+
if b.configuration != nil {
163+
configurer, err := sdkv2betalib.NewConfigurer(opts...)
164+
if err != nil {
165+
return nil, err
166+
}
167+
return configurer, nil
168+
}
169+
162170
var c Configuration
163171
configurer, err := sdkv2betalib.NewConfigurer(opts...)
164172
if err != nil {

libs/plugins/protoc-gen-platform/languages/go/plugins/v2beta/cli_methods/templates/file.go.tmpl

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ package {{ goPath .File }}cli
88
import (
99
"encoding/json"
1010
"os"
11-
"connectrpc.com/connect"
11+
1212
"google.golang.org/protobuf/encoding/protojson"
1313
"github.com/spf13/cobra"
1414
clog "github.com/charmbracelet/log"
15-
sdkv2betalib "github.com/openecosystems/ecosystem/go/oeco-sdk/v2beta"
1615

16+
cli "github.com/adino/platform/apps/clients/public/cli/v2alpha/adino/cli"
17+
sdkv2betalib "github.com/openecosystems/ecosystem/go/oeco-sdk/v2beta"
18+
"github.com/adino/platform/apps/clients/public/cli/v2alpha/adino/utils"
1719
adinosdkv2beta "github.com/adino/platform/go/adino-sdk/v2beta"
1820

1921
{{ range getImportPackages .File }}
@@ -33,53 +35,45 @@ var {{ .Name }}{{ $version.UpperCamelCase }}Cmd = &cobra.Command{
3335
Long: `{{- $leadingDetachedComments -}}`,
3436
Run: func(cmd *cobra.Command, args []string) {
3537
log := cmd.Context().Value(sdkv2betalib.LoggerContextKey).(*clog.Logger)
38+
adino := cmd.Context().Value(cli.AdinoSDKContextKey).(*adinosdkv2beta.AdinoClient)
3639
log.Debug("Calling {{ .Name.LowerCamelCase }} {{ $entityName.LowerCamelCase }}")
37-
//settings := cmd.Root().Context().Value(sdkv2betalib.SettingsContextKey).(*sdkv2betalib.CLIConfiguration)
3840

39-
_, err := cmd.Flags().GetString("field-mask")
41+
params, err := cliutils.ExtractParameters(cmd, args)
4042
if err != nil {
4143
log.Error(err)
4244
os.Exit(1)
4345
}
4446

45-
_, err = cmd.Flags().GetBool("validate-only")
46-
if err != nil {
47-
log.Error(err)
48-
os.Exit(1)
49-
}
50-
51-
_request, err := cmd.Flags().GetString("request")
52-
if err != nil {
53-
log.Error(err)
54-
os.Exit(1)
55-
}
56-
57-
if _request == "" {
58-
_request = "{}"
59-
}
60-
61-
_r := {{ goPath .File }}.{{ .Input.Name.UpperCamelCase }}{}
62-
err = protojson.Unmarshal([]byte(_request), &_r)
47+
request := {{ goPath .File }}.{{ .Input.Name.UpperCamelCase }}{}
48+
err = protojson.Unmarshal([]byte(params.Request), &request)
6349
if err != nil {
64-
log.Error(err)
65-
os.Exit(1)
50+
log.Error(err)
51+
os.Exit(1)
6652
}
6753

68-
request := connect.NewRequest[{{ goPath .File }}.{{ .Input.Name.UpperCamelCase }}](&_r)
69-
adino, err := adinosdkv2beta.NewAdinoClient()
70-
if err != nil {
71-
log.Error(err)
72-
os.Exit(1)
73-
}
54+
{{- if eq (getCqrsType . ) "stream-server" }} // server streaming
55+
err = adino.{{ $system }}.{{ $s.Name.UpperCamelCase }}.{{ .Name.UpperCamelCase }}(cmd.Context(), &request, func(msg *{{ goPath .File }}.{{ .Output.Name.UpperCamelCase }}) {
56+
log.Info("Received {{ .Output.Name.UpperCamelCase }}:", msg)
57+
val, _ := json.MarshalIndent(&msg, "", " ")
58+
log.Info(string(val))
59+
})
60+
if err != nil {
61+
log.Fatal(err)
62+
}
63+
{{- else if eq (getCqrsType . ) "stream-bidi" }} // bidi streaming
7464

75-
response, err := adino.{{ $system }}.{{ $s.Name.UpperCamelCase }}.{{ .Name.UpperCamelCase }}(cmd.Context(), request)
65+
{{- else }} // unary
66+
response, err := adino.{{ $system }}.{{ $s.Name.UpperCamelCase }}.{{ .Name.UpperCamelCase }}(cmd.Context(), &request, params.CallOptions...)
7667
if err != nil {
77-
log.Error(err)
78-
os.Exit(1)
68+
log.Error(err)
69+
os.Exit(1)
7970
}
8071

8172
val, _ := json.MarshalIndent(&response, "", " ")
8273
log.Info(string(val))
74+
{{ end -}}
75+
76+
8377
},
8478
}
8579

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11

22
// NewAdinoClient creates and initializes a new AdinoClient with the specified configuration, base URL, and client options.
3-
func NewAdinoClient(opts ...SDKOption) (*AdinoClient, sdkv2betalib.SpecErrorable) {
4-
options, serr := NewSDKOptions(opts)
5-
if serr != nil {
6-
return nil, serr
7-
}
8-
9-
o := options.ToConnectParameters()
3+
func NewAdinoClient(opts ...adinoclient.SDKOption) (*AdinoClient, sdkv2betalib.SpecErrorable) {
104

115
return &AdinoClient{
12-
options: options,

libs/plugins/protoc-gen-platform/languages/go/plugins/v2beta/client/templates/file.go.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
package adinosdkv2beta
33

44
import (
5+
adinoclient "github.com/adino/platform/go/adino-sdk/v2beta/client"
56
sdkv2betalib "github.com/openecosystems/ecosystem/go/oeco-sdk/v2beta"
67
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
{{ $e := entity .File -}}{{- $alias := getGoPackageAlias .File }}
2-
{{ .Name.UpperCamelCase }}: {{ $alias }}connect.New{{ .Name.UpperCamelCase }}Client(o.HttpClient, o.BaseURL, o.Opts...),
2+
{{ .Name.UpperCamelCase }}: {{ $alias }}connect.New{{ .Name.UpperCamelCase }}SpecClient(opts...),

libs/plugins/protoc-gen-platform/languages/go/plugins/v2beta/client/templates/struct_open.go.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
// AdinoClient provides a unified client interface for interacting with systems.
44
type AdinoClient struct {
5-
options *SDKOptions
5+
options *adinoclient.SDKOptions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
{{ $e := entity .File -}}{{- $alias := getGoPackageAlias .File }}
2-
{{ .Name.UpperCamelCase }} {{ $alias }}connect.{{ .Name.UpperCamelCase }}Client
2+
{{ .Name.UpperCamelCase }} {{ $alias }}connect.{{ .Name.UpperCamelCase }}SpecClient

0 commit comments

Comments
 (0)