Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract generates wrappers for internal package methods for github.com/google/s2a-go #1664

Open
phanvanpeterbloomreach opened this issue Oct 15, 2024 · 0 comments

Comments

@phanvanpeterbloomreach
Copy link

phanvanpeterbloomreach commented Oct 15, 2024

Extract generates wrappers for internal package methods for github.com/google/s2a-go

The yaegi extract is generating wrappers for internal package methods, which violates the Go language's package visibility rules. This happens when extracting github.com/google/s2a-go package.

package main

func main() {
	if err := extractSymbols(); err != nil {
		log.Fatalln(err)
	}
}

func extractSymbols() error {
	wd, err := os.Getwd()
	if err != nil {
		return err
	}

	name := filepath.Base(wd)
	ext := extract.Extractor{
		Dest: name,
	}
	var buf bytes.Buffer
	importPath, err := ext.Extract("github.com/google/s2a-go", name, &buf)
	if err != nil {
		return err
	}

	r := strings.NewReplacer("/", "-", ".", "_", "~", "_")
	oFile := r.Replace(importPath) + ".go"
	f, err := os.Create(oFile)
	if err != nil {
		return err
	}

	if _, err := io.Copy(f, &buf); err != nil {
		_ = f.Close()
		return err
	}

	if err := f.Close(); err != nil {
		return err
	}

	return nil
}

Expected generated file

// Code generated by 'yaegi extract github.com/google/s2a-go'. DO NOT EDIT.

package yaegi_experiment

import (
	"context"
	"crypto/tls"
	"github.com/google/s2a-go"
	"google.golang.org/grpc/credentials"
	"reflect"
)

func init() {
	Symbols["github.com/google/s2a-go/s2a"] = map[string]reflect.Value{
		// function, constant and variable definitions
		"AuthInfoFromContext":             reflect.ValueOf(s2a.AuthInfoFromContext),
		"AuthInfoFromPeer":                reflect.ValueOf(s2a.AuthInfoFromPeer),
		"ConnectToGoogle":                 reflect.ValueOf(s2a.ConnectToGoogle),
		"DefaultClientOptions":            reflect.ValueOf(s2a.DefaultClientOptions),
		"DefaultServerOptions":            reflect.ValueOf(s2a.DefaultServerOptions),
		"NewClientCreds":                  reflect.ValueOf(s2a.NewClientCreds),
		"NewHostname":                     reflect.ValueOf(s2a.NewHostname),
		"NewS2ADialTLSContextFunc":        reflect.ValueOf(s2a.NewS2ADialTLSContextFunc),
		"NewServerCreds":                  reflect.ValueOf(s2a.NewServerCreds),
		"NewSpiffeID":                     reflect.ValueOf(s2a.NewSpiffeID),
		"NewTLSClientConfigFactory":       reflect.ValueOf(s2a.NewTLSClientConfigFactory),
		"NewUID":                          reflect.ValueOf(s2a.NewUID),
		"ReservedCustomVerificationMode3": reflect.ValueOf(s2a.ReservedCustomVerificationMode3),
		"ReservedCustomVerificationMode4": reflect.ValueOf(s2a.ReservedCustomVerificationMode4),
		"ReservedCustomVerificationMode5": reflect.ValueOf(s2a.ReservedCustomVerificationMode5),
		"Spiffe":                          reflect.ValueOf(s2a.Spiffe),
		"Unspecified":                     reflect.ValueOf(s2a.Unspecified),

		// type definitions
		"AuthInfo":               reflect.ValueOf((*s2a.AuthInfo)(nil)),
		"ClientOptions":          reflect.ValueOf((*s2a.ClientOptions)(nil)),
		"FallbackDialer":         reflect.ValueOf((*s2a.FallbackDialer)(nil)),
		"FallbackOptions":        reflect.ValueOf((*s2a.FallbackOptions)(nil)),
		"Identity":               reflect.ValueOf((*s2a.Identity)(nil)),
		"ServerOptions":          reflect.ValueOf((*s2a.ServerOptions)(nil)),
		"TLSClientConfigFactory": reflect.ValueOf((*s2a.TLSClientConfigFactory)(nil)),
		"TLSClientConfigOptions": reflect.ValueOf((*s2a.TLSClientConfigOptions)(nil)),
		"VerificationModeType":   reflect.ValueOf((*s2a.VerificationModeType)(nil)),

		// interface wrapper definitions
		"_AuthInfo":               reflect.ValueOf((*_github_com_google_s2a_go_AuthInfo)(nil)),
		"_Identity":               reflect.ValueOf((*_github_com_google_s2a_go_Identity)(nil)),
		"_TLSClientConfigFactory": reflect.ValueOf((*_github_com_google_s2a_go_TLSClientConfigFactory)(nil)),
	}
}

// _github_com_google_s2a_go_AuthInfo is an interface wrapper for AuthInfo type
type _github_com_google_s2a_go_AuthInfo struct {
	IValue                interface{}
	WApplicationProtocol  func() string
	WAuthType             func() string
	WIsHandshakeResumed   func() bool
	WLocalCertFingerprint func() []byte
	WPeerCertFingerprint  func() []byte
	WSecurityLevel        func() credentials.SecurityLevel
}

func (W _github_com_google_s2a_go_AuthInfo) ApplicationProtocol() string {
	return W.WApplicationProtocol()
}
func (W _github_com_google_s2a_go_AuthInfo) AuthType() string {
	return W.WAuthType()
}
func (W _github_com_google_s2a_go_AuthInfo) IsHandshakeResumed() bool {
	return W.WIsHandshakeResumed()
}
func (W _github_com_google_s2a_go_AuthInfo) LocalCertFingerprint() []byte {
	return W.WLocalCertFingerprint()
}
func (W _github_com_google_s2a_go_AuthInfo) PeerCertFingerprint() []byte {
	return W.WPeerCertFingerprint()
}
func (W _github_com_google_s2a_go_AuthInfo) SecurityLevel() credentials.SecurityLevel {
	return W.WSecurityLevel()
}

// _github_com_google_s2a_go_Identity is an interface wrapper for Identity type
type _github_com_google_s2a_go_Identity struct {
	IValue interface{}
	WName  func() string
}

func (W _github_com_google_s2a_go_Identity) Name() string {
	return W.WName()
}

// _github_com_google_s2a_go_TLSClientConfigFactory is an interface wrapper for TLSClientConfigFactory type
type _github_com_google_s2a_go_TLSClientConfigFactory struct {
	IValue interface{}
	WBuild func(ctx context.Context, opts *s2a.TLSClientConfigOptions) (*tls.Config, error)
}

func (W _github_com_google_s2a_go_TLSClientConfigFactory) Build(ctx context.Context, opts *s2a.TLSClientConfigOptions) (*tls.Config, error) {
	return W.WBuild(ctx, opts)
}

Actual generated file

// Code generated by 'yaegi extract github.com/google/s2a-go'. DO NOT EDIT.

package yaegi_experiment2

import (
	"context"
	"crypto/tls"
	"github.com/google/s2a-go"
	"github.com/google/s2a-go/internal/proto/common_go_proto"
	"google.golang.org/grpc/credentials"
	"reflect"
)

func init() {
	Symbols["github.com/google/s2a-go/s2a"] = map[string]reflect.Value{
		// function, constant and variable definitions
		"AuthInfoFromContext":             reflect.ValueOf(s2a.AuthInfoFromContext),
		"AuthInfoFromPeer":                reflect.ValueOf(s2a.AuthInfoFromPeer),
		"ConnectToGoogle":                 reflect.ValueOf(s2a.ConnectToGoogle),
		"DefaultClientOptions":            reflect.ValueOf(s2a.DefaultClientOptions),
		"DefaultServerOptions":            reflect.ValueOf(s2a.DefaultServerOptions),
		"NewClientCreds":                  reflect.ValueOf(s2a.NewClientCreds),
		"NewHostname":                     reflect.ValueOf(s2a.NewHostname),
		"NewS2ADialTLSContextFunc":        reflect.ValueOf(s2a.NewS2ADialTLSContextFunc),
		"NewServerCreds":                  reflect.ValueOf(s2a.NewServerCreds),
		"NewSpiffeID":                     reflect.ValueOf(s2a.NewSpiffeID),
		"NewTLSClientConfigFactory":       reflect.ValueOf(s2a.NewTLSClientConfigFactory),
		"NewUID":                          reflect.ValueOf(s2a.NewUID),
		"ReservedCustomVerificationMode3": reflect.ValueOf(s2a.ReservedCustomVerificationMode3),
		"ReservedCustomVerificationMode4": reflect.ValueOf(s2a.ReservedCustomVerificationMode4),
		"ReservedCustomVerificationMode5": reflect.ValueOf(s2a.ReservedCustomVerificationMode5),
		"Spiffe":                          reflect.ValueOf(s2a.Spiffe),
		"Unspecified":                     reflect.ValueOf(s2a.Unspecified),

		// type definitions
		"AuthInfo":               reflect.ValueOf((*s2a.AuthInfo)(nil)),
		"ClientOptions":          reflect.ValueOf((*s2a.ClientOptions)(nil)),
		"FallbackDialer":         reflect.ValueOf((*s2a.FallbackDialer)(nil)),
		"FallbackOptions":        reflect.ValueOf((*s2a.FallbackOptions)(nil)),
		"Identity":               reflect.ValueOf((*s2a.Identity)(nil)),
		"ServerOptions":          reflect.ValueOf((*s2a.ServerOptions)(nil)),
		"TLSClientConfigFactory": reflect.ValueOf((*s2a.TLSClientConfigFactory)(nil)),
		"TLSClientConfigOptions": reflect.ValueOf((*s2a.TLSClientConfigOptions)(nil)),
		"VerificationModeType":   reflect.ValueOf((*s2a.VerificationModeType)(nil)),

		// interface wrapper definitions
		"_AuthInfo":               reflect.ValueOf((*_github_com_google_s2a_go_AuthInfo)(nil)),
		"_Identity":               reflect.ValueOf((*_github_com_google_s2a_go_Identity)(nil)),
		"_TLSClientConfigFactory": reflect.ValueOf((*_github_com_google_s2a_go_TLSClientConfigFactory)(nil)),
	}
}

// _github_com_google_s2a_go_AuthInfo is an interface wrapper for AuthInfo type
type _github_com_google_s2a_go_AuthInfo struct {
	IValue                interface{}
	WApplicationProtocol  func() string
	WAuthType             func() string
	WCiphersuite          func() common_go_proto.Ciphersuite
	WIsHandshakeResumed   func() bool
	WLocalCertFingerprint func() []byte
	WLocalIdentity        func() *common_go_proto.Identity
	WPeerCertFingerprint  func() []byte
	WPeerIdentity         func() *common_go_proto.Identity
	WSecurityLevel        func() credentials.SecurityLevel
	WTLSVersion           func() common_go_proto.TLSVersion
}

func (W _github_com_google_s2a_go_AuthInfo) ApplicationProtocol() string {
	return W.WApplicationProtocol()
}
func (W _github_com_google_s2a_go_AuthInfo) AuthType() string {
	return W.WAuthType()
}
func (W _github_com_google_s2a_go_AuthInfo) Ciphersuite() common_go_proto.Ciphersuite {
	return W.WCiphersuite()
}
func (W _github_com_google_s2a_go_AuthInfo) IsHandshakeResumed() bool {
	return W.WIsHandshakeResumed()
}
func (W _github_com_google_s2a_go_AuthInfo) LocalCertFingerprint() []byte {
	return W.WLocalCertFingerprint()
}
func (W _github_com_google_s2a_go_AuthInfo) LocalIdentity() *common_go_proto.Identity {
	return W.WLocalIdentity()
}
func (W _github_com_google_s2a_go_AuthInfo) PeerCertFingerprint() []byte {
	return W.WPeerCertFingerprint()
}
func (W _github_com_google_s2a_go_AuthInfo) PeerIdentity() *common_go_proto.Identity {
	return W.WPeerIdentity()
}
func (W _github_com_google_s2a_go_AuthInfo) SecurityLevel() credentials.SecurityLevel {
	return W.WSecurityLevel()
}
func (W _github_com_google_s2a_go_AuthInfo) TLSVersion() common_go_proto.TLSVersion {
	return W.WTLSVersion()
}

// _github_com_google_s2a_go_Identity is an interface wrapper for Identity type
type _github_com_google_s2a_go_Identity struct {
	IValue interface{}
	WName  func() string
}

func (W _github_com_google_s2a_go_Identity) Name() string {
	return W.WName()
}

// _github_com_google_s2a_go_TLSClientConfigFactory is an interface wrapper for TLSClientConfigFactory type
type _github_com_google_s2a_go_TLSClientConfigFactory struct {
	IValue interface{}
	WBuild func(ctx context.Context, opts *s2a.TLSClientConfigOptions) (*tls.Config, error)
}

func (W _github_com_google_s2a_go_TLSClientConfigFactory) Build(ctx context.Context, opts *s2a.TLSClientConfigOptions) (*tls.Config, error) {
	return W.WBuild(ctx, opts)
}

Yaegi Version

v0.16.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant