mirror of
https://github.com/openziti/zrok.git
synced 2024-11-07 16:54:23 +01:00
create service (dial) policy for new identity for metrics service (#130)
This commit is contained in:
parent
13fabc9ec6
commit
9f4c37f88a
@ -21,7 +21,7 @@ func newAdminCreateIdentity() *adminCreateIdentity {
|
||||
cmd := &cobra.Command{
|
||||
Use: "identity <name>",
|
||||
Aliases: []string{"id"},
|
||||
Short: "Create an identity and basic edge policies",
|
||||
Short: "Create an identity and policies for a public frontend",
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
command := &adminCreateIdentity{cmd: cmd}
|
||||
|
@ -3,11 +3,14 @@ package controller
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/admin"
|
||||
"github.com/openziti/edge/rest_management_api_client/service"
|
||||
rest_model_edge "github.com/openziti/edge/rest_model"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
)
|
||||
|
||||
type createIdentityHandler struct{}
|
||||
@ -37,7 +40,7 @@ func (h *createIdentityHandler) Handle(params admin.CreateIdentityParams, princi
|
||||
}
|
||||
|
||||
zId := idc.Payload.Data.ID
|
||||
cfg, err := enrollIdentity(zId, edge)
|
||||
idCfg, err := enrollIdentity(zId, edge)
|
||||
if err != nil {
|
||||
logrus.Errorf("error enrolling identity: %v", err)
|
||||
return admin.NewCreateIdentityInternalServerError()
|
||||
@ -48,10 +51,36 @@ func (h *createIdentityHandler) Handle(params admin.CreateIdentityParams, princi
|
||||
return admin.NewCreateIdentityInternalServerError()
|
||||
}
|
||||
|
||||
filter := fmt.Sprintf("name=\"%v\" and tags.zrok != null", cfg.Metrics.ServiceName)
|
||||
limit := int64(0)
|
||||
offset := int64(0)
|
||||
listSvcReq := &service.ListServicesParams{
|
||||
Filter: &filter,
|
||||
Limit: &limit,
|
||||
Offset: &offset,
|
||||
}
|
||||
listSvcReq.SetTimeout(30 * time.Second)
|
||||
listSvcResp, err := edge.Service.ListServices(listSvcReq, nil)
|
||||
if err != nil {
|
||||
logrus.Errorf("error listing metrics service: %v", err)
|
||||
return admin.NewCreateIdentityInternalServerError()
|
||||
}
|
||||
if len(listSvcResp.Payload.Data) != 1 {
|
||||
logrus.Errorf("could not find metrics service")
|
||||
return admin.NewCreateIdentityInternalServerError()
|
||||
}
|
||||
svcZId := *listSvcResp.Payload.Data[0].ID
|
||||
|
||||
spName := fmt.Sprintf("%v-%v-dial", name, cfg.Metrics.ServiceName)
|
||||
if err := createNamedDialServicePolicy(spName, svcZId, zId, edge); err != nil {
|
||||
logrus.Errorf("error creating named dial service policy '%v': %v", spName, err)
|
||||
return admin.NewCreateIdentityInternalServerError()
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
enc := json.NewEncoder(&out)
|
||||
enc.SetEscapeHTML(false)
|
||||
err = enc.Encode(&cfg)
|
||||
err = enc.Encode(&idCfg)
|
||||
if err != nil {
|
||||
logrus.Errorf("error encoding identity config: %v", err)
|
||||
return admin.NewCreateFrontendInternalServerError()
|
||||
|
Loading…
Reference in New Issue
Block a user