chipingress

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 15 Imported by: 1

README

ChipIngress

ChipIngress is a gRPC client library for interacting with the ChipIngress service. It provides functionality for publishing CloudEvents to the ChipIngress service and supports various authentication methods.

Features

  • CloudEvent Publishing: Publish single events or batches of events
  • Authentication Support: Multiple authentication methods including basic auth and token-based auth
  • Secure Communication: Support for both TLS and insecure connections
  • Event Management: Utilities for creating, converting, and managing CloudEvents

Installation

go get github.com/smartcontractkit/chainlink-common/pkg/chipingress

Usage

Basic Client Creation
import "github.com/smartcontractkit/chainlink-common/pkg/chipingress"

// Create client with default settings (insecure connection)
client, err := chipingress.NewClient("localhost:9090")
if err != nil {
    log.Fatal(err)
}
defer client.Close()
Client with TLS
client, err := chipingress.NewClient("example.com:9090", chipingress.WithTLS())
if err != nil {
    log.Fatal(err)
}
defer client.Close()
Client with Authentication
// Basic Auth
client, err := chipingress.NewClient("example.com:9090", 
    chipingress.WithTLS(),
    chipingress.WithBasicAuth("username", "password"))

// Token Auth
tokenProvider := &myTokenProvider{}
client, err := chipingress.NewClient("example.com:9090", 
    chipingress.WithTLS(),
    chipingress.WithTokenAuth(tokenProvider))
Creating and Publishing Events
// Create a new event
event, err := chipingress.NewEvent(
    "my-domain", 
    "my-entity", 
    []byte("event payload"),
    map[string]any{
        "subject": "test-subject",
        "time": time.Now(),
    })
if err != nil {
    log.Fatal(err)
}

// Convert to protobuf
eventPb, err := chipingress.EventToProto(event)
if err != nil {
    log.Fatal(err)
}

// Publish the event
response, err := client.Publish(context.Background(), eventPb)
if err != nil {
    log.Fatal(err)
}

Dependencies

  • github.com/cloudevents/sdk-go/v2 - CloudEvents SDK
  • github.com/google/uuid - UUID generation
  • google.golang.org/grpc - gRPC communication
  • google.golang.org/protobuf - Protocol buffer support

License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChipIngressClient

type ChipIngressClient = pb.ChipIngressClient

Client

type ChipIngress_StreamEventsClient

type ChipIngress_StreamEventsClient = pb.ChipIngress_StreamEventsClient

type Client

type Client interface {
	pb.ChipIngressClient
	Close() error
}

func NewClient

func NewClient(address string, opts ...Opt) (Client, error)

NewClient creates a new client for the Chip Ingress service with optional configuration.

type CloudEvent

type CloudEvent = ce.Event

Cloudevents types

func NewEvent

func NewEvent(domain, entity string, payload []byte, attributes map[string]any) (CloudEvent, error)

NewEvent creates a new CloudEvent with the specified domain, entity, payload, and optional attributes.

func ProtoToEvent

func ProtoToEvent(eventPb *CloudEventPb) (CloudEvent, error)

type CloudEventBatch

type CloudEventBatch = pb.CloudEventBatch

Message types

func EventsToBatch

func EventsToBatch(events []CloudEvent) (*CloudEventBatch, error)

type CloudEventPb

type CloudEventPb = cepb.CloudEvent

func EventToProto

func EventToProto(event CloudEvent) (*CloudEventPb, error)

type EmptyRequest

type EmptyRequest = pb.EmptyRequest

type HeaderProvider

type HeaderProvider interface {
	GetHeaders() map[string]string
}

HeaderProvider defines an interface for providing headers

type Opt

type Opt func(*clientConfig)

Opt defines a function type for configuring the ChipIngressClient.

func WithBasicAuth

func WithBasicAuth(user, pass string) Opt

WithBasicAuth sets the basic-auth credentials for the ChipIngress service. Default is to require TLS for security.

func WithHeaderProvider

func WithHeaderProvider(provider HeaderProvider) Opt

WithHeaderProvider sets a dynamic header provider for requests NOTE: for CSA-Key based authentication, use WithTokenAuth instead.

func WithInsecureConnection

func WithInsecureConnection() Opt

WithInsecureConnection configures the client to use an insecure connection (no TLS).

func WithTLS

func WithTLS() Opt

Add a new option function for TLS with HTTP/2

func WithTokenAuth

func WithTokenAuth(tokenProvider HeaderProvider) Opt

WithTokenAuth sets the token-based credentials for the ChipIngress service. Use for CSA-Key based authentication.

func WithTransportCredentials

func WithTransportCredentials(creds credentials.TransportCredentials) Opt

WithTransportCredentials sets the transport custom credentials for the ChipIngress service.

type PingResponse

type PingResponse = pb.PingResponse

type PublishResponse

type PublishResponse = pb.PublishResponse

type PublishResult

type PublishResult = pb.PublishResult

type StreamEventsRequest

type StreamEventsRequest = pb.StreamEventsRequest

type StreamEventsResponse

type StreamEventsResponse = pb.StreamEventsResponse

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL