github.com/argoproj/argo-events@v1.9.1/eventsources/sources/bitbucket/oauth_token_auth_strategy.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 bitbucket 17 18 import ( 19 "fmt" 20 21 bitbucketv2 "github.com/ktrysmt/go-bitbucket" 22 corev1 "k8s.io/api/core/v1" 23 24 "github.com/argoproj/argo-events/common" 25 ) 26 27 type OAuthTokenAuthStrategy struct { 28 token string 29 } 30 31 func NewOAuthTokenAuthStrategy(oauthTokenSecret *corev1.SecretKeySelector) (*OAuthTokenAuthStrategy, error) { 32 token, err := common.GetSecretFromVolume(oauthTokenSecret) 33 if err != nil { 34 return nil, fmt.Errorf("failed to retrieve bitbucket oauth token from secret, %w", err) 35 } 36 37 return &OAuthTokenAuthStrategy{ 38 token: token, 39 }, nil 40 } 41 42 // BitbucketClient implements the AuthStrategy interface. 43 func (as *OAuthTokenAuthStrategy) BitbucketClient() *bitbucketv2.Client { 44 return bitbucketv2.NewOAuthbearerToken(as.token) 45 }