mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 23:02:52 +01:00
parent
369d703050
commit
86b1e3cde7
@ -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
32
sdk/dialer.go
Normal 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
37
sdk/listener.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user