Skip to content

Commit

Permalink
Add file keys import command
Browse files Browse the repository at this point in the history
  • Loading branch information
johannac committed Oct 2, 2018
1 parent c0222c8 commit cc64539
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions command-bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var commandLocator akamai.CommandLocator = func() ([]cli.Command, error) {
commandCreateCollection,
commandUpdateCollectionAcl,
commandAddCollectionKey,
commandKeysImport,
}

return commands, nil
Expand Down
62 changes: 62 additions & 0 deletions command-keys-import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2018. Akamai Technologies, Inc
//
// 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 main

import (
"fmt"

api "github.com/akamai/AkamaiOPEN-edgegrid-golang/apikey-manager-v1"
akamai "github.com/akamai/cli-common-golang"

"github.com/fatih/color"
"github.com/urfave/cli"
)

var commandKeysImport cli.Command = cli.Command{
Name: "import-keys",
ArgsUsage: "",
Description: "This operation imports keys from a file to a key collection. Accepted formats are XML, CSV, JSON",
HideHelp: true,
Action: callKeysImport,
Flags: []cli.Flag{
cli.IntFlag{
Name: "collection",
Usage: "The collection ID to modify.",
},
cli.StringFlag{
Name: "filename",
Usage: "The name of the file to import.",
},
},
}

func callKeysImport(c *cli.Context) error {
err := initConfig(c)
if err != nil {
return cli.NewExitError(color.RedString(err.Error()), 1)
}

akamai.StartSpinner(
"Importing keys to collection...",
fmt.Sprintf("Importing keys to collection...... [%s]", color.GreenString("OK")),
)

keys, err := api.CollectionImportKeys(
c.Int("collection"),
c.String("filename"),
)

return output(c, keys, err)
}
10 changes: 10 additions & 0 deletions examples/keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"value": "1234",
"label": "Test 1"
},
{
"value": "5678",
"label": "Test 2"
}
]

0 comments on commit cc64539

Please sign in to comment.