github.com/reviewdog/reviewdog@v0.17.5-0.20240516205324-0cd103a83d58/service/bitbucket/cloud_api_context.go (about) 1 package bitbucket 2 3 import ( 4 "context" 5 6 bbapi "github.com/reviewdog/go-bitbucket" 7 ) 8 9 // BuildCloudAPIContext builds context.Context used to call Bitbucket Cloud Code Insights API 10 func BuildCloudAPIContext(ctx context.Context, user, password, token string) context.Context { 11 if user != "" && password != "" { 12 ctx = withBasicAuth(ctx, user, password) 13 } 14 15 if token != "" { 16 ctx = withAccessToken(ctx, token) 17 } 18 19 return ctx 20 } 21 22 // WithBasicAuth adds basic auth credentials to context 23 func withBasicAuth(ctx context.Context, username, password string) context.Context { 24 return context.WithValue(ctx, bbapi.ContextBasicAuth, 25 bbapi.BasicAuth{ 26 UserName: username, 27 Password: password, 28 }) 29 } 30 31 // WithAccessToken adds basic auth credentials to context 32 func withAccessToken(ctx context.Context, accessToken string) context.Context { 33 return context.WithValue(ctx, bbapi.ContextAccessToken, accessToken) 34 }