2022-08-03 20:58:11 +02:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-openapi/runtime/middleware"
|
2023-01-13 21:01:34 +01:00
|
|
|
"github.com/openziti/zrok/rest_model_zrok"
|
|
|
|
"github.com/openziti/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
|
|
|
}
|
2023-01-04 19:43:37 +01:00
|
|
|
var out rest_model_zrok.EnvironmentSharesList
|
2022-08-03 21:05:28 +02:00
|
|
|
for _, env := range envs {
|
2023-01-04 19:13:50 +01:00
|
|
|
shrs, err := str.FindSharesForEnvironment(env.Id, tx)
|
2022-08-03 21:05:28 +02:00
|
|
|
if err != nil {
|
2023-01-04 20:21:23 +01:00
|
|
|
logrus.Errorf("error finding shares for environment '%v': %v", env.ZId, err)
|
2022-09-26 22:35:06 +02:00
|
|
|
return metadata.NewOverviewInternalServerError()
|
2022-08-03 21:05:28 +02:00
|
|
|
}
|
2023-01-04 19:43:37 +01:00
|
|
|
es := &rest_model_zrok.EnvironmentShares{
|
2022-10-19 21:21:15 +02:00
|
|
|
Environment: &rest_model_zrok.Environment{
|
|
|
|
Address: env.Address,
|
2022-11-01 21:52:02 +01:00
|
|
|
CreatedAt: env.CreatedAt.UnixMilli(),
|
2022-10-19 21:21:15 +02:00
|
|
|
Description: env.Description,
|
|
|
|
Host: env.Host,
|
2022-11-01 21:52:02 +01:00
|
|
|
UpdatedAt: env.UpdatedAt.UnixMilli(),
|
2022-10-19 21:21:15 +02:00
|
|
|
ZID: env.ZId,
|
|
|
|
},
|
|
|
|
}
|
2022-12-07 18:24:00 +01:00
|
|
|
|
2023-01-04 19:13:50 +01:00
|
|
|
for _, shr := range shrs {
|
2022-12-01 18:54:14 +01:00
|
|
|
feEndpoint := ""
|
2023-01-04 19:13:50 +01:00
|
|
|
if shr.FrontendEndpoint != nil {
|
|
|
|
feEndpoint = *shr.FrontendEndpoint
|
2022-11-22 17:14:58 +01:00
|
|
|
}
|
2022-12-01 18:54:14 +01:00
|
|
|
feSelection := ""
|
2023-01-04 19:13:50 +01:00
|
|
|
if shr.FrontendSelection != nil {
|
|
|
|
feSelection = *shr.FrontendSelection
|
2022-12-01 18:54:14 +01:00
|
|
|
}
|
|
|
|
beProxyEndpoint := ""
|
2023-01-04 19:13:50 +01:00
|
|
|
if shr.BackendProxyEndpoint != nil {
|
|
|
|
beProxyEndpoint = *shr.BackendProxyEndpoint
|
2022-11-22 17:14:58 +01:00
|
|
|
}
|
2023-01-04 19:43:37 +01:00
|
|
|
es.Shares = append(es.Shares, &rest_model_zrok.Share{
|
2023-01-04 19:13:50 +01:00
|
|
|
Token: shr.Token,
|
|
|
|
ZID: shr.ZId,
|
|
|
|
ShareMode: shr.ShareMode,
|
|
|
|
BackendMode: shr.BackendMode,
|
2022-12-01 18:54:14 +01:00
|
|
|
FrontendSelection: feSelection,
|
|
|
|
FrontendEndpoint: feEndpoint,
|
|
|
|
BackendProxyEndpoint: beProxyEndpoint,
|
2023-01-04 19:13:50 +01:00
|
|
|
Reserved: shr.Reserved,
|
|
|
|
CreatedAt: shr.CreatedAt.UnixMilli(),
|
|
|
|
UpdatedAt: shr.UpdatedAt.UnixMilli(),
|
2022-10-19 21:21:15 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
out = append(out, es)
|
|
|
|
}
|
|
|
|
return metadata.NewOverviewOK().WithPayload(out)
|
|
|
|
}
|