mirror of
https://github.com/openziti/zrok.git
synced 2025-01-03 04:29:19 +01:00
zrok_edge_sdk; identity (#112)
This commit is contained in:
parent
f1388ab271
commit
856cf45ddc
@ -196,13 +196,13 @@ func assertIdentity(zId string, edge *rest_management_api_client.ZitiEdgeManagem
|
||||
}
|
||||
|
||||
func bootstrapIdentity(name string, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
|
||||
idc, err := createIdentity(name, rest_model_edge.IdentityTypeDevice, nil, edge)
|
||||
idc, err := zrok_edge_sdk.CreateIdentity(name, rest_model_edge.IdentityTypeDevice, nil, edge)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "error creating '%v' identity", name)
|
||||
}
|
||||
|
||||
zId := idc.Payload.Data.ID
|
||||
cfg, err := enrollIdentity(zId, edge)
|
||||
cfg, err := zrok_edge_sdk.EnrollIdentity(zId, edge)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "error enrolling '%v' identity", name)
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/openziti-test-kitchen/zrok/controller/store"
|
||||
"github.com/openziti-test-kitchen/zrok/controller/zrok_edge_sdk"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/admin"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -27,7 +28,7 @@ func (h *createFrontendHandler) Handle(params admin.CreateFrontendParams, princi
|
||||
}
|
||||
|
||||
zId := params.Body.ZID
|
||||
detail, err := getIdentity(zId, client)
|
||||
detail, err := zrok_edge_sdk.GetIdentity(zId, client)
|
||||
if err != nil {
|
||||
logrus.Errorf("error getting identity details for '%v': %v", zId, err)
|
||||
return admin.NewCreateFrontendInternalServerError()
|
||||
|
@ -34,14 +34,14 @@ func (h *createIdentityHandler) Handle(params admin.CreateIdentityParams, princi
|
||||
return admin.NewCreateIdentityInternalServerError()
|
||||
}
|
||||
|
||||
idc, err := createIdentity(name, rest_model_edge.IdentityTypeService, nil, edge)
|
||||
idc, err := zrok_edge_sdk.CreateIdentity(name, rest_model_edge.IdentityTypeService, nil, edge)
|
||||
if err != nil {
|
||||
logrus.Errorf("error creating identity: %v", err)
|
||||
return admin.NewCreateIdentityInternalServerError()
|
||||
}
|
||||
|
||||
zId := idc.Payload.Data.ID
|
||||
idCfg, err := enrollIdentity(zId, edge)
|
||||
idCfg, err := zrok_edge_sdk.EnrollIdentity(zId, edge)
|
||||
if err != nil {
|
||||
logrus.Errorf("error enrolling identity: %v", err)
|
||||
return admin.NewCreateIdentityInternalServerError()
|
||||
|
@ -52,7 +52,7 @@ func (h *disableHandler) Handle(params environment.DisableParams, principal *res
|
||||
logrus.Errorf("error deleting edge router policy: %v", err)
|
||||
return environment.NewDisableInternalServerError()
|
||||
}
|
||||
if err := deleteIdentity(params.Body.Identity, edge); err != nil {
|
||||
if err := zrok_edge_sdk.DeleteIdentity(params.Body.Identity, edge); err != nil {
|
||||
logrus.Errorf("error deleting identity: %v", err)
|
||||
return environment.NewDisableInternalServerError()
|
||||
}
|
||||
|
@ -31,13 +31,18 @@ func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_
|
||||
logrus.Errorf("error getting edge client: %v", err)
|
||||
return environment.NewEnableInternalServerError()
|
||||
}
|
||||
ident, err := createEnvironmentIdentity(principal.Email, client)
|
||||
accountToken, err := createToken()
|
||||
if err != nil {
|
||||
logrus.Errorf("error creating account token: %v", err)
|
||||
return environment.NewEnableInternalServerError()
|
||||
}
|
||||
ident, err := zrok_edge_sdk.CreateEnvironmentIdentity(principal.Email, accountToken, client)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return environment.NewEnableInternalServerError()
|
||||
}
|
||||
envZId := ident.Payload.Data.ID
|
||||
cfg, err := enrollIdentity(envZId, client)
|
||||
cfg, err := zrok_edge_sdk.EnrollIdentity(envZId, client)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return environment.NewEnableInternalServerError()
|
||||
|
@ -1,35 +1,30 @@
|
||||
package controller
|
||||
package zrok_edge_sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/openziti-test-kitchen/zrok/controller/zrok_edge_sdk"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
identity_edge "github.com/openziti/edge/rest_management_api_client/identity"
|
||||
"github.com/openziti/edge/rest_management_api_client/identity"
|
||||
rest_model_edge "github.com/openziti/edge/rest_model"
|
||||
sdk_config "github.com/openziti/sdk-golang/ziti/config"
|
||||
"github.com/openziti/sdk-golang/ziti/config"
|
||||
"github.com/openziti/sdk-golang/ziti/enroll"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
)
|
||||
|
||||
func createEnvironmentIdentity(accountEmail string, client *rest_management_api_client.ZitiEdgeManagement) (*identity_edge.CreateIdentityCreated, error) {
|
||||
name, err := createToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func CreateEnvironmentIdentity(accountEmail, accountToken string, client *rest_management_api_client.ZitiEdgeManagement) (*identity.CreateIdentityCreated, error) {
|
||||
identityType := rest_model_edge.IdentityTypeUser
|
||||
moreTags := map[string]interface{}{"zrokEmail": accountEmail}
|
||||
return createIdentity(name, identityType, moreTags, client)
|
||||
return CreateIdentity(accountToken, identityType, moreTags, client)
|
||||
}
|
||||
|
||||
func createIdentity(name string, identityType rest_model_edge.IdentityType, moreTags map[string]interface{}, client *rest_management_api_client.ZitiEdgeManagement) (*identity_edge.CreateIdentityCreated, error) {
|
||||
func CreateIdentity(name string, identityType rest_model_edge.IdentityType, moreTags map[string]interface{}, client *rest_management_api_client.ZitiEdgeManagement) (*identity.CreateIdentityCreated, error) {
|
||||
isAdmin := false
|
||||
tags := zrok_edge_sdk.ZrokTags()
|
||||
tags := ZrokTags()
|
||||
for k, v := range moreTags {
|
||||
tags.SubTags[k] = v
|
||||
}
|
||||
req := identity_edge.NewCreateIdentityParams()
|
||||
req := identity.NewCreateIdentityParams()
|
||||
req.Identity = &rest_model_edge.IdentityCreate{
|
||||
Enrollment: &rest_model_edge.IdentityCreateEnrollment{Ott: true},
|
||||
IsAdmin: &isAdmin,
|
||||
@ -47,11 +42,11 @@ func createIdentity(name string, identityType rest_model_edge.IdentityType, more
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func getIdentity(zId string, client *rest_management_api_client.ZitiEdgeManagement) (*identity_edge.ListIdentitiesOK, error) {
|
||||
func GetIdentity(zId string, client *rest_management_api_client.ZitiEdgeManagement) (*identity.ListIdentitiesOK, error) {
|
||||
filter := fmt.Sprintf("id=\"%v\"", zId)
|
||||
limit := int64(0)
|
||||
offset := int64(0)
|
||||
req := &identity_edge.ListIdentitiesParams{
|
||||
req := &identity.ListIdentitiesParams{
|
||||
Filter: &filter,
|
||||
Limit: &limit,
|
||||
Offset: &offset,
|
||||
@ -65,8 +60,8 @@ func getIdentity(zId string, client *rest_management_api_client.ZitiEdgeManageme
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func enrollIdentity(zId string, client *rest_management_api_client.ZitiEdgeManagement) (*sdk_config.Config, error) {
|
||||
p := &identity_edge.DetailIdentityParams{
|
||||
func EnrollIdentity(zId string, client *rest_management_api_client.ZitiEdgeManagement) (*config.Config, error) {
|
||||
p := &identity.DetailIdentityParams{
|
||||
Context: context.Background(),
|
||||
ID: zId,
|
||||
}
|
||||
@ -90,8 +85,8 @@ func enrollIdentity(zId string, client *rest_management_api_client.ZitiEdgeManag
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
func deleteIdentity(id string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
req := &identity_edge.DeleteIdentityParams{
|
||||
func DeleteIdentity(id string, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
req := &identity.DeleteIdentityParams{
|
||||
ID: id,
|
||||
Context: context.Background(),
|
||||
}
|
Loading…
Reference in New Issue
Block a user