github.com/argoproj/argo-events@v1.9.1/eventsources/sources/github/appauth.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 http://www.apache.org/licenses/LICENSE-2.0 7 Unless required by applicable law or agreed to in writing, software 8 distributed under the License is distributed on an "AS IS" BASIS, 9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 See the License for the specific language governing permissions and 11 limitations under the License. 12 */ 13 14 package github 15 16 import ( 17 "net/http" 18 19 "github.com/bradleyfalzon/ghinstallation/v2" 20 ) 21 22 type AppsAuthStrategy struct { 23 AppID int64 24 BaseURL string 25 InstallationID int64 26 PrivateKey string 27 Transport http.RoundTripper 28 } 29 30 // AuthTransport implements the AuthStrategy interface. 31 func (t *AppsAuthStrategy) AuthTransport() (http.RoundTripper, error) { 32 appTransport, err := ghinstallation.New(t.transport(), t.AppID, t.InstallationID, []byte(t.PrivateKey)) 33 if appTransport != nil && t.BaseURL != "" { 34 appTransport.BaseURL = t.BaseURL 35 } 36 return appTransport, err 37 } 38 39 func (t *AppsAuthStrategy) transport() http.RoundTripper { 40 if t.Transport != nil { 41 return t.Transport 42 } 43 44 return http.DefaultTransport 45 }