github.com/argoproj/argo-events@v1.9.1/eventsources/sources/bitbucket/basic_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 BasicAuthStrategy struct {
    28  	username string
    29  	password string
    30  }
    31  
    32  func NewBasicAuthStrategy(usernameSecret, passwordSecret *corev1.SecretKeySelector) (*BasicAuthStrategy, error) {
    33  	username, err := common.GetSecretFromVolume(usernameSecret)
    34  	if err != nil {
    35  		return nil, fmt.Errorf("failed to retrieve bitbucket username from secret, %w", err)
    36  	}
    37  
    38  	password, err := common.GetSecretFromVolume(passwordSecret)
    39  	if err != nil {
    40  		return nil, fmt.Errorf("failed to retrieve bitbucket password from secret, %w", err)
    41  	}
    42  
    43  	return &BasicAuthStrategy{
    44  		username: username,
    45  		password: password,
    46  	}, nil
    47  }
    48  
    49  // BitbucketClient implements the AuthStrategy interface.
    50  func (as *BasicAuthStrategy) BitbucketClient() *bitbucketv2.Client {
    51  	return bitbucketv2.NewBasicAuth(as.username, as.password)
    52  }