Skip to content
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

feat: adds support to import apidocs into new orgs #357 #360

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions cmd/apidocs/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,40 @@ import (
"github.com/spf13/cobra"
)

/**
How the useNewSiteID flag works:
Assume data is exported from org1 which contains siteid site1. The fles are exported as
site_org1-site1.json and apidocs_org1-site1_00000.json

When importing this data into a new org, the siteid changes (since it is a combination of
org name and siteid).

Now import the data to org2 as
apigeecli apidocs import -o org2 -s site1 --source-f . --use-new-siteid=true -t $token
*/

// ImpCmd to import products
var ImpCmd = &cobra.Command{
Use: "import",
Short: "Import from a folder containing apidocs",
Long: "Import from a folder containing apidocs",
Args: func(cmd *cobra.Command, args []string) (err error) {
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) error {
if siteid == "" {
return fmt.Errorf("siteid is a mandatory parameter")
}
return apidocs.Import(siteid, folder)
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) error {
return apidocs.Import(siteid, useSrcSiteID, folder)
},
}

var useSrcSiteID string

func init() {
ImpCmd.Flags().StringVarP(&folder, "folder", "f",
"", "Folder containing site_<siteid>.json and apidocs_<siteid>_<id>.json files")

ImpCmd.Flags().StringVarP(&useSrcSiteID, "use-src-siteid", "",
"", "Use source siteid when importing; useful whem importing data between two orgs")
_ = ImpCmd.MarkFlagRequired("folder")
}
31 changes: 28 additions & 3 deletions internal/client/apidocs/apidocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,29 @@ func Export(folder string) (err error) {
return nil
}

func Import(siteid string, folder string) (err error) {
/**
How the useNewSiteID flag works:
Assume data is exported from org1 which contains siteid site1. The fles are exported as
site_org1-site1.json and apidocs_org1-site1_00000.json

When importing this data into a new org, the siteid changes (since it is a combination of
org name and siteid).

Now import the data to org2 as
apigeecli apidocs import -o org2 -s site1 --source-f . --use-new-siteid=true -t $token
*/

// Import
func Import(siteid string, useSrcSiteID string, folder string) (err error) {
var errs []string
var respBody []byte
docsList, err := readAPIDocsDataFile(path.Join(folder, "site_"+siteid+".json"))
var docsList []data

if useSrcSiteID != "" {
docsList, err = readAPIDocsDataFile(path.Join(folder, "site_"+useSrcSiteID+".json"))
} else {
docsList, err = readAPIDocsDataFile(path.Join(folder, "site_"+siteid+".json"))
}
if err != nil {
return err
}
Expand All @@ -363,7 +382,13 @@ func Import(siteid string, folder string) (err error) {
}

// 2. find the documentation associated with this site
documentationFileName := path.Join(folder, "apidocs_"+siteid+"_"+doc.ID+".json")
var documentationFileName string
if useSrcSiteID != "" {
apiDocsName := fmt.Sprintf("apidocs_%s_%s.json", useSrcSiteID, doc.ID)
documentationFileName = path.Join(folder, apiDocsName)
} else {
documentationFileName = path.Join(folder, "apidocs_"+siteid+"_"+doc.ID+".json")
}
apidocument, err := readAPIDocumentationFile(documentationFileName)
if err != nil {
errs = append(errs, err.Error())
Expand Down
3 changes: 2 additions & 1 deletion internal/client/apps/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func GetKey(developerEmail string, appID string, key string) (respBody []byte, e

// UpdateKey
func UpdateKey(developerEmail string, appID string, consumerKey string,
apiProducts []string, scopes []string, attrs map[string]string) (respBody []byte, err error) {
apiProducts []string, scopes []string, attrs map[string]string,
) (respBody []byte, err error) {
u, _ := url.Parse(apiclient.BaseURL)

key := []string{}
Expand Down