| 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 remotecmdscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/ |
| 18 | |
| 19 | import ( |
| 20 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/" |
| 21 | "fmtscip-go gomod github.com/golang/go/src go1.18 fmt/" |
| 22 | "io/ioutilscip-go gomod github.com/golang/go/src go1.18 `io/ioutil`/" |
| 23 | |
| 24 | "github.com/sassoftware/relic/v7/cmdline/sharedscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/shared`/" |
| 25 | |
| 26 | "github.com/spf13/cobrascip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/" |
| 27 | ) |
| 28 | |
| 29 | var ListKeysCmdscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/ListKeysCmd. = &cobrascip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/Command#{ |
| 30 | Usescip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/Command#Use.: "list-keys", |
| 31 | Shortscip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/Command#Short.: "List keys available on the remote server", |
| 32 | RunEscip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/Command#RunE.: listKeysCmdscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/listKeysCmd()., |
| 33 | } |
| 34 | |
| 35 | func initscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/init().() { |
| 36 | RemoteCmdscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/RemoteCmd..AddCommandscip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/Command#AddCommand().(ListKeysCmdscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/ListKeysCmd.) |
| 37 | } |
| 38 | |
| 39 | func listKeysCmdscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/listKeysCmd().(cmd *cobrascip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/.Commandscip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/Command#, args []string) error { |
| 40 | var keyList []string |
| 41 | response, err := CallRemotescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/CallRemote().("list_keys", "GET", nil, nil) |
| 42 | if err != nil { |
| 43 | return sharedscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/shared`/.Failscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/shared`/Fail().(err) |
| 44 | } |
| 45 | resbytes, err := ioutilscip-go gomod github.com/golang/go/src go1.18 `io/ioutil`/.ReadAllscip-go gomod github.com/golang/go/src go1.18 `io/ioutil`/ReadAll().(response.Bodyscip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#Body.) |
| 46 | if err != nil { |
| 47 | return sharedscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/shared`/.Failscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/shared`/Fail().(err) |
| 48 | } |
| 49 | response.Bodyscip-go gomod github.com/golang/go/src go1.18 `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src go1.18 io/Closer#Close().() |
| 50 | err = jsonscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.18 `encoding/json`/Unmarshal().(resbytes, &keyList) |
| 51 | if err != nil { |
| 52 | return sharedscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/shared`/.Failscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/shared`/Fail().(err) |
| 53 | } |
| 54 | for _, key := range keyList { |
| 55 | fmtscip-go gomod github.com/golang/go/src go1.18 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.18 fmt/Println().(key) |
| 56 | } |
| 57 | return nil |
| 58 | } |