Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pkg/capabilities/pb/capabilities.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/capabilities/pb/capabilities.proto
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ message InitialiseRequest {
uint32 oracle_factory_id = 8;
uint32 gateway_connector_id = 9;
uint32 keystore_id = 10;
uint32 org_resolver_id = 11;
}

message CapabilityInfosReply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
keystoreservice "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/core/services/keystore"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/core/services/keyvalue"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/core/services/oraclefactory"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/core/services/orgresolver"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/core/services/pipeline"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/core/services/telemetry"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/goplugin"
Expand Down Expand Up @@ -156,6 +157,15 @@ func (c *StandardCapabilitiesClient) Initialise(ctx context.Context, dependencie
}
resources = append(resources, gatewayConnectorRes)

orgResolverID, orgResolverRes, err := c.ServeNew("OrgResolver", func(s *grpc.Server) {
pb.RegisterOrgResolverServer(s, orgresolver.NewServer(dependencies.OrgResolver))
})
if err != nil {
c.CloseAll(resources...)
return fmt.Errorf("failed to serve org resolver: %w", err)
}
resources = append(resources, orgResolverRes)

_, err = c.StandardCapabilitiesClient.Initialise(ctx, &capabilitiespb.InitialiseRequest{
Config: config,
ErrorLogId: errorLogID,
Expand All @@ -167,6 +177,7 @@ func (c *StandardCapabilitiesClient) Initialise(ctx context.Context, dependencie
OracleFactoryId: oracleFactoryID,
GatewayConnectorId: gatewayConnectorID,
KeystoreId: keyStoreID,
OrgResolverId: orgResolverID,
})

if err != nil {
Expand Down Expand Up @@ -310,6 +321,14 @@ func (s *standardCapabilitiesServer) Initialise(ctx context.Context, request *ca
resources = append(resources, net.Resource{Closer: gatewayConnectorConn, Name: "GatewayConnector"})
gatewayConnector := gateway.NewGatewayConnectorClient(gatewayConnectorConn, s.BrokerExt)

orgResolverConn, err := s.Dial(request.OrgResolverId)
if err != nil {
s.CloseAll(resources...)
return nil, net.ErrConnDial{Name: "OrgResolver", ID: request.OrgResolverId, Err: err}
}
resources = append(resources, net.Resource{Closer: orgResolverConn, Name: "OrgResolver"})
orgResolver := orgresolver.NewClient(orgResolverConn)

dependencies := core.StandardCapabilitiesDependencies{
Config: request.Config,
TelemetryService: telemetry,
Expand All @@ -321,6 +340,7 @@ func (s *standardCapabilitiesServer) Initialise(ctx context.Context, request *ca
OracleFactory: oracleFactory,
GatewayConnector: gatewayConnector,
P2PKeystore: keyStore,
OrgResolver: orgResolver,
}

if err = s.impl.Initialise(ctx, dependencies); err != nil {
Expand Down
48 changes: 48 additions & 0 deletions pkg/loop/internal/core/services/orgresolver/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package orgresolver

import (
"context"

"google.golang.org/grpc"

"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb"
"github.com/smartcontractkit/chainlink-common/pkg/services/orgresolver"
)

var _ orgresolver.OrgResolver = (*Client)(nil)

type Client struct {
grpc pb.OrgResolverClient
}

func (c *Client) Get(ctx context.Context, owner string) (string, error) {
resp, err := c.grpc.Get(ctx, &pb.GetOrganizationRequest{Owner: owner})
if err != nil {
return "", err
}
return resp.OrganizationId, nil
}

func (c *Client) Start(_ context.Context) error {
return nil
}

func (c *Client) HealthReport() map[string]error {
return map[string]error{c.Name(): nil}
}

func (c *Client) Close() error {
return nil
}

func (c *Client) Name() string {
return "OrgResolverClient"
}

func (c *Client) Ready() error {
return nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to implement Service?

Suggested change
func (c *Client) Start(_ context.Context) error {
return nil
}
func (c *Client) HealthReport() map[string]error {
return map[string]error{c.Name(): nil}
}
func (c *Client) Close() error {
return nil
}
func (c *Client) Name() string {
return "OrgResolverClient"
}
func (c *Client) Ready() error {
return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't, won't any consumer of the service in the capabilities get hit with a panic if they try to call these methods?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func NewClient(cc grpc.ClientConnInterface) *Client {
return &Client{grpc: pb.NewOrgResolverClient(cc)}
}
27 changes: 27 additions & 0 deletions pkg/loop/internal/core/services/orgresolver/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package orgresolver

import (
"context"

"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb"
"github.com/smartcontractkit/chainlink-common/pkg/services/orgresolver"
)

var _ pb.OrgResolverServer = (*Server)(nil)

type Server struct {
pb.UnimplementedOrgResolverServer
impl orgresolver.OrgResolver
}

func NewServer(impl orgresolver.OrgResolver) *Server {
return &Server{impl: impl}
}

func (s *Server) Get(ctx context.Context, req *pb.GetOrganizationRequest) (*pb.GetOrganizationResponse, error) {
orgID, err := s.impl.Get(ctx, req.Owner)
if err != nil {
return nil, err
}
return &pb.GetOrganizationResponse{OrganizationId: orgID}, nil
}
1 change: 1 addition & 0 deletions pkg/loop/internal/pb/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative pipeline_runner.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative keyvalue_store.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative validate_config.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative orgresolver.proto
package pb
174 changes: 174 additions & 0 deletions pkg/loop/internal/pb/orgresolver.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pkg/loop/internal/pb/orgresolver.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
syntax = "proto3";

option go_package = "github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb";

package loop;

import "google/protobuf/empty.proto";

message GetOrganizationRequest {
string owner = 1;
}

message GetOrganizationResponse {
string organization_id = 1;
}

service OrgResolver {
rpc Get(GetOrganizationRequest) returns (GetOrganizationResponse);
}
Loading
Loading