github.com/adevinta/maiao@v0.0.0-20240318133227-b6f9656b5e07/pkg/credentials/auth_method.go (about)

     1  package credentials
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/adevinta/maiao/pkg/log"
     7  )
     8  
     9  type GitAuth struct {
    10  	Credentials CredentialGetter
    11  }
    12  
    13  func (a *GitAuth) SetAuth(r *http.Request) {
    14  	creds, err := a.Credentials.CredentialForHost(r.Host)
    15  	if err != nil || creds == nil {
    16  		log.Logger.WithField("host", r.Host).WithError(err).Infof("failed to find credentials")
    17  		return
    18  	}
    19  	r.SetBasicAuth(creds.Username, creds.Password)
    20  }
    21  
    22  func (a *GitAuth) Name() string {
    23  	return "auth from credentials"
    24  }
    25  
    26  func (a *GitAuth) String() string {
    27  	return "auth from credentials"
    28  }