Skip to content

Commit

Permalink
feat: GenericEventSource to support authentication. Closes argoproj#928
Browse files Browse the repository at this point in the history
… (argoproj#935)

Signed-off-by: Derek Wang <whynowy@gmail.com>
  • Loading branch information
whynowy authored Dec 21, 2020
1 parent c742f19 commit 7c09b97
Show file tree
Hide file tree
Showing 9 changed files with 444 additions and 325 deletions.
14 changes: 14 additions & 0 deletions api/event-source.html

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

14 changes: 14 additions & 0 deletions api/event-source.md

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

4 changes: 4 additions & 0 deletions api/openapi-spec/swagger.json

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

21 changes: 17 additions & 4 deletions eventsources/sources/generic/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ package generic
import (
"context"
"encoding/json"
fmt "fmt"
"time"

"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/metadata"

"github.com/argoproj/argo-events/common"
"github.com/argoproj/argo-events/common/logging"
"github.com/argoproj/argo-events/eventsources/sources"
apicommon "github.com/argoproj/argo-events/pkg/apis/common"
"github.com/argoproj/argo-events/pkg/apis/events"
"github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
)

// EventListener implements Eventing for generic event source
Expand Down Expand Up @@ -110,7 +114,16 @@ func (el *EventListener) connect() (Eventing_StartEventSourceClient, error) {
}
el.conn = conn
client := NewEventingClient(el.conn)
return client.StartEventSource(context.Background(), &EventSource{
ctx := context.Background()
if el.GenericEventSource.AuthSecret != nil {
token, err := common.GetSecretFromVolume(el.GenericEventSource.AuthSecret)
if err != nil {
return nil, err
}
auth := fmt.Sprintf("Bearer %s", token)
ctx = metadata.NewOutgoingContext(ctx, metadata.Pairs("authorization", auth))
}
return client.StartEventSource(ctx, &EventSource{
Name: el.GetEventName(),
Config: []byte(el.GenericEventSource.Config),
})
Expand Down
696 changes: 375 additions & 321 deletions pkg/apis/eventsource/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pkg/apis/eventsource/v1alpha1/generated.proto

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

8 changes: 8 additions & 0 deletions pkg/apis/eventsource/v1alpha1/openapi_generated.go

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

3 changes: 3 additions & 0 deletions pkg/apis/eventsource/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,9 @@ type GenericEventSource struct {
// Metadata holds the user defined metadata which will passed along the event payload.
// +optional
Metadata map[string]string `json:"metadata,omitempty" protobuf:"bytes,5,rep,name=metadata"`
// AuthSecret holds a secret selector that contains a bearer token for authentication
// +optional
AuthSecret *corev1.SecretKeySelector `json:"authSecret,omitempty" protobuf:"bytes,6,opt,name=authSecret"`
}

const (
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/eventsource/v1alpha1/zz_generated.deepcopy.go

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

0 comments on commit 7c09b97

Please sign in to comment.