2018-04-18 19:36:26 -04:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/moby/buildkit/session"
|
2019-09-20 20:42:32 -04:00
|
|
|
"github.com/pkg/errors"
|
2018-04-18 19:36:26 -04:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
|
|
|
func CredentialsFunc(ctx context.Context, c session.Caller) func(string) (string, string, error) {
|
|
|
|
return func(host string) (string, string, error) {
|
|
|
|
client := NewAuthClient(c.Conn())
|
|
|
|
|
|
|
|
resp, err := client.Credentials(ctx, &CredentialsRequest{
|
|
|
|
Host: host,
|
|
|
|
})
|
|
|
|
if err != nil {
|
2019-09-20 20:42:32 -04:00
|
|
|
if st, ok := status.FromError(errors.Cause(err)); ok && st.Code() == codes.Unimplemented {
|
2018-04-18 19:36:26 -04:00
|
|
|
return "", "", nil
|
|
|
|
}
|
2019-09-20 20:42:32 -04:00
|
|
|
return "", "", errors.WithStack(err)
|
2018-04-18 19:36:26 -04:00
|
|
|
}
|
|
|
|
return resp.Username, resp.Secret, nil
|
|
|
|
}
|
|
|
|
}
|