Skip to content

Commit

Permalink
Merge pull request #57 from thebsdbox/collection_delete
Browse files Browse the repository at this point in the history
delete an existing collection
  • Loading branch information
thebsdbox committed Jul 11, 2018
2 parents ee5001b + 6115554 commit 64a4f23
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cmd/ucp_collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func init() {
ucpCollectionsCreate.Flags().StringVar(&name, "name", "", "Name of new collection")
ucpCollectionsCreate.Flags().StringVar(&parentID, "parent", "", "The ID of the parent collection")

ucpCollectionsDelete.Flags().StringVar(&name, "id", "", "ID of the collection to delete")

ucpCollectionsSet.Flags().StringVar(&name, "id", "", "The ID of the collection to update")

ucpCollectionsSet.Flags().StringVar(&newConstraint.LabelKey, "key", "", "The ID of the parent collection")
Expand All @@ -33,6 +35,8 @@ func init() {
ucpAuth.AddCommand(ucpCollections)

ucpCollections.AddCommand(ucpCollectionsCreate)
ucpCollections.AddCommand(ucpCollectionsDelete)

ucpCollections.AddCommand(ucpCollectionsList)
ucpCollections.AddCommand(ucpCollectionsGet)
ucpCollections.AddCommand(ucpCollectionsSet)
Expand Down Expand Up @@ -99,6 +103,29 @@ var ucpCollectionsCreate = &cobra.Command{
},
}

var ucpCollectionsDelete = &cobra.Command{
Use: "delete",
Short: "Delete a Docker EE Collection",
Run: func(cmd *cobra.Command, args []string) {
log.SetLevel(log.Level(logLevel))
if name == "" {
cmd.Help()
log.Fatalf("No collection ID specified")
}

client, err := ucp.ReadToken()
if err != nil {
log.Fatalf("%v", err)
}
err = client.DeleteCollection(name)
if err != nil {
log.Fatalf("%v", err)
}
log.Infof("Succesfully delete collection [%s]", name)

},
}

var ucpCollectionsGet = &cobra.Command{
Use: "get",
Short: "Get information about a Docker EE Collection",
Expand Down
15 changes: 15 additions & 0 deletions pkg/ucp/ucpCollections.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ func (c *Client) CreateCollection(name, parentID string) error {
return nil
}

// DeleteCollection - This will get all accounts
func (c *Client) DeleteCollection(collectionID string) error {
// Build the URL (TODO set limit)

url := fmt.Sprintf("%s/collections/%s", c.UCPURL, collectionID)

log.Debugf("Built URL [%s]", url)
_, err := c.delRequest(url, nil)
if err != nil {
return err
}

return nil
}

// GetCollection - This will get all accounts
func (c *Client) GetCollection(collectionID string) (*ucptypes.Collection, error) {
// Build the URL (TODO set limit)
Expand Down

0 comments on commit 64a4f23

Please sign in to comment.