...

Source file src/github.com/sassoftware/relic/cmdline/remotecmd/listkeyscmd.go

Documentation: github.com/sassoftware/relic/cmdline/remotecmd

     1  //
     2  // Copyright (c) SAS Institute Inc.
     3  //
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  //     http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package remotecmd
    18  
    19  import (
    20  	"encoding/json"
    21  	"fmt"
    22  	"io/ioutil"
    23  
    24  	"github.com/sassoftware/relic/cmdline/shared"
    25  
    26  	"github.com/spf13/cobra"
    27  )
    28  
    29  var ListKeysCmd = &cobra.Command{
    30  	Use:   "list-keys",
    31  	Short: "List keys available on the remote server",
    32  	RunE:  listKeysCmd,
    33  }
    34  
    35  func init() {
    36  	RemoteCmd.AddCommand(ListKeysCmd)
    37  }
    38  
    39  func listKeysCmd(cmd *cobra.Command, args []string) error {
    40  	var keyList []string
    41  	response, err := CallRemote("list_keys", "GET", nil, nil)
    42  	if err != nil {
    43  		return shared.Fail(err)
    44  	}
    45  	resbytes, err := ioutil.ReadAll(response.Body)
    46  	if err != nil {
    47  		return shared.Fail(err)
    48  	}
    49  	response.Body.Close()
    50  	err = json.Unmarshal(resbytes, &keyList)
    51  	if err != nil {
    52  		return shared.Fail(err)
    53  	}
    54  	for _, key := range keyList {
    55  		fmt.Println(key)
    56  	}
    57  	return nil
    58  }
    59  

View as plain text