Skip to content

Commit

Permalink
feat(source): salesforce
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Apr 17, 2024
1 parent ea20fd7 commit f630e71
Show file tree
Hide file tree
Showing 32 changed files with 2,769 additions and 3 deletions.
42 changes: 41 additions & 1 deletion example/values-aks-nats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,52 @@ config:
pvc:
size: 10Gi

gateway:
enabled: true
merge:
gateways:
- name: typhoon-gw-west-nats
urls:
- nats://gwp:[email protected]:7222
- name: typhoon-gw-central-nats
urls:
- nats://gwp:[email protected]:7222
authorization:
user: gwp
password: gwp

merge:
accounts:
$SYS:
jetstream: true
users:
- user: sys
password: pass

natsBox:
contexts:
sys:
merge: { user: sys, password: pass }
defaultContextName: sys

podTemplate:
topologySpreadConstraints:
kubernetes.io/hostname:
maxSkew: 1
whenUnsatisfiable: DoNotSchedule

service:
ports:
gateway:
enabled: true
merge:
metadata:
annotations:
service.beta.kubernetes.io/azure-load-balancer-ipv4: ""
service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
type: LoadBalancer

container:
env:
# different from k8s units, suffix must be B, KiB, MiB, GiB, or TiB
Expand All @@ -27,4 +67,4 @@ container:
memory: 8Gi
limits:
cpu: "2"
memory: 8Gi
memory: 8Gi
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/getkin/kin-openapi v0.123.0
github.com/gofiber/fiber/v2 v2.52.1
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang/mock v1.7.0-rc.1
github.com/golangci/golangci-lint v1.56.2
github.com/google/cel-go v0.17.7
Expand All @@ -32,6 +33,7 @@ require (
go.opencensus.io v0.24.0
go.uber.org/zap v1.26.0
golang.org/x/mod v0.15.0
golang.org/x/net v0.21.0
golang.org/x/oauth2 v0.17.0
google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014
google.golang.org/protobuf v1.33.0
Expand All @@ -41,6 +43,7 @@ require (
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
knative.dev/eventing v0.31.1-0.20220523181303-c3e13967001f
knative.dev/networking v0.0.0-20240220074405-630e71a2dbc7
knative.dev/pkg v0.0.0-20240219120257-9227ebb57a4e
Expand Down Expand Up @@ -299,7 +302,6 @@ require (
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
golang.org/x/exp/typeparams v0.0.0-20231219180239-dc181d75b848 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
Expand All @@ -320,7 +322,6 @@ require (
k8s.io/helm v2.17.0+incompatible // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed // indirect
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect
mvdan.cc/unparam v0.0.0-20240104100049-c549a3470d14 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/sources/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var AllTypes = []v1alpha1.GroupObject{
{Single: &HTTPPollerSource{}, List: &HTTPPollerSourceList{}},
{Single: &OCIMetricsSource{}, List: &OCIMetricsSourceList{}},
{Single: &WebhookSource{}, List: &WebhookSourceList{}},
{Single: &SalesforceSource{}, List: &SalesforceSourceList{}},
}

// addKnownTypes adds all this custom API's types to Scheme.
Expand Down
68 changes: 68 additions & 0 deletions pkg/apis/sources/v1alpha1/salesforce_lifecycle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package v1alpha1

import (
"context"

"k8s.io/apimachinery/pkg/runtime/schema"

"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"

"github.com/zeiss/typhoon/pkg/apis/common/v1alpha1"
)

// GetGroupVersionKind implements kmeta.OwnerRefable.
func (s *SalesforceSource) GetGroupVersionKind() schema.GroupVersionKind {
return SchemeGroupVersion.WithKind("SalesforceSource")
}

// GetConditionSet implements duckv1.KRShaped.
func (s *SalesforceSource) GetConditionSet() apis.ConditionSet {
return v1alpha1.EventSenderConditionSet
}

// GetStatus implements duckv1.KRShaped.
func (s *SalesforceSource) GetStatus() *duckv1.Status {
return &s.Status.Status
}

// GetSink implements EventSender.
func (s *SalesforceSource) GetSink() *duckv1.Destination {
return &s.Spec.Sink
}

// GetStatusManager implements Reconcilable.
func (s *SalesforceSource) GetStatusManager() *v1alpha1.StatusManager {
return &v1alpha1.StatusManager{
ConditionSet: s.GetConditionSet(),
Status: &s.Status,
}
}

// AsEventSource implements EventSource.
func (s *SalesforceSource) AsEventSource() string {
channel := s.Spec.Subscription.Channel
if channel[0] != '/' {
channel = "/" + channel
}
return "com.zeiss.typhoon.salesforce" + channel
}

// GetEventTypes returns the event types generated by the source.
func (s *SalesforceSource) GetEventTypes() []string {
return []string{"com.salesforce.stream.message"}
}

// GetAdapterOverrides implements AdapterConfigurable.
func (s *SalesforceSource) GetAdapterOverrides() *v1alpha1.AdapterOverrides {
return s.Spec.AdapterOverrides
}

// SetDefaults implements apis.Defaultable
func (s *SalesforceSource) SetDefaults(ctx context.Context) {
}

// Validate implements apis.Validatable
func (s *SalesforceSource) Validate(ctx context.Context) *apis.FieldError {
return nil
}
71 changes: 71 additions & 0 deletions pkg/apis/sources/v1alpha1/salesforce_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"

"github.com/zeiss/typhoon/pkg/apis/common/v1alpha1"
)

// +genclient
// +genreconciler
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// SalesforceSource is the Schema for the event source.
type SalesforceSource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SalesforceSourceSpec `json:"spec,omitempty"`
Status v1alpha1.Status `json:"status,omitempty"`
}

// Check the interfaces the event source should be implementing.
var (
_ v1alpha1.Reconcilable = (*SalesforceSource)(nil)
_ v1alpha1.AdapterConfigurable = (*SalesforceSource)(nil)
_ v1alpha1.EventSource = (*SalesforceSource)(nil)
_ v1alpha1.EventSender = (*SalesforceSource)(nil)
)

// SalesforceSourceSpec defines the desired state of the event source.
type SalesforceSourceSpec struct {
duckv1.SourceSpec `json:",inline"`

// Authentication method to interact with the Salesforce API.
Auth SalesforceAuth `json:"auth"`

// APIVersion at Salesforce.
// +optional
APIVersion *string `json:"apiVersion"`

// Subscription to a Salesforce channel
Subscription SalesforceSubscription `json:"subscription"`

// Adapter spec overrides parameters.
// +optional
AdapterOverrides *v1alpha1.AdapterOverrides `json:"adapterOverrides,omitempty"`
}

// SalesforceSubscription to connect to.
type SalesforceSubscription struct {
Channel string `json:"channel"`
ReplayID *int `json:"replayID,omitempty"`
}

// SalesforceAuth contains Salesforce credentials.
type SalesforceAuth struct {
ClientID string `json:"clientID"`
Server string `json:"server"`
User string `json:"user"`
CertKey v1alpha1.ValueFromField `json:"certKey"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// SalesforceSourceList contains a list of event sources.
type SalesforceSourceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []SalesforceSource `json:"items"`
}
128 changes: 128 additions & 0 deletions pkg/apis/sources/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit f630e71

Please sign in to comment.