github.com/argoproj/argo-events@v1.9.1/eventsources/sources/github/types.go (about)

     1  /*
     2  
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  
     7  	http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    15  
    16  package github
    17  
    18  import (
    19  	"net/http"
    20  
    21  	"github.com/google/go-github/v50/github"
    22  
    23  	"github.com/argoproj/argo-events/eventsources/common/webhook"
    24  	"github.com/argoproj/argo-events/metrics"
    25  	apicommon "github.com/argoproj/argo-events/pkg/apis/common"
    26  	"github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1"
    27  )
    28  
    29  // EventListener implements Eventing for GitHub event source
    30  type EventListener struct {
    31  	EventSourceName   string
    32  	EventName         string
    33  	GithubEventSource v1alpha1.GithubEventSource
    34  	Metrics           *metrics.Metrics
    35  }
    36  
    37  // GetEventSourceName returns name of event source
    38  func (el *EventListener) GetEventSourceName() string {
    39  	return el.EventSourceName
    40  }
    41  
    42  // GetEventName returns name of event
    43  func (el *EventListener) GetEventName() string {
    44  	return el.EventName
    45  }
    46  
    47  // GetEventSourceType return type of event server
    48  func (el *EventListener) GetEventSourceType() apicommon.EventSourceType {
    49  	return apicommon.GithubEvent
    50  }
    51  
    52  // Router contains information about the route
    53  type Router struct {
    54  	// route contains configuration for an API endpoint
    55  	route *webhook.Route
    56  	// githubEventSource is the event source that holds information to consume events from GitHub
    57  	githubEventSource *v1alpha1.GithubEventSource
    58  	// githubClient is the client to connect to GitHub
    59  	githubClient *github.Client
    60  	// (owner + "," + repo name) -> hook ID
    61  	repoHookIDs map[string]int64
    62  	// org name -> hook ID
    63  	orgHookIDs map[string]int64
    64  	// hookSecret is a GitHub webhook secret
    65  	hookSecret string
    66  }
    67  
    68  // cred stores the api access token or webhook secret
    69  type cred struct {
    70  	secret string
    71  }
    72  
    73  // AuthStrategy is implemented by the different GitHub auth strategies that are supported
    74  type AuthStrategy interface {
    75  	// AuthTransport returns an http.RoundTripper that is used with an http.Client to make
    76  	// authenticated requests using HTTP Basic Authentication.
    77  	AuthTransport() (http.RoundTripper, error)
    78  }