diff --git a/sdk/access.go b/sdk/access.go index 15e42d4d..c759c13b 100644 --- a/sdk/access.go +++ b/sdk/access.go @@ -12,7 +12,7 @@ func CreateAccess(root env_core.Root, request *AccessRequest) (*Access, error) { out := share.NewAccessParams() out.Body = &rest_model_zrok.AccessRequest{ ShrToken: request.ShareToken, - EnvZID: root.Environment().Token, + EnvZID: root.Environment().ZitiIdentity, } zrok, err := root.Client() diff --git a/sdk/dialer.go b/sdk/dialer.go new file mode 100644 index 00000000..2283ea6c --- /dev/null +++ b/sdk/dialer.go @@ -0,0 +1,32 @@ +package sdk + +import ( + "github.com/openziti/sdk-golang/ziti" + "github.com/openziti/sdk-golang/ziti/edge" + "github.com/openziti/zrok/environment/env_core" + "github.com/pkg/errors" +) + +func NewDialer(shrToken string, root env_core.Root) (edge.Conn, error) { + zif, err := root.ZitiIdentityNamed(root.EnvironmentIdentityName()) + if err != nil { + return nil, errors.Wrap(err, "error getting ziti identity path") + } + + zcfg, err := ziti.NewConfigFromFile(zif) + if err != nil { + return nil, errors.Wrap(err, "error loading ziti identity") + } + + zctx, err := ziti.NewContext(zcfg) + if err != nil { + return nil, errors.Wrap(err, "error getting ziti context") + } + + conn, err := zctx.Dial(shrToken) + if err != nil { + return nil, errors.Wrapf(err, "error dialing '%v'", shrToken) + } + + return conn, nil +} diff --git a/sdk/listener.go b/sdk/listener.go new file mode 100644 index 00000000..4aece922 --- /dev/null +++ b/sdk/listener.go @@ -0,0 +1,37 @@ +package sdk + +import ( + "github.com/openziti/sdk-golang/ziti" + "github.com/openziti/sdk-golang/ziti/edge" + "github.com/openziti/zrok/environment/env_core" + "github.com/pkg/errors" + "time" +) + +func NewListener(shrToken string, root env_core.Root) (edge.Listener, error) { + return NewListenerWithOptions(shrToken, root, &ziti.ListenOptions{ConnectTimeout: 30 * time.Second, MaxConnections: 64}) +} + +func NewListenerWithOptions(shrToken string, root env_core.Root, opts *ziti.ListenOptions) (edge.Listener, error) { + zif, err := root.ZitiIdentityNamed(root.EnvironmentIdentityName()) + if err != nil { + return nil, errors.Wrap(err, "error getting ziti identity path") + } + + zcfg, err := ziti.NewConfigFromFile(zif) + if err != nil { + return nil, errors.Wrap(err, "error loading ziti identity") + } + + zctx, err := ziti.NewContext(zcfg) + if err != nil { + return nil, errors.Wrap(err, "error getting ziti context") + } + + listener, err := zctx.ListenWithOptions(shrToken, opts) + if err != nil { + return nil, errors.Wrap(err, "error creating listener") + } + + return listener, nil +}