-
Notifications
You must be signed in to change notification settings - Fork 3
/
grpc.go
30 lines (24 loc) · 900 Bytes
/
grpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package registryproxy
import (
"context"
"fmt"
dockerregistryproxyv1 "github.com/VJftw/docker-registry-proxy/api/proto/v1"
"github.com/google/go-containerregistry/pkg/authn"
"go.uber.org/zap"
)
// RegistryAuthResolveGRPC resolves the registry authentication from via GRPC
func RegistryAuthResolveGRPC(client dockerregistryproxyv1.AuthenticationProviderAPIClient) (authn.Authenticator, error) {
resp, err := client.Provide(context.Background(), &dockerregistryproxyv1.ProvideRequest{})
if err != nil {
return nil, err
}
cfg := authn.AuthConfig{
Username: resp.GetUsername(),
Password: resp.GetPassword(),
Auth: resp.GetAuth(),
IdentityToken: resp.GetIdentityToken(),
RegistryToken: resp.GetRegistryToken(),
}
logger.Info("received credentials from auth provider", zap.String("credentials", fmt.Sprintf("%#v", cfg)))
return authn.FromConfig(cfg), nil
}