mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 08:03:49 +01:00
access capabilities; minor alignment and refactoring (#34)
This commit is contained in:
parent
7dc14445ad
commit
7a3533209a
52
sdk/access.go
Normal file
52
sdk/access.go
Normal file
@ -0,0 +1,52 @@
|
||||
package sdk
|
||||
|
||||
import (
|
||||
httptransport "github.com/go-openapi/runtime/client"
|
||||
"github.com/openziti/zrok/environment/env_core"
|
||||
"github.com/openziti/zrok/rest_client_zrok/share"
|
||||
"github.com/openziti/zrok/rest_model_zrok"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
zrok, err := root.Client()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error getting zrok client")
|
||||
}
|
||||
auth := httptransport.APIKeyAuth("X-TOKEN", "header", root.Environment().Token)
|
||||
|
||||
in, err := zrok.Share.Access(out, auth)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "unable to create access")
|
||||
}
|
||||
|
||||
return &Access{Token: in.Payload.FrontendToken, ShareToken: request.ShareToken, BackendMode: BackendMode(in.Payload.BackendMode)}, nil
|
||||
}
|
||||
|
||||
func DeleteAccess(root env_core.Root, acc *Access) error {
|
||||
out := share.NewUnaccessParams()
|
||||
out.Body = &rest_model_zrok.UnaccessRequest{
|
||||
FrontendToken: acc.Token,
|
||||
ShrToken: acc.ShareToken,
|
||||
EnvZID: root.Environment().ZitiIdentity,
|
||||
}
|
||||
|
||||
zrok, err := root.Client()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting zrok client")
|
||||
}
|
||||
auth := httptransport.APIKeyAuth("X-TOKEN", "header", root.Environment().Token)
|
||||
|
||||
_, err = zrok.Share.Unaccess(out, auth)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error deleting access")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
14
sdk/model.go
14
sdk/model.go
@ -24,6 +24,20 @@ type ShareRequest struct {
|
||||
Target string
|
||||
}
|
||||
|
||||
type Share struct {
|
||||
Token string
|
||||
}
|
||||
|
||||
type AccessRequest struct {
|
||||
ShareToken string
|
||||
}
|
||||
|
||||
type Access struct {
|
||||
Token string
|
||||
ShareToken string
|
||||
BackendMode BackendMode
|
||||
}
|
||||
|
||||
type Metrics struct {
|
||||
Namespace string
|
||||
Sessions map[string]SessionMetrics
|
||||
|
@ -9,10 +9,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Share struct {
|
||||
Token string
|
||||
}
|
||||
|
||||
func CreateShare(root env_core.Root, request *ShareRequest) (*Share, error) {
|
||||
var err error
|
||||
var out *share.ShareParams
|
||||
@ -77,11 +73,11 @@ func newPublicShare(root env_core.Root, request *ShareRequest) *share.ShareParam
|
||||
return req
|
||||
}
|
||||
|
||||
func DeleteShare(root env_core.Root, shrToken string) error {
|
||||
func DeleteShare(root env_core.Root, shr *Share) error {
|
||||
req := share.NewUnshareParams()
|
||||
req.Body = &rest_model_zrok.UnshareRequest{
|
||||
EnvZID: root.Environment().ZitiIdentity,
|
||||
ShrToken: shrToken,
|
||||
ShrToken: shr.Token,
|
||||
}
|
||||
|
||||
zrok, err := root.Client()
|
||||
@ -94,5 +90,6 @@ func DeleteShare(root env_core.Root, shrToken string) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error deleting share")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user