Skip to content

Commit 304d67a

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #688 from Edson-Rios/issue687
Added new command `ibmcloud sl cdn origin-remove`
2 parents accaabf + aabc8b3 commit 304d67a

7 files changed

Lines changed: 190 additions & 0 deletions

File tree

plugin/commands/cdn/cdn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func SetupCobraCommands(sl *metadata.SoftlayerCommand) *cobra.Command {
1616
}
1717
cobraCmd.AddCommand(NewListCommand(sl).Command)
1818
cobraCmd.AddCommand(NewDeleteCommand(sl).Command)
19+
cobraCmd.AddCommand(NewOriginRemoveCommand(sl).Command)
1920
cobraCmd.AddCommand(NewDetailCommand(sl).Command)
2021
cobraCmd.AddCommand(NewEditCommand(sl).Command)
2122
cobraCmd.AddCommand(NewOriginListCommand(sl).Command)

plugin/commands/cdn/cdn_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestManagers(t *testing.T) {
1919

2020
var availableCommands = []string{
2121
"detail",
22+
"origin-remove",
2223
"delete",
2324
"edit",
2425
"list",
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package cdn
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/errors"
7+
. "github.ibm.com/SoftLayer/softlayer-cli/plugin/i18n"
8+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/managers"
9+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
10+
)
11+
12+
type OriginRemoveCommand struct {
13+
*metadata.SoftlayerCommand
14+
CdnManager managers.CdnManager
15+
Command *cobra.Command
16+
}
17+
18+
func NewOriginRemoveCommand(sl *metadata.SoftlayerCommand) *OriginRemoveCommand {
19+
thisCmd := &OriginRemoveCommand{
20+
SoftlayerCommand: sl,
21+
CdnManager: managers.NewCdnManager(sl.Session),
22+
}
23+
cobraCmd := &cobra.Command{
24+
Use: "origin-remove " + T("IDENTIFIER") + " " + T("PATH"),
25+
Short: T("Removes an origin path for an existing CDN mapping."),
26+
Long: T(`${COMMAND_NAME} sl cdn origin-remove
27+
Example:
28+
${COMMAND_NAME} sl cdn origin-remove 123456789 "/path/*"`),
29+
Args: metadata.TwoArgs,
30+
RunE: func(cmd *cobra.Command, args []string) error {
31+
return thisCmd.Run(args)
32+
},
33+
}
34+
thisCmd.Command = cobraCmd
35+
return thisCmd
36+
}
37+
38+
func (cmd *OriginRemoveCommand) Run(args []string) error {
39+
cdnId := args[0]
40+
path := args[1]
41+
42+
_, err := cmd.CdnManager.RemoveOrigin(cdnId, path)
43+
if err != nil {
44+
return errors.NewAPIError(T("Failed to delete origin."), err.Error(), 2)
45+
}
46+
47+
cmd.UI.Ok()
48+
cmd.UI.Print(T("The origin {{.Id}} with path {{.Path}} was deleted.", map[string]interface{}{"Path": path, "Id": cdnId}))
49+
return nil
50+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package cdn_test
2+
3+
import (
4+
"github.com/IBM-Cloud/ibm-cloud-cli-sdk/testhelpers/terminal"
5+
. "github.com/onsi/ginkgo"
6+
. "github.com/onsi/gomega"
7+
"github.com/softlayer/softlayer-go/session"
8+
9+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/commands/cdn"
10+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/metadata"
11+
"github.ibm.com/SoftLayer/softlayer-cli/plugin/testhelpers"
12+
)
13+
14+
var _ = Describe("Cdn origin-remove", func() {
15+
var (
16+
fakeUI *terminal.FakeUI
17+
cliCommand *cdn.OriginRemoveCommand
18+
fakeSession *session.Session
19+
slCommand *metadata.SoftlayerCommand
20+
)
21+
BeforeEach(func() {
22+
fakeUI = terminal.NewFakeUI()
23+
fakeSession = testhelpers.NewFakeSoftlayerSession([]string{})
24+
slCommand = metadata.NewSoftlayerCommand(fakeUI, fakeSession)
25+
cliCommand = cdn.NewOriginRemoveCommand(slCommand)
26+
cliCommand.Command.PersistentFlags().Var(cliCommand.OutputFlag, "output", "--output=JSON for json output.")
27+
})
28+
29+
Describe("Cdn origin-remove", func() {
30+
Context("Cdn origin-remove, Invalid Usage", func() {
31+
It("Set command without id and path", func() {
32+
err := testhelpers.RunCobraCommand(cliCommand.Command)
33+
Expect(err).To(HaveOccurred())
34+
Expect(err.Error()).To(ContainSubstring("Incorrect Usage: This command requires two argument"))
35+
})
36+
})
37+
38+
Context("Cdn origin-remove, correct use", func() {
39+
It("return cdn origin-remove", func() {
40+
err := testhelpers.RunCobraCommand(cliCommand.Command, "123456", "/path/*")
41+
Expect(err).NotTo(HaveOccurred())
42+
Expect(fakeUI.Outputs()).To(ContainSubstring("The origin"))
43+
Expect(fakeUI.Outputs()).To(ContainSubstring("was deleted."))
44+
})
45+
})
46+
})
47+
})

plugin/managers/cdn.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
type CdnManager interface {
1515
GetNetworkCdnMarketplaceConfigurationMapping() ([]datatypes.Container_Network_CdnMarketplace_Configuration_Mapping, error)
1616
DeleteCDN(uniqueId string) ([]datatypes.Container_Network_CdnMarketplace_Configuration_Mapping, error)
17+
RemoveOrigin(uniqueId string, path string) (string, error)
1718
GetDetailCDN(uniqueId int, mask string) (datatypes.Container_Network_CdnMarketplace_Configuration_Mapping, error)
1819
GetUsageMetrics(uniqueId int, history int, mask string) (datatypes.Container_Network_CdnMarketplace_Metrics, error)
1920
GetOrigins(uniqueId string) ([]datatypes.Container_Network_CdnMarketplace_Configuration_Mapping_Path, error)
@@ -65,6 +66,14 @@ func (a cdnManager) DeleteCDN(uniqueId string) ([]datatypes.Container_Network_Cd
6566
return a.CdnService.Mask(mask).DeleteDomainMapping(&uniqueId)
6667
}
6768

69+
/*
70+
Removes an origin path for an existing CDN mapping.
71+
https://sldn.softlayer.com/reference/services/SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path/deleteOriginPath/
72+
*/
73+
func (a cdnManager) RemoveOrigin(uniqueId string, path string) (string, error) {
74+
return a.CdnPathService.DeleteOriginPath(&uniqueId, &path)
75+
}
76+
6877
/*
6978
Gets the total number of predetermined statistics for direct display for the given mapping.
7079
https://sldn.softlayer.com/reference/services/SoftLayer_Network_CdnMarketplace_Metrics/getMappingUsageMetrics/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"Status [200]: Path \/test\/* has been deleted."

plugin/testhelpers/fake_cdn_manager.go

Lines changed: 81 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)