Skip to content

Commit

Permalink
Merge pull request #105 from apigee/issue104
Browse files Browse the repository at this point in the history
import sharedflows from folder
  • Loading branch information
srinandan authored Oct 31, 2022
2 parents 1d43b2e + 31f0e95 commit 5f84694
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
46 changes: 41 additions & 5 deletions cmd/sharedflows/crtsf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,70 @@
package sharedflows

import (
"fmt"
"os"
"path"

"github.com/apigee/apigeecli/apiclient"
"github.com/apigee/apigeecli/bundlegen/proxybundle"
"github.com/apigee/apigeecli/client/sharedflows"
"github.com/spf13/cobra"
)

//Cmd to create shared flow
// Cmd to create shared flow
var CreateCmd = &cobra.Command{
Use: "create",
Short: "Creates a sharedflow in an Apigee Org",
Long: "Creates a sharedflow in an Apigee Org",
Args: func(cmd *cobra.Command, args []string) (err error) {
apiclient.SetApigeeEnv(env)
if sfZip != "" && sfFolder != "" {
return fmt.Errorf("sharedflow bundle (zip) and folder to a sharedflow cannot be combined")
}
if sfZip == "" && sfFolder == "" {
return fmt.Errorf("either sharedflow bundle (zip) or folder must be specified, not both")
}
if sfFolder != "" {
if _, err := os.Stat(sfFolder); os.IsNotExist(err) {
return err
}
}
return apiclient.SetApigeeOrg(org)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
_, err = sharedflows.Create(name, proxy)
if sfZip != "" {
_, err = sharedflows.Create(name, sfZip)
} else if sfFolder != "" {
tmpDir, err := os.MkdirTemp("", "sf")
if err != nil {
return err
}
defer os.RemoveAll(tmpDir)

sfBundlePath := path.Join(tmpDir, name+".zip")

if err = proxybundle.GenerateArchiveBundle(sfFolder, sfBundlePath); err != nil {
return err
}
if _, err = sharedflows.Create(name, sfBundlePath); err != nil {
return err
}
return os.Remove(sfBundlePath)
}
return
},
}

var proxy string
var sfZip, sfFolder string

func init() {

CreateCmd.Flags().StringVarP(&name, "name", "n",
"", "Sharedflow name")
CreateCmd.Flags().StringVarP(&proxy, "proxy", "p",
"", "Sharedflow bundle path")
CreateCmd.Flags().StringVarP(&sfZip, "sf-zip", "p",
"", "Path to the Sharedflow bundle/zip file")
CreateCmd.Flags().StringVarP(&sfFolder, "sf-zip-folder", "f",
"", "Path to the Sharedflow Bundle; ex: ./test/sharedflowbundle")

_ = CreateCmd.MarkFlagRequired("name")
}
6 changes: 6 additions & 0 deletions test/sharedflowbundle/policies/Verify-API-Key-1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VerifyAPIKey continueOnError="false" enabled="true" name="Verify-API-Key-1">
<DisplayName>Verify API Key-1</DisplayName>
<Properties/>
<APIKey ref="request.queryparam.apikey"/>
</VerifyAPIKey>
6 changes: 6 additions & 0 deletions test/sharedflowbundle/sharedflows/default.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SharedFlow name="default">
<Step>
<Name>Verify-API-Key-1</Name>
</Step>
</SharedFlow>
13 changes: 13 additions & 0 deletions test/sharedflowbundle/test_flow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<SharedFlowBundle revision="3" name="test_flow">
<DisplayName>test_flow</DisplayName>
<Description>undefined</Description>
<CreatedAt>1611207547050</CreatedAt>
<LastModifiedAt>1667066833526</LastModifiedAt>
<Policies>
<Policy>Verify-API-Key-1</Policy>
</Policies>
<SharedFlows>
<SharedFlow>default</SharedFlow>
</SharedFlows>
<subType>SharedFlow</subType>
</SharedFlowBundle>

0 comments on commit 5f84694

Please sign in to comment.