imjoey commented on a change in pull request #1893: URL: https://github.com/apache/apisix-dashboard/pull/1893#discussion_r647050081
########## File path: api/internal/core/migrate/migrate.go ########## @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * + * http://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 migrate + +import ( + "context" + "encoding/json" + "errors" + + "github.com/apisix/manager-api/internal/core/store" + "github.com/apisix/manager-api/internal/log" +) + +var ( + ErrConflict = errors.New("conflict") +) + +func Export(ctx context.Context) ([]byte, error) { + exportData := newDataSet() + store.RangeStore(func(key store.HubKey, s *store.GenericStore) bool { + s.Range(ctx, func(_ string, obj interface{}) bool { + err := exportData.Add(obj) + if err != nil { + log.Errorf("Add obj to export list failed:%s", err) + return true + } + return true + }) + return true + }) + + data, err := json.Marshal(exportData) + if err != nil { + return nil, err + } + + return data, nil +} + +type ConflictMode int + +const ( + ModeReturn ConflictMode = iota + ModeOverwrite + ModeSkip +) + +func Import(ctx context.Context, data []byte, mode ConflictMode) (*DataSet, error) { + importData := newDataSet() + err := json.Unmarshal(data, &importData) + if err != nil { + return nil, err + } + conflict, conflictData := isConflicted(ctx, importData) + if conflict && mode == ModeReturn { Review comment: @fregie shall we use `&` here? ########## File path: docs/en/latest/api/api.md ########## @@ -25,6 +25,44 @@ Manager API directly operates ETCD and provides data management for Apache APISI **License:** [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) +### /apisix/admin/migrate/export + +#### GET + +##### Summary: + +Export a config file for migrate. Review comment: @fregie The current implementation seems not to consider that compatibility among different versions of resource objects. So shall we provide a clear notice to tell users that which version of APISIX this functionality works from? Thanks. ########## File path: docs/en/latest/api/api.md ########## @@ -25,6 +25,44 @@ Manager API directly operates ETCD and provides data management for Apache APISI **License:** [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) +### /apisix/admin/migrate/export + +#### GET + +##### Summary: + +Export a config file for migrate. + +##### Parameters + +None. + +##### Responses + +A file for download. + +### /apisix/admin/migrate/import + +##### Summary: + +Import the config file for restore config. + +#### POST + +##### Parameters (FORM) Review comment: @fregie As current APIs provided by manager-api are all of RESTful-JSON, instead of FORM. Please also see OpenAPI export/import APIs for example. So how about we also add support for that format? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
