This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from srinandan/clean
Clean unused integrations execute integrations
- Loading branch information
Showing
7 changed files
with
264 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// 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 | ||
// | ||
// 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 integrations | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/apigee/apigeecli/clilog" | ||
"github.com/srinandan/integrationcli/apiclient" | ||
) | ||
|
||
func Clean(name string, reportOnly bool, keepList []string) (err error) { | ||
|
||
var listOfVersions []basicIntegrationVersion | ||
var nextPage string | ||
|
||
apiclient.SetPrintOutput(false) | ||
for { | ||
respBody, err := ListVersions(name, -1, nextPage, "", "", false, false, true) | ||
if err != nil { | ||
return err | ||
} | ||
iversions := listbasicIntegrationVersions{} | ||
err = json.Unmarshal(respBody, &iversions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
listOfVersions = append(listOfVersions, iversions.BasicIntegrationVersions...) | ||
if iversions.NextPageToken == "" { | ||
break | ||
} | ||
nextPage = iversions.NextPageToken | ||
} | ||
|
||
if len(listOfVersions) == 0 { | ||
clilog.Warning.Println("no integration versions where found") | ||
return nil | ||
} | ||
|
||
for _, iversion := range listOfVersions { | ||
if iversion.State != "ACTIVE" { | ||
if reportOnly { | ||
fmt.Println("[REPORT]: Integration '" + name + "' Version: " + iversion.Version + " and Snapshot " + iversion.SnapshotNumber + " can be cleaned") | ||
} else { | ||
_, err = Delete(name, iversion.Version) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
} | ||
|
||
apiclient.SetPrintOutput(true) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// 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 | ||
// | ||
// 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 integrations | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/srinandan/integrationcli/apiclient" | ||
"github.com/srinandan/integrationcli/client/integrations" | ||
) | ||
|
||
// CleanCmd to delete integration versions | ||
var CleanCmd = &cobra.Command{ | ||
Use: "clean", | ||
Short: "Deletes undeployed/unused versions of an Integration", | ||
Long: "Deletes undeployed/unused versions of an Integration", | ||
Args: func(cmd *cobra.Command, args []string) (err error) { | ||
if err = apiclient.SetRegion(region); err != nil { | ||
return err | ||
} | ||
|
||
return apiclient.SetProjectID(project) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
return integrations.Clean(name, reportOnly, keepList) | ||
}, | ||
} | ||
|
||
var reportOnly bool | ||
var keepList []string | ||
|
||
func init() { | ||
CleanCmd.Flags().StringVarP(&name, "name", "n", | ||
"", "Integration name") | ||
CleanCmd.Flags().BoolVarP(&reportOnly, "report", "", | ||
true, "Report which integration snapshots will be deleted") | ||
CleanCmd.Flags().StringArrayVarP(&keepList, "keepList", "k", | ||
[]string{}, "List of snapshots to keep, -k 1 -k 2") | ||
|
||
_ = CleanCmd.MarkFlagRequired("name") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// 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 | ||
// | ||
// 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 integrations | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/srinandan/integrationcli/apiclient" | ||
"github.com/srinandan/integrationcli/client/integrations" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ExecuteCmd an Integration | ||
var ExecuteCmd = &cobra.Command{ | ||
Use: "execute", | ||
Short: "Execute an integration", | ||
Long: "execute an integration", | ||
Args: func(cmd *cobra.Command, args []string) (err error) { | ||
if err = apiclient.SetRegion(region); err != nil { | ||
return err | ||
} | ||
return apiclient.SetProjectID(project) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
|
||
if _, err := os.Stat(executionFile); os.IsNotExist(err) { | ||
return err | ||
} | ||
|
||
content, err := ioutil.ReadFile(executionFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = integrations.Execute(name, content) | ||
return | ||
|
||
}, | ||
} | ||
|
||
var executionFile string | ||
|
||
func init() { | ||
ExecuteCmd.Flags().StringVarP(&name, "name", "n", | ||
"", "Integration flow name") | ||
ExecuteCmd.Flags().StringVarP(&executionFile, "file", "f", | ||
"", "Integration flow JSON file path") | ||
|
||
_ = ExecuteCmd.MarkFlagRequired("name") | ||
_ = ExecuteCmd.MarkFlagRequired("file") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"triggerId": "api_trigger/fdic_API_1", | ||
"inputParameters": { | ||
"fdic_certificate_number": { | ||
"stringValue": "21314" | ||
} | ||
} | ||
} |