-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2515 Adding import and export #2571
base: main
Are you sure you want to change the base?
Conversation
@@ -102,6 +102,8 @@ require ( | |||
github.com/MichaelMure/go-term-text v0.3.1 // indirect | |||
github.com/alecthomas/chroma v0.10.0 // indirect | |||
github.com/andybalholm/brotli v1.1.0 // indirect | |||
github.com/antchfx/jsonquery v1.3.6 // indirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these dependencies necessary? Maybe we can discuss?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's used to select specific nodes out of the file input and it's used in the tests to compare the json outcomes.
@@ -200,6 +200,7 @@ func (o *QuickstartOpts) run(ctx context.Context) { | |||
tmpDir, _ := os.MkdirTemp("", "quickstart") | |||
o.Home = tmpDir | |||
o.cleanOnExit = true | |||
logrus.Infof("temporary --home '%s'", o.Home) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably unintentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is the counterpart to a log statement in the else which logs the permanent home in a similar way
@@ -145,6 +147,8 @@ func NewCmdRoot(in io.Reader, out, err io.Writer, cmd *cobra.Command) *cobra.Com | |||
opsCommands.AddCommand(NewUnwrapIdentityFileCommand(out, err)) | |||
opsCommands.AddCommand(verify.NewVerifyNetwork(out, err)) | |||
opsCommands.AddCommand(verify.NewVerifyTraffic(out, err)) | |||
opsCommands.AddCommand(download.NewDownloadCmd(out, err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to Import/Export to keep consistent pls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import
is a protected word so i can't unless you have a different suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewImportCmd
/NewExportCmd
|
||
type CacheGetter func(id string) (interface{}, error) | ||
|
||
func GetItemFromCache(c *cache.Cache, key string, fn CacheGetter) (interface{}, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use a map and remove this and the dependencies? This "doing" something?
log.Errorf("Could not obtain an ID for the service policy with filter %s: %v", filter, err) | ||
return nil | ||
} | ||
if resp == nil || resp.Payload == nil || resp.Payload.Data == nil || len(resp.Payload.Data) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if resp == nil || resp.Payload == nil || resp.Payload.Data == nil || len(resp.Payload.Data) == 0 {
is repeated verbatim a few times (10). Feels like a candidate to make a small validator function to me
Filter: &filter, | ||
Context: context.Background(), | ||
} | ||
params.SetTimeout(5 * time.Second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these 5 * time.Second
should at very least references a single constant. might be worthwhile making it configurable some day (not now)
return | ||
} | ||
|
||
externalJwtSigner1 := jsonquery.FindOne(doc, "//externalJwtSigners/*[name='NetFoundry Console Integration External JWT Signer']") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you add a test case for whatever the issue was with "handling missing identities" from 498c206 ?
type Download struct { | ||
loginOpts edge.LoginOptions | ||
client *rest_management_api_client.ZitiEdgeManagement | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you remove the whitespace so these things sort alphabetically and are indented similarly?
loginOpts edge.LoginOptions | ||
client *rest_management_api_client.ZitiEdgeManagement | ||
|
||
verbose bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is covered in edge.LoginOptions
but it's Verbose
there. pls remove
authPolicyCache *cache.Cache | ||
externalJwtCache *cache.Cache | ||
|
||
Out io.Writer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also covered in edge.LoginOptions
i believe, no?
|
||
var output Output | ||
|
||
func NewDownload(loginOpts edge.LoginOptions, client *rest_management_api_client.ZitiEdgeManagement, ofJson bool, ofYaml bool, file *os.File, filename string) Download { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be removed. this isn't idiomatic go. Since Download is public, people can just make a new struct just like you did and set all the things on their own.
result := map[string]interface{}{} | ||
|
||
all := slices.Contains(args, "all") || len(args) == 0 | ||
if all || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole section is confusing to the 'first time reader' (me). Can we discuss what's going on here with these or's?
if all || | ||
slices.Contains(args, "ca") || slices.Contains(args, "cas") || | ||
slices.Contains(args, "certificate-authority") || slices.Contains(args, "certificate-authorities") { | ||
if d.verbose { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if d.verbose is not needed. simply call log.debug. same comment -- multiple instances
} | ||
cas, err := d.GetCertificateAuthorities() | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean it stops at the first error? that could be .... annoying if it takes a while for this to run?
"github.com/openziti/ziti/internal" | ||
"github.com/openziti/ziti/internal/rest/mgmt" | ||
"github.com/openziti/ziti/ziti/cmd/edge" | ||
c "github.com/openziti/ziti/ziti/constants" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was there another "constants" that needed to be aliased?
|
||
// convert to a map of values | ||
m := d.ToMap(item) | ||
d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"})
seems like a good candidate to refactor imo
|
||
// filter unwanted properties | ||
d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt", | ||
"edgeRouterRolesDisplay", "identityRolesDisplay", "isSystem"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"isSystem" is really something we would want to filter? should any "system" entities be exported/imported at all?
m := d.ToMap(item) | ||
|
||
// filter unwanted properties | ||
d.Filter(m, []string{"id", "_links", "createdAt", "updatedAt"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CAs should probably come along with a warning, indicating the user is going to need to re-verify the CA on import. it might be there, but if not, that should be added to avoid the confusion when they import and the ca is not "verified"
"github.com/openziti/edge-api/rest_management_api_client/config" | ||
"github.com/openziti/edge-api/rest_management_api_client/service" | ||
"github.com/openziti/edge-api/rest_model" | ||
common "github.com/openziti/ziti/internal/ascode" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as a reader, it feels like it would be better to see all these "common" aliases removed in favor of using "ascode".
client *rest_management_api_client.ZitiEdgeManagement | ||
reader Reader | ||
|
||
verbose bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the same comments as on Export (also rename to Import/Export? which are not reserved as they are capitalized)
|
||
cmd := &cobra.Command{ | ||
Use: "export [entity]", | ||
Short: "Export Ziti entities", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mind removing the " ziti " parts of these descriptions? We know it's a ziti entity :)
authPolicies := map[string]string{} | ||
if all || | ||
slices.Contains(args, "auth-policy") || slices.Contains(args, "auth-policies") || | ||
slices.Contains(args, "identity") || slices.Contains(args, "identities") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i feel like these or's should be changed into functions and tests added for them...
- IdentitiesNeeded(args)
- AuthPoliciesNeeded(args)
- ServicesNeeded(args)
etc. i think it'll clean up the or's and it'll make it testable
Support in the cli to import entities into a network and exporting entities from a network. Supports both json and yaml.
closes #2515