mirror of
https://github.com/hanzozt/zt.git
synced 2026-11-03 05:01:58 +00:00
* Changing export/import structs to allow running it without using a Cobra command * Switched away from using LoginOpts/Options out and err * Removed unused file property * Refactored input options and out/err handling * Refactored to remove public loginOpts in import and export * Fixed import * Fixed lint issue. Updated help * Removed verbose check around log statements * Switched some log statements to print to stderr for consistency * Refactored to remove specific output handling * Fixed lint issue * Refactor to use central client for both import and export
74 lines
2.3 KiB
Go
74 lines
2.3 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package exporter
|
|
|
|
import (
|
|
"github.com/openziti/edge-api/rest_management_api_client/edge_router"
|
|
"github.com/openziti/edge-api/rest_model"
|
|
"slices"
|
|
)
|
|
|
|
func (exporter Exporter) IsEdgeRouterExportRequired(args []string) bool {
|
|
return slices.Contains(args, "all") || len(args) == 0 || // explicit all or nothing specified
|
|
slices.Contains(args, "edge-router") ||
|
|
slices.Contains(args, "er")
|
|
}
|
|
|
|
func (exporter Exporter) GetEdgeRouters() ([]map[string]interface{}, error) {
|
|
|
|
return exporter.getEntities(
|
|
"EdgeRouters",
|
|
func() (int64, error) {
|
|
limit := int64(1)
|
|
resp, err := exporter.Client.EdgeRouter.ListEdgeRouters(&edge_router.ListEdgeRoutersParams{Limit: &limit}, nil)
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
return *resp.GetPayload().Meta.Pagination.TotalCount, nil
|
|
},
|
|
|
|
func(offset *int64, limit *int64) ([]interface{}, error) {
|
|
resp, err := exporter.Client.EdgeRouter.ListEdgeRouters(&edge_router.ListEdgeRoutersParams{Limit: limit, Offset: offset}, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
entities := make([]interface{}, len(resp.GetPayload().Data))
|
|
for i, c := range resp.GetPayload().Data {
|
|
entities[i] = interface{}(c)
|
|
}
|
|
return entities, nil
|
|
},
|
|
|
|
func(entity interface{}) (map[string]interface{}, error) {
|
|
|
|
item := entity.(*rest_model.EdgeRouterDetail)
|
|
|
|
// convert to a map of values
|
|
m, err := exporter.ToMap(item)
|
|
if err != nil {
|
|
log.WithError(err).Error("error converting EdgeRouter to map")
|
|
}
|
|
exporter.defaultRoleAttributes(m)
|
|
|
|
// filter unwanted properties
|
|
exporter.Filter(m, []string{"id", "_links", "createdAt", "updatedAt",
|
|
"cost", "fingerprint", "isVerified", "isOnline", "enrollmentJwt", "enrollmentCreatedAt", "enrollmentExpiresAt", "syncStatus", "versionInfo", "certPem", "supportedProtocols"})
|
|
|
|
return m, nil
|
|
})
|
|
}
|