diff --git a/controller/createFrontend.go b/controller/createFrontend.go index 9a7d22c0..648a8f25 100644 --- a/controller/createFrontend.go +++ b/controller/createFrontend.go @@ -28,7 +28,7 @@ func (h *createFrontendHandler) Handle(params admin.CreateFrontendParams, princi } zId := params.Body.ZID - detail, err := zrokEdgeSdk.GetIdentity(zId, client) + detail, err := zrokEdgeSdk.GetIdentityByZId(zId, client) if err != nil { logrus.Errorf("error getting identity details for '%v': %v", zId, err) return admin.NewCreateFrontendInternalServerError() diff --git a/controller/enable.go b/controller/enable.go index 2ea63dc5..a4dc153e 100644 --- a/controller/enable.go +++ b/controller/enable.go @@ -25,18 +25,14 @@ func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_ logrus.Errorf("error starting transaction: %v", err) return environment.NewEnableInternalServerError() } + defer func() { _ = tx.Rollback() }() client, err := edgeClient() if err != nil { logrus.Errorf("error getting edge client: %v", err) return environment.NewEnableInternalServerError() } - accountToken, err := createToken() - if err != nil { - logrus.Errorf("error creating account token: %v", err) - return environment.NewEnableInternalServerError() - } - ident, err := zrokEdgeSdk.CreateEnvironmentIdentity(principal.Email, accountToken, client) + ident, err := zrokEdgeSdk.CreateEnvironmentIdentity(principal.Email, params.Body.Description, client) if err != nil { logrus.Error(err) return environment.NewEnableInternalServerError() diff --git a/controller/zrokEdgeSdk/identity.go b/controller/zrokEdgeSdk/identity.go index 33bcaee0..e8859ebc 100644 --- a/controller/zrokEdgeSdk/identity.go +++ b/controller/zrokEdgeSdk/identity.go @@ -12,16 +12,16 @@ import ( "time" ) -func CreateEnvironmentIdentity(accountEmail, accountToken string, client *rest_management_api_client.ZitiEdgeManagement) (*identity.CreateIdentityCreated, error) { +func CreateEnvironmentIdentity(accountEmail, envDescription string, client *rest_management_api_client.ZitiEdgeManagement) (*identity.CreateIdentityCreated, error) { identityType := rest_model_edge.IdentityTypeUser moreTags := map[string]interface{}{"zrokEmail": accountEmail} - return CreateIdentity(accountToken, identityType, moreTags, client) + return CreateIdentity(envDescription, identityType, moreTags, client) } -func CreateIdentity(name string, identityType rest_model_edge.IdentityType, moreTags map[string]interface{}, client *rest_management_api_client.ZitiEdgeManagement) (*identity.CreateIdentityCreated, error) { +func CreateIdentity(name string, identityType rest_model_edge.IdentityType, addlTags map[string]interface{}, client *rest_management_api_client.ZitiEdgeManagement) (*identity.CreateIdentityCreated, error) { isAdmin := false tags := ZrokTags() - for k, v := range moreTags { + for k, v := range addlTags { tags.SubTags[k] = v } req := identity.NewCreateIdentityParams() @@ -42,7 +42,7 @@ func CreateIdentity(name string, identityType rest_model_edge.IdentityType, more return resp, nil } -func GetIdentity(zId string, client *rest_management_api_client.ZitiEdgeManagement) (*identity.ListIdentitiesOK, error) { +func GetIdentityByZId(zId string, client *rest_management_api_client.ZitiEdgeManagement) (*identity.ListIdentitiesOK, error) { filter := fmt.Sprintf("id=\"%v\"", zId) limit := int64(0) offset := int64(0) @@ -82,12 +82,13 @@ func EnrollIdentity(zId string, client *rest_management_api_client.ZitiEdgeManag if err != nil { return nil, err } + logrus.Infof("enrolled ziti identity '%v'", zId) return conf, nil } -func DeleteIdentity(id string, edge *rest_management_api_client.ZitiEdgeManagement) error { +func DeleteIdentity(zId string, edge *rest_management_api_client.ZitiEdgeManagement) error { req := &identity.DeleteIdentityParams{ - ID: id, + ID: zId, Context: context.Background(), } req.SetTimeout(30 * time.Second) @@ -95,6 +96,6 @@ func DeleteIdentity(id string, edge *rest_management_api_client.ZitiEdgeManageme if err != nil { return err } - logrus.Infof("deleted environment identity '%v'", id) + logrus.Infof("deleted ziti identity '%v'", zId) return nil }