zrok/controller/overview.go

55 lines
1.8 KiB
Go
Raw Normal View History

2022-08-03 20:58:11 +02:00
package controller
import (
"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/metadata"
2022-08-03 21:05:28 +02:00
"github.com/sirupsen/logrus"
2022-08-03 20:58:11 +02:00
)
func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Principal) middleware.Responder {
2022-08-03 21:05:28 +02:00
tx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
2022-09-26 22:35:06 +02:00
return metadata.NewOverviewInternalServerError()
2022-08-03 21:05:28 +02:00
}
defer func() { _ = tx.Rollback() }()
envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx)
if err != nil {
2022-09-09 16:20:05 +02:00
logrus.Errorf("error finding environments for '%v': %v", principal.Email, err)
2022-09-26 22:35:06 +02:00
return metadata.NewOverviewInternalServerError()
2022-08-03 21:05:28 +02:00
}
var out rest_model_zrok.EnvironmentServicesList
for _, env := range envs {
svcs, err := str.FindServicesForEnvironment(env.Id, tx)
if err != nil {
logrus.Errorf("error finding services for environment '%v': %v", env.ZitiIdentityId, err)
2022-09-26 22:35:06 +02:00
return metadata.NewOverviewInternalServerError()
2022-08-03 21:05:28 +02:00
}
es := &rest_model_zrok.EnvironmentServices{
Environment: &rest_model_zrok.Environment{
Active: env.Active,
Address: env.Address,
CreatedAt: env.CreatedAt.String(),
Description: env.Description,
Host: env.Host,
UpdatedAt: env.UpdatedAt.String(),
ZitiIdentityID: env.ZitiIdentityId,
},
}
for _, svc := range svcs {
es.Services = append(es.Services, &rest_model_zrok.Service{
Active: svc.Active,
CreatedAt: svc.CreatedAt.String(),
Frontend: svc.Frontend,
Backend: svc.Backend,
2022-08-03 21:05:28 +02:00
UpdatedAt: svc.UpdatedAt.String(),
ZitiServiceID: svc.ZitiServiceId,
ZrokServiceID: svc.ZrokServiceId,
2022-08-03 21:05:28 +02:00
})
}
out = append(out, es)
}
return metadata.NewOverviewOK().WithPayload(out)
2022-08-03 20:58:11 +02:00
}