improvements to zrok_sdk_edge for identities (#112)

This commit is contained in:
Michael Quigley 2022-12-14 14:57:55 -05:00
parent c9c4ca6c49
commit 0fe55e8213
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 12 additions and 15 deletions

View File

@ -28,7 +28,7 @@ func (h *createFrontendHandler) Handle(params admin.CreateFrontendParams, princi
} }
zId := params.Body.ZID zId := params.Body.ZID
detail, err := zrokEdgeSdk.GetIdentity(zId, client) detail, err := zrokEdgeSdk.GetIdentityByZId(zId, client)
if err != nil { if err != nil {
logrus.Errorf("error getting identity details for '%v': %v", zId, err) logrus.Errorf("error getting identity details for '%v': %v", zId, err)
return admin.NewCreateFrontendInternalServerError() return admin.NewCreateFrontendInternalServerError()

View File

@ -25,18 +25,14 @@ func (h *enableHandler) Handle(params environment.EnableParams, principal *rest_
logrus.Errorf("error starting transaction: %v", err) logrus.Errorf("error starting transaction: %v", err)
return environment.NewEnableInternalServerError() return environment.NewEnableInternalServerError()
} }
defer func() { _ = tx.Rollback() }()
client, err := edgeClient() client, err := edgeClient()
if err != nil { if err != nil {
logrus.Errorf("error getting edge client: %v", err) logrus.Errorf("error getting edge client: %v", err)
return environment.NewEnableInternalServerError() return environment.NewEnableInternalServerError()
} }
accountToken, err := createToken() ident, err := zrokEdgeSdk.CreateEnvironmentIdentity(principal.Email, params.Body.Description, client)
if err != nil {
logrus.Errorf("error creating account token: %v", err)
return environment.NewEnableInternalServerError()
}
ident, err := zrokEdgeSdk.CreateEnvironmentIdentity(principal.Email, accountToken, client)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
return environment.NewEnableInternalServerError() return environment.NewEnableInternalServerError()

View File

@ -12,16 +12,16 @@ import (
"time" "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 identityType := rest_model_edge.IdentityTypeUser
moreTags := map[string]interface{}{"zrokEmail": accountEmail} 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 isAdmin := false
tags := ZrokTags() tags := ZrokTags()
for k, v := range moreTags { for k, v := range addlTags {
tags.SubTags[k] = v tags.SubTags[k] = v
} }
req := identity.NewCreateIdentityParams() req := identity.NewCreateIdentityParams()
@ -42,7 +42,7 @@ func CreateIdentity(name string, identityType rest_model_edge.IdentityType, more
return resp, nil 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) filter := fmt.Sprintf("id=\"%v\"", zId)
limit := int64(0) limit := int64(0)
offset := int64(0) offset := int64(0)
@ -82,12 +82,13 @@ func EnrollIdentity(zId string, client *rest_management_api_client.ZitiEdgeManag
if err != nil { if err != nil {
return nil, err return nil, err
} }
logrus.Infof("enrolled ziti identity '%v'", zId)
return conf, nil 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{ req := &identity.DeleteIdentityParams{
ID: id, ID: zId,
Context: context.Background(), Context: context.Background(),
} }
req.SetTimeout(30 * time.Second) req.SetTimeout(30 * time.Second)
@ -95,6 +96,6 @@ func DeleteIdentity(id string, edge *rest_management_api_client.ZitiEdgeManageme
if err != nil { if err != nil {
return err return err
} }
logrus.Infof("deleted environment identity '%v'", id) logrus.Infof("deleted ziti identity '%v'", zId)
return nil return nil
} }