sdk.CreateAccess fix; sdk.NewListener; sdk.NewDialer (#34, #379)

This commit is contained in:
Michael Quigley 2023-07-26 16:19:16 -04:00
parent 369d703050
commit 86b1e3cde7
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 70 additions and 1 deletions

View File

@ -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()

32
sdk/dialer.go Normal file
View File

@ -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
}

37
sdk/listener.go Normal file
View File

@ -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
}