mirror of
https://github.com/openziti/zrok.git
synced 2024-11-07 08:44:14 +01:00
more services -> shares (#144)
This commit is contained in:
parent
fe89551bfb
commit
74b9786a61
@ -44,14 +44,14 @@ func (h *accessHandler) Handle(params share.AccessParams, principal *rest_model_
|
||||
return share.NewAccessNotFound()
|
||||
}
|
||||
|
||||
svcToken := params.Body.ShrToken
|
||||
sshr, err := str.FindShareWithToken(svcToken, tx)
|
||||
shrToken := params.Body.ShrToken
|
||||
sshr, err := str.FindShareWithToken(shrToken, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error finding service")
|
||||
logrus.Errorf("error finding share")
|
||||
return share.NewAccessNotFound()
|
||||
}
|
||||
if sshr == nil {
|
||||
logrus.Errorf("unable to find service '%v' for user '%v'", svcToken, principal.Email)
|
||||
logrus.Errorf("unable to find share '%v' for user '%v'", shrToken, principal.Email)
|
||||
return share.NewAccessNotFound()
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ func (h *accessHandler) Handle(params share.AccessParams, principal *rest_model_
|
||||
addlTags := map[string]interface{}{
|
||||
"zrokEnvironmentZId": envZId,
|
||||
"zrokFrontendToken": feToken,
|
||||
"zrokServiceToken": svcToken,
|
||||
"zrokShareToken": shrToken,
|
||||
}
|
||||
if err := zrokEdgeSdk.CreateServicePolicyDial(envZId+"-"+sshr.ZId+"-dial", sshr.ZId, []string{envZId}, addlTags, edge); err != nil {
|
||||
logrus.Errorf("unable to create dial policy: %v", err)
|
||||
|
@ -86,7 +86,7 @@ func Bootstrap(skipCtrl, skipFrontend bool, inCfg *Config) error {
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
publicFe, err := str.FindFrontendWithZId(frontendZId, tx)
|
||||
if err != nil {
|
||||
logrus.Warnf("missing public frontend for ziti id '%v'; please use 'zrok admin create frontend %v public https://{svcToken}.your.dns.name' to create a frontend instance", frontendZId, frontendZId)
|
||||
logrus.Warnf("missing public frontend for ziti id '%v'; please use 'zrok admin create frontend %v public https://{token}.your.dns.name' to create a frontend instance", frontendZId, frontendZId)
|
||||
} else {
|
||||
if publicFe.PublicName != nil && publicFe.UrlTemplate != nil {
|
||||
logrus.Infof("found public frontend entry '%v' (%v) for ziti identity '%v'", *publicFe.PublicName, publicFe.Token, frontendZId)
|
||||
|
@ -40,8 +40,8 @@ func (h *disableHandler) Handle(params environment.DisableParams, principal *res
|
||||
logrus.Errorf("error getting edge client: %v", err)
|
||||
return environment.NewDisableInternalServerError()
|
||||
}
|
||||
if err := h.removeServicesForEnvironment(envId, tx, edge); err != nil {
|
||||
logrus.Errorf("error removing services for environment: %v", err)
|
||||
if err := h.removeSharesForEnvironment(envId, tx, edge); err != nil {
|
||||
logrus.Errorf("error removing shares for environment: %v", err)
|
||||
return environment.NewDisableInternalServerError()
|
||||
}
|
||||
if err := h.removeEnvironment(envId, tx); err != nil {
|
||||
@ -75,7 +75,7 @@ func (h *disableHandler) checkZitiIdentity(id string, principal *rest_model_zrok
|
||||
return -1, errors.Errorf("no such environment '%v'", id)
|
||||
}
|
||||
|
||||
func (h *disableHandler) removeServicesForEnvironment(envId int, tx *sqlx.Tx, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
func (h *disableHandler) removeSharesForEnvironment(envId int, tx *sqlx.Tx, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
env, err := str.GetEnvironment(envId, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -85,24 +85,24 @@ func (h *disableHandler) removeServicesForEnvironment(envId int, tx *sqlx.Tx, ed
|
||||
return err
|
||||
}
|
||||
for _, shr := range shrs {
|
||||
svcToken := shr.Token
|
||||
logrus.Infof("garbage collecting service '%v' for environment '%v'", svcToken, env.ZId)
|
||||
if err := zrokEdgeSdk.DeleteServiceEdgeRouterPolicy(env.ZId, svcToken, edge); err != nil {
|
||||
shrToken := shr.Token
|
||||
logrus.Infof("garbage collecting share '%v' for environment '%v'", shrToken, env.ZId)
|
||||
if err := zrokEdgeSdk.DeleteServiceEdgeRouterPolicy(env.ZId, shrToken, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
if err := zrokEdgeSdk.DeleteServicePolicyDial(env.ZId, svcToken, edge); err != nil {
|
||||
if err := zrokEdgeSdk.DeleteServicePolicyDial(env.ZId, shrToken, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
if err := zrokEdgeSdk.DeleteServicePolicyBind(env.ZId, svcToken, edge); err != nil {
|
||||
if err := zrokEdgeSdk.DeleteServicePolicyBind(env.ZId, shrToken, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
if err := zrokEdgeSdk.DeleteConfig(env.ZId, svcToken, edge); err != nil {
|
||||
if err := zrokEdgeSdk.DeleteConfig(env.ZId, shrToken, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
if err := zrokEdgeSdk.DeleteService(env.ZId, shr.ZId, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
logrus.Infof("removed service '%v' for environment '%v'", shr.Token, env.ZId)
|
||||
logrus.Infof("removed share '%v' for environment '%v'", shr.Token, env.ZId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -110,11 +110,11 @@ func (h *disableHandler) removeServicesForEnvironment(envId int, tx *sqlx.Tx, ed
|
||||
func (h *disableHandler) removeEnvironment(envId int, tx *sqlx.Tx) error {
|
||||
shrs, err := str.FindSharesForEnvironment(envId, tx)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error finding services for environment '%d'", envId)
|
||||
return errors.Wrapf(err, "error finding shares for environment '%d'", envId)
|
||||
}
|
||||
for _, shr := range shrs {
|
||||
if err := str.DeleteShare(shr.Id, tx); err != nil {
|
||||
return errors.Wrapf(err, "error deleting service '%d' for environment '%d'", shr.Id, envId)
|
||||
return errors.Wrapf(err, "error deleting share '%d' for environment '%d'", shr.Id, envId)
|
||||
}
|
||||
}
|
||||
if err := str.DeleteEnvironment(envId, tx); err != nil {
|
||||
|
@ -37,14 +37,14 @@ func (h *environmentDetailHandler) Handle(params metadata.GetEnvironmentDetailPa
|
||||
}
|
||||
shrs, err := str.FindSharesForEnvironment(senv.Id, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error finding services for environment '%v': %v", senv.ZId, err)
|
||||
logrus.Errorf("error finding shares for environment '%v': %v", senv.ZId, err)
|
||||
return metadata.NewGetEnvironmentDetailInternalServerError()
|
||||
}
|
||||
var sparkData map[string][]int64
|
||||
if cfg.Influx != nil {
|
||||
sparkData, err = sparkDataForServices(shrs)
|
||||
sparkData, err = sparkDataForShares(shrs)
|
||||
if err != nil {
|
||||
logrus.Errorf("error querying spark data for services: %v", err)
|
||||
logrus.Errorf("error querying spark data for shares: %v", err)
|
||||
return metadata.NewGetEnvironmentDetailInternalServerError()
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
|
||||
for _, env := range envs {
|
||||
shrs, err := str.FindSharesForEnvironment(env.Id, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error finding services for environment '%v': %v", env.ZId, err)
|
||||
logrus.Errorf("error finding shares for environment '%v': %v", env.ZId, err)
|
||||
return metadata.NewOverviewInternalServerError()
|
||||
}
|
||||
es := &rest_model_zrok.EnvironmentShares{
|
||||
|
@ -56,7 +56,7 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
|
||||
return share.NewShareInternalServerError()
|
||||
}
|
||||
|
||||
var svcZId string
|
||||
var shrZId string
|
||||
var frontendEndpoints []string
|
||||
switch params.Body.ShareMode {
|
||||
case "public":
|
||||
@ -76,17 +76,17 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
|
||||
if sfe != nil && sfe.UrlTemplate != nil {
|
||||
frontendZIds = append(frontendZIds, sfe.ZId)
|
||||
frontendTemplates = append(frontendTemplates, *sfe.UrlTemplate)
|
||||
logrus.Infof("added frontend selection '%v' with ziti identity '%v' for service '%v'", frontendSelection, sfe.ZId, shrToken)
|
||||
logrus.Infof("added frontend selection '%v' with ziti identity '%v' for share '%v'", frontendSelection, sfe.ZId, shrToken)
|
||||
}
|
||||
}
|
||||
svcZId, frontendEndpoints, err = newPublicResourceAllocator().allocate(envZId, shrToken, frontendZIds, frontendTemplates, params, edge)
|
||||
shrZId, frontendEndpoints, err = newPublicResourceAllocator().allocate(envZId, shrToken, frontendZIds, frontendTemplates, params, edge)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return share.NewShareInternalServerError()
|
||||
}
|
||||
|
||||
case "private":
|
||||
svcZId, frontendEndpoints, err = newPrivateResourceAllocator().allocate(envZId, shrToken, params, edge)
|
||||
shrZId, frontendEndpoints, err = newPrivateResourceAllocator().allocate(envZId, shrToken, params, edge)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return share.NewShareInternalServerError()
|
||||
@ -97,11 +97,11 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
|
||||
return share.NewShareInternalServerError()
|
||||
}
|
||||
|
||||
logrus.Debugf("allocated service '%v'", shrToken)
|
||||
logrus.Debugf("allocated share '%v'", shrToken)
|
||||
|
||||
reserved := params.Body.Reserved
|
||||
sshr := &store.Share{
|
||||
ZId: svcZId,
|
||||
ZId: shrZId,
|
||||
Token: shrToken,
|
||||
ShareMode: params.Body.ShareMode,
|
||||
BackendMode: params.Body.BackendMode,
|
||||
@ -116,15 +116,15 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr
|
||||
|
||||
sid, err := str.CreateShare(envId, sshr, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error creating service record: %v", err)
|
||||
logrus.Errorf("error creating share record: %v", err)
|
||||
return share.NewShareInternalServerError()
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
logrus.Errorf("error committing service record: %v", err)
|
||||
logrus.Errorf("error committing share record: %v", err)
|
||||
return share.NewShareInternalServerError()
|
||||
}
|
||||
logrus.Infof("recorded service '%v' with id '%v' for '%v'", shrToken, sid, principal.Email)
|
||||
logrus.Infof("recorded share '%v' with id '%v' for '%v'", shrToken, sid, principal.Email)
|
||||
|
||||
return share.NewShareCreated().WithPayload(&rest_model_zrok.ShareResponse{
|
||||
FrontendProxyEndpoints: frontendEndpoints,
|
||||
|
@ -39,14 +39,14 @@ func (h *shareDetailHandler) Handle(params metadata.GetShareDetailParams, princi
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
logrus.Errorf("environment not matched for service '%v' for account '%v'", params.ShrToken, principal.Email)
|
||||
logrus.Errorf("environment not matched for share '%v' for account '%v'", params.ShrToken, principal.Email)
|
||||
return metadata.NewGetShareDetailNotFound()
|
||||
}
|
||||
var sparkData map[string][]int64
|
||||
if cfg.Influx != nil {
|
||||
sparkData, err = sparkDataForServices([]*store.Share{shr})
|
||||
sparkData, err = sparkDataForShares([]*store.Share{shr})
|
||||
if err != nil {
|
||||
logrus.Errorf("error querying spark data for services: %v", err)
|
||||
logrus.Errorf("error querying spark data for share: %v", err)
|
||||
return metadata.NewGetEnvironmentDetailInternalServerError()
|
||||
}
|
||||
}
|
||||
|
@ -13,26 +13,26 @@ func newPrivateResourceAllocator() *privateResourceAllocator {
|
||||
return &privateResourceAllocator{}
|
||||
}
|
||||
|
||||
func (a *privateResourceAllocator) allocate(envZId, svcToken string, params share.ShareParams, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, frontendEndpoints []string, err error) {
|
||||
func (a *privateResourceAllocator) allocate(envZId, shrToken string, params share.ShareParams, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, frontendEndpoints []string, err error) {
|
||||
var authUsers []*model.AuthUser
|
||||
for _, authUser := range params.Body.AuthUsers {
|
||||
authUsers = append(authUsers, &model.AuthUser{authUser.Username, authUser.Password})
|
||||
}
|
||||
cfgZId, err := zrokEdgeSdk.CreateConfig(zrokProxyConfigId, envZId, svcToken, params.Body.AuthScheme, authUsers, edge)
|
||||
cfgZId, err := zrokEdgeSdk.CreateConfig(zrokProxyConfigId, envZId, shrToken, params.Body.AuthScheme, authUsers, edge)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
svcZId, err = zrokEdgeSdk.CreateShareService(envZId, svcToken, cfgZId, edge)
|
||||
svcZId, err = zrokEdgeSdk.CreateShareService(envZId, shrToken, cfgZId, edge)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := zrokEdgeSdk.CreateServicePolicyBind(envZId+"-"+svcZId+"-bind", svcZId, envZId, zrokEdgeSdk.ZrokServiceTags(svcToken).SubTags, edge); err != nil {
|
||||
if err := zrokEdgeSdk.CreateServicePolicyBind(envZId+"-"+svcZId+"-bind", svcZId, envZId, zrokEdgeSdk.ZrokShareTags(shrToken).SubTags, edge); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := zrokEdgeSdk.CreateShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId, edge); err != nil {
|
||||
if err := zrokEdgeSdk.CreateShareServiceEdgeRouterPolicy(envZId, shrToken, svcZId, edge); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,11 @@ func (a *publicResourceAllocator) allocate(envZId, svcToken string, frontendZIds
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := zrokEdgeSdk.CreateServicePolicyBind(envZId+"-"+svcZId+"-bind", svcZId, envZId, zrokEdgeSdk.ZrokServiceTags(svcToken).SubTags, edge); err != nil {
|
||||
if err := zrokEdgeSdk.CreateServicePolicyBind(envZId+"-"+svcZId+"-bind", svcZId, envZId, zrokEdgeSdk.ZrokShareTags(svcToken).SubTags, edge); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
if err := zrokEdgeSdk.CreateServicePolicyDial(envZId+"-"+svcZId+"-dial", svcZId, frontendZIds, zrokEdgeSdk.ZrokServiceTags(svcToken).SubTags, edge); err != nil {
|
||||
if err := zrokEdgeSdk.CreateServicePolicyDial(envZId+"-"+svcZId+"-dial", svcZId, frontendZIds, zrokEdgeSdk.ZrokShareTags(svcToken).SubTags, edge); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/openziti-test-kitchen/zrok/controller/store"
|
||||
)
|
||||
|
||||
func sparkDataForServices(shrs []*store.Share) (map[string][]int64, error) {
|
||||
func sparkDataForShares(shrs []*store.Share) (map[string][]int64, error) {
|
||||
out := make(map[string][]int64)
|
||||
|
||||
if len(shrs) > 0 {
|
||||
@ -37,20 +37,20 @@ func sparkDataForServices(shrs []*store.Share) (map[string][]int64, error) {
|
||||
}
|
||||
|
||||
func sparkFluxQuery(shrs []*store.Share) string {
|
||||
svcFilter := "|> filter(fn: (r) =>"
|
||||
shrFilter := "|> filter(fn: (r) =>"
|
||||
for i, shr := range shrs {
|
||||
if i > 0 {
|
||||
svcFilter += " or"
|
||||
shrFilter += " or"
|
||||
}
|
||||
svcFilter += fmt.Sprintf(" r[\"share\"] == \"%v\"", shr.Token)
|
||||
shrFilter += fmt.Sprintf(" r[\"share\"] == \"%v\"", shr.Token)
|
||||
}
|
||||
svcFilter += ")"
|
||||
shrFilter += ")"
|
||||
query := "read = from(bucket: \"zrok\")" +
|
||||
"|> range(start: -5m)" +
|
||||
"|> filter(fn: (r) => r[\"_measurement\"] == \"xfer\")" +
|
||||
"|> filter(fn: (r) => r[\"_field\"] == \"bytesRead\" or r[\"_field\"] == \"bytesWritten\")" +
|
||||
"|> filter(fn: (r) => r[\"namespace\"] == \"frontend\")" +
|
||||
svcFilter +
|
||||
shrFilter +
|
||||
"|> aggregateWindow(every: 5s, fn: sum, createEmpty: true)\n" +
|
||||
"|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")" +
|
||||
"|> yield(name: \"last\")"
|
||||
|
@ -70,7 +70,7 @@ func (h *unaccessHandler) Handle(params share.UnaccessParams, principal *rest_mo
|
||||
return share.NewUnaccessNotFound()
|
||||
}
|
||||
|
||||
if err := zrokEdgeSdk.DeleteServicePolicy(envZId, fmt.Sprintf("tags.zrokServiceToken=\"%v\" and tags.zrokFrontendToken=\"%v\" and type=1", shrToken, feToken), edge); err != nil {
|
||||
if err := zrokEdgeSdk.DeleteServicePolicy(envZId, fmt.Sprintf("tags.zrokShareToken=\"%v\" and tags.zrokFrontendToken=\"%v\" and type=1", shrToken, feToken), edge); err != nil {
|
||||
logrus.Errorf("error removing access to '%v' for '%v': %v", shrToken, envZId, err)
|
||||
return share.NewUnaccessInternalServerError()
|
||||
}
|
||||
|
@ -59,34 +59,34 @@ func (h *unshareHandler) Handle(params share.UnshareParams, principal *rest_mode
|
||||
}
|
||||
|
||||
var sshr *store.Share
|
||||
if svcs, err := str.FindSharesForEnvironment(senv.Id, tx); err == nil {
|
||||
for _, svc := range svcs {
|
||||
if svc.ZId == svcZId {
|
||||
sshr = svc
|
||||
if shrs, err := str.FindSharesForEnvironment(senv.Id, tx); err == nil {
|
||||
for _, shr := range shrs {
|
||||
if shr.ZId == svcZId {
|
||||
sshr = shr
|
||||
break
|
||||
}
|
||||
}
|
||||
if sshr == nil {
|
||||
err := errors.Errorf("service with id '%v' not found for '%v'", svcZId, principal.Email)
|
||||
err := errors.Errorf("share with id '%v' not found for '%v'", svcZId, principal.Email)
|
||||
logrus.Error(err)
|
||||
return share.NewUnshareNotFound()
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("error finding services for account '%v': %v", principal.Email, err)
|
||||
logrus.Errorf("error finding shares for account '%v': %v", principal.Email, err)
|
||||
return share.NewUnshareInternalServerError()
|
||||
}
|
||||
|
||||
if sshr.Reserved == params.Body.Reserved {
|
||||
// single tag-based service deallocator; should work regardless of sharing mode
|
||||
// single tag-based share deallocator; should work regardless of sharing mode
|
||||
if err := h.deallocateResources(senv, shrToken, svcZId, edge); err != nil {
|
||||
logrus.Errorf("error unsharing ziti resources for '%v': %v", sshr, err)
|
||||
return share.NewUnshareInternalServerError()
|
||||
}
|
||||
|
||||
logrus.Debugf("deallocated service '%v'", shrToken)
|
||||
logrus.Debugf("deallocated share '%v'", shrToken)
|
||||
|
||||
if err := str.DeleteShare(sshr.Id, tx); err != nil {
|
||||
logrus.Errorf("error deactivating service '%v': %v", svcZId, err)
|
||||
logrus.Errorf("error deactivating share '%v': %v", svcZId, err)
|
||||
return share.NewUnshareInternalServerError()
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
@ -95,14 +95,14 @@ func (h *unshareHandler) Handle(params share.UnshareParams, principal *rest_mode
|
||||
}
|
||||
|
||||
} else {
|
||||
logrus.Infof("service '%v' is reserved, skipping deallocation", shrToken)
|
||||
logrus.Infof("share '%v' is reserved, skipping deallocation", shrToken)
|
||||
}
|
||||
|
||||
return share.NewUnshareOK()
|
||||
}
|
||||
|
||||
func (h *unshareHandler) findServiceZId(svcToken string, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
|
||||
filter := fmt.Sprintf("name=\"%v\"", svcToken)
|
||||
func (h *unshareHandler) findServiceZId(shrToken string, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
|
||||
filter := fmt.Sprintf("name=\"%v\"", shrToken)
|
||||
limit := int64(1)
|
||||
offset := int64(0)
|
||||
listReq := &edge_service.ListServicesParams{
|
||||
@ -119,20 +119,20 @@ func (h *unshareHandler) findServiceZId(svcToken string, edge *rest_management_a
|
||||
if len(listResp.Payload.Data) == 1 {
|
||||
return *(listResp.Payload.Data[0].ID), nil
|
||||
}
|
||||
return "", errors.Errorf("service '%v' not found", svcToken)
|
||||
return "", errors.Errorf("share '%v' not found", shrToken)
|
||||
}
|
||||
|
||||
func (h *unshareHandler) deallocateResources(senv *store.Environment, svcToken, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
if err := zrokEdgeSdk.DeleteServiceEdgeRouterPolicy(senv.ZId, svcToken, edge); err != nil {
|
||||
func (h *unshareHandler) deallocateResources(senv *store.Environment, shrToken, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
if err := zrokEdgeSdk.DeleteServiceEdgeRouterPolicy(senv.ZId, shrToken, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := zrokEdgeSdk.DeleteServicePolicyDial(senv.ZId, svcToken, edge); err != nil {
|
||||
if err := zrokEdgeSdk.DeleteServicePolicyDial(senv.ZId, shrToken, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := zrokEdgeSdk.DeleteServicePolicyBind(senv.ZId, svcToken, edge); err != nil {
|
||||
if err := zrokEdgeSdk.DeleteServicePolicyBind(senv.ZId, shrToken, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := zrokEdgeSdk.DeleteConfig(senv.ZId, svcToken, edge); err != nil {
|
||||
if err := zrokEdgeSdk.DeleteConfig(senv.ZId, shrToken, edge); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := zrokEdgeSdk.DeleteService(senv.ZId, svcZId, edge); err != nil {
|
||||
|
@ -26,7 +26,7 @@ func (h *updateShareHandler) Handle(params share.UpdateShareParams, principal *r
|
||||
|
||||
sshr, err := str.FindShareWithToken(shrToken, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("service '%v' not found: %v", shrToken, err)
|
||||
logrus.Errorf("share '%v' not found: %v", shrToken, err)
|
||||
return share.NewUpdateShareNotFound()
|
||||
}
|
||||
|
||||
@ -44,18 +44,18 @@ func (h *updateShareHandler) Handle(params share.UpdateShareParams, principal *r
|
||||
}
|
||||
}
|
||||
if !envFound {
|
||||
logrus.Errorf("environment not found for service '%v'", shrToken)
|
||||
logrus.Errorf("environment not found for share '%v'", shrToken)
|
||||
return share.NewUpdateShareNotFound()
|
||||
}
|
||||
|
||||
sshr.BackendProxyEndpoint = &backendProxyEndpoint
|
||||
if err := str.UpdateShare(sshr, tx); err != nil {
|
||||
logrus.Errorf("error updating service '%v': %v", shrToken, err)
|
||||
logrus.Errorf("error updating share '%v': %v", shrToken, err)
|
||||
return share.NewUpdateShareInternalServerError()
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
logrus.Errorf("error committing transaction for service '%v' update: %v", shrToken, err)
|
||||
logrus.Errorf("error committing transaction for share '%v' update: %v", shrToken, err)
|
||||
return share.NewUpdateShareInternalServerError()
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,6 @@ func realRemoteAddress(req *http.Request) string {
|
||||
return ip
|
||||
}
|
||||
|
||||
func proxyUrl(svcToken, template string) string {
|
||||
return strings.Replace(template, "{svcToken}", svcToken, -1)
|
||||
func proxyUrl(shrToken, template string) string {
|
||||
return strings.Replace(template, "{token}", shrToken, -1)
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func CreateConfig(cfgTypeZId, envZId, svcToken string, authSchemeStr string, authUsers []*model.AuthUser, edge *rest_management_api_client.ZitiEdgeManagement) (cfgZId string, err error) {
|
||||
func CreateConfig(cfgTypeZId, envZId, shrToken string, authSchemeStr string, authUsers []*model.AuthUser, edge *rest_management_api_client.ZitiEdgeManagement) (cfgZId string, err error) {
|
||||
authScheme, err := model.ParseAuthScheme(authSchemeStr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -28,8 +28,8 @@ func CreateConfig(cfgTypeZId, envZId, svcToken string, authSchemeStr string, aut
|
||||
cfgCrt := &rest_model.ConfigCreate{
|
||||
ConfigTypeID: &cfgTypeZId,
|
||||
Data: cfg,
|
||||
Name: &svcToken,
|
||||
Tags: ZrokServiceTags(svcToken),
|
||||
Name: &shrToken,
|
||||
Tags: ZrokShareTags(shrToken),
|
||||
}
|
||||
cfgReq := &config.CreateConfigParams{
|
||||
Config: cfgCrt,
|
||||
@ -44,8 +44,8 @@ func CreateConfig(cfgTypeZId, envZId, svcToken string, authSchemeStr string, aut
|
||||
return cfgResp.Payload.Data.ID, nil
|
||||
}
|
||||
|
||||
func DeleteConfig(envZId, svcToken string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := fmt.Sprintf("tags.zrokServiceToken=\"%v\"", svcToken)
|
||||
func DeleteConfig(envZId, shrToken string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := fmt.Sprintf("tags.zrokShareToken=\"%v\"", shrToken)
|
||||
limit := int64(0)
|
||||
offset := int64(0)
|
||||
listReq := &config.ListConfigsParams{
|
||||
|
@ -11,8 +11,8 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func CreateShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
serpZId, err := CreateServiceEdgeRouterPolicy(svcToken, svcZId, ZrokServiceTags(svcToken).SubTags, edge)
|
||||
func CreateShareServiceEdgeRouterPolicy(envZId, shrToken, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
serpZId, err := CreateServiceEdgeRouterPolicy(shrToken, svcZId, ZrokShareTags(shrToken).SubTags, edge)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -20,10 +20,10 @@ func CreateShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId string, edge *r
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateServiceEdgeRouterPolicy(name, svcZId string, moreTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
|
||||
func CreateServiceEdgeRouterPolicy(name, shrZId string, moreTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
|
||||
edgeRouterRoles := []string{"#all"}
|
||||
semantic := rest_model.SemanticAllOf
|
||||
serviceRoles := []string{fmt.Sprintf("@%v", svcZId)}
|
||||
serviceRoles := []string{fmt.Sprintf("@%v", shrZId)}
|
||||
tags := ZrokTags()
|
||||
for k, v := range moreTags {
|
||||
tags.SubTags[k] = v
|
||||
@ -42,13 +42,13 @@ func CreateServiceEdgeRouterPolicy(name, svcZId string, moreTags map[string]inte
|
||||
serpParams.SetTimeout(30 * time.Second)
|
||||
resp, err := edge.ServiceEdgeRouterPolicy.CreateServiceEdgeRouterPolicy(serpParams, nil)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "error creating serp '%v' for service '%v'", name, svcZId)
|
||||
return "", errors.Wrapf(err, "error creating serp '%v' for service '%v'", name, shrZId)
|
||||
}
|
||||
return resp.Payload.Data.ID, nil
|
||||
}
|
||||
|
||||
func DeleteServiceEdgeRouterPolicy(envZId, svcToken string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := fmt.Sprintf("tags.zrokServiceToken=\"%v\"", svcToken)
|
||||
func DeleteServiceEdgeRouterPolicy(envZId, shrToken string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := fmt.Sprintf("tags.zrokShareToken=\"%v\"", shrToken)
|
||||
limit := int64(1)
|
||||
offset := int64(0)
|
||||
listReq := &service_edge_router_policy.ListServiceEdgeRouterPoliciesParams{
|
||||
|
@ -10,16 +10,16 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func CreateShareService(envZId, svcToken, cfgZId string, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, err error) {
|
||||
svcZId, err = CreateService(svcToken, []string{cfgZId}, map[string]interface{}{"zrokServiceToken": svcToken}, edge)
|
||||
func CreateShareService(envZId, shrToken, cfgZId string, edge *rest_management_api_client.ZitiEdgeManagement) (shrZId string, err error) {
|
||||
shrZId, err = CreateService(shrToken, []string{cfgZId}, map[string]interface{}{"zrokShareToken": shrToken}, edge)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "error creating service '%v'", svcToken)
|
||||
return "", errors.Wrapf(err, "error creating share '%v'", shrToken)
|
||||
}
|
||||
logrus.Infof("created zrok service named '%v' (with ziti id '%v') for environment '%v'", svcToken, svcZId, envZId)
|
||||
return svcZId, nil
|
||||
logrus.Infof("created share '%v' (with ziti id '%v') for environment '%v'", shrToken, shrZId, envZId)
|
||||
return shrZId, nil
|
||||
}
|
||||
|
||||
func CreateService(name string, cfgZIds []string, addlTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, err error) {
|
||||
func CreateService(name string, cfgZIds []string, addlTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) (shrZId string, err error) {
|
||||
encryptionRequired := true
|
||||
svc := &rest_model.ServiceCreate{
|
||||
EncryptionRequired: &encryptionRequired,
|
||||
|
@ -16,30 +16,30 @@ const (
|
||||
servicePolicyBind = 2
|
||||
)
|
||||
|
||||
func CreateServicePolicyBind(name, svcZId, bindZId string, addlTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
func CreateServicePolicyBind(name, shrZId, bindZId string, addlTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
semantic := rest_model.SemanticAllOf
|
||||
identityRoles := []string{"@" + bindZId}
|
||||
serviceRoles := []string{"@" + svcZId}
|
||||
serviceRoles := []string{"@" + shrZId}
|
||||
spZId, err := createServicePolicy(name, semantic, identityRoles, serviceRoles, addlTags, servicePolicyBind, edge)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating bind service policy for service '%v' for identity '%v'", svcZId, bindZId)
|
||||
return errors.Wrapf(err, "error creating bind service policy for service '%v' for identity '%v'", shrZId, bindZId)
|
||||
}
|
||||
logrus.Infof("created bind service policy '%v' for service '%v' for identity '%v'", spZId, svcZId, bindZId)
|
||||
logrus.Infof("created bind service policy '%v' for service '%v' for identity '%v'", spZId, shrZId, bindZId)
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateServicePolicyDial(name, svcZId string, dialZIds []string, addlTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
func CreateServicePolicyDial(name, shrZId string, dialZIds []string, addlTags map[string]interface{}, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
semantic := rest_model.SemanticAllOf
|
||||
var identityRoles []string
|
||||
for _, zId := range dialZIds {
|
||||
identityRoles = append(identityRoles, "@"+zId)
|
||||
}
|
||||
serviceRoles := []string{"@" + svcZId}
|
||||
serviceRoles := []string{"@" + shrZId}
|
||||
spZId, err := createServicePolicy(name, semantic, identityRoles, serviceRoles, addlTags, servicePolicyDial, edge)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error creating dial service policy for service '%v' for identities '%v'", svcZId, dialZIds)
|
||||
return errors.Wrapf(err, "error creating dial service policy for service '%v' for identities '%v'", shrZId, dialZIds)
|
||||
}
|
||||
logrus.Infof("created dial service policy '%v' for service '%v' for identities '%v'", spZId, svcZId, dialZIds)
|
||||
logrus.Infof("created dial service policy '%v' for service '%v' for identities '%v'", spZId, shrZId, dialZIds)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -78,12 +78,12 @@ func createServicePolicy(name string, semantic rest_model.Semantic, identityRole
|
||||
return resp.Payload.Data.ID, nil
|
||||
}
|
||||
|
||||
func DeleteServicePolicyBind(envZId, svcToken string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
return DeleteServicePolicy(envZId, fmt.Sprintf("tags.zrokServiceToken=\"%v\" and type=%d", svcToken, servicePolicyBind), edge)
|
||||
func DeleteServicePolicyBind(envZId, shrToken string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
return DeleteServicePolicy(envZId, fmt.Sprintf("tags.zrokShareToken=\"%v\" and type=%d", shrToken, servicePolicyBind), edge)
|
||||
}
|
||||
|
||||
func DeleteServicePolicyDial(envZId, svcToken string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
return DeleteServicePolicy(envZId, fmt.Sprintf("tags.zrokServiceToken=\"%v\" and type=%d", svcToken, servicePolicyDial), edge)
|
||||
func DeleteServicePolicyDial(envZId, shrToken string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
return DeleteServicePolicy(envZId, fmt.Sprintf("tags.zrokShareToken=\"%v\" and type=%d", shrToken, servicePolicyDial), edge)
|
||||
}
|
||||
|
||||
func DeleteServicePolicy(envZId, filter string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
|
@ -13,9 +13,9 @@ func ZrokTags() *rest_model.Tags {
|
||||
}
|
||||
}
|
||||
|
||||
func ZrokServiceTags(svcToken string) *rest_model.Tags {
|
||||
func ZrokShareTags(shrToken string) *rest_model.Tags {
|
||||
tags := ZrokTags()
|
||||
tags.SubTags["zrokServiceToken"] = svcToken
|
||||
tags.SubTags["zrokShareToken"] = shrToken
|
||||
return tags
|
||||
}
|
||||
|
||||
@ -24,4 +24,4 @@ func MergeTags(tags *rest_model.Tags, addl map[string]interface{}) *rest_model.T
|
||||
tags.SubTags[k] = v
|
||||
}
|
||||
return tags
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ const Detail = (props) => {
|
||||
detailComponent = <Environment selection={props.selection} />;
|
||||
break;
|
||||
|
||||
case "service":
|
||||
case "share":
|
||||
detailComponent = <ShareDetail selection={props.selection} />;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ const Shares = (props) => {
|
||||
<div className={"zrok-datatable"}>
|
||||
<DataTable
|
||||
className={"zrok-datatable"}
|
||||
data={detail.services}
|
||||
data={detail.shares}
|
||||
columns={columns}
|
||||
defaultSortField={1}
|
||||
noDataComponent={<p>No shares in environment</p>}
|
||||
|
@ -22,7 +22,7 @@ const Network = (props) => {
|
||||
case "environment":
|
||||
nodeColor = "#444";
|
||||
break;
|
||||
case "service":
|
||||
case "share":
|
||||
nodeColor = "#291A66";
|
||||
break;
|
||||
}
|
||||
@ -42,7 +42,7 @@ const Network = (props) => {
|
||||
ctx.stroke();
|
||||
} else {
|
||||
switch(node.type) {
|
||||
case "service":
|
||||
case "share":
|
||||
ctx.strokeStyle = "#433482";
|
||||
ctx.stroke();
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ export const mergeGraph = (oldGraph, user, newOverview) => {
|
||||
source: envNode.id,
|
||||
color: "#777"
|
||||
});
|
||||
if(env.services) {
|
||||
env.services.forEach(svc => {
|
||||
if(env.shares) {
|
||||
env.shares.forEach(svc => {
|
||||
let svcLabel = svc.token;
|
||||
if(svc.backendProxyEndpoint !== "") {
|
||||
svcLabel = svc.backendProxyEndpoint;
|
||||
@ -51,7 +51,7 @@ export const mergeGraph = (oldGraph, user, newOverview) => {
|
||||
let svcNode = {
|
||||
id: svc.token,
|
||||
label: svcLabel,
|
||||
type: "service",
|
||||
type: "share",
|
||||
val: 50
|
||||
};
|
||||
newGraph.nodes.push(svcNode);
|
||||
|
Loading…
Reference in New Issue
Block a user