Debian Codegraph @

cmdline/remotecmd/getkeycmd.go

raw symbols SCIP
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 "errorsscip-go gomod github.com/golang/go/src go1.18 errors/"
22 "io/ioutilscip-go gomod github.com/golang/go/src go1.18 `io/ioutil`/"
23 "net/urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/"
24 "osscip-go gomod github.com/golang/go/src go1.18 os/"
25
26 "github.com/spf13/cobrascip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/"
27
28 "github.com/sassoftware/relic/v7/cmdline/sharedscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/shared`/"
29 )
30
31 var GetKeyCmdscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/GetKeyCmd. = &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#{
32 Usescip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/Command#Use.: "get-key",
33 Shortscip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/Command#Short.: "Get a public key certificate from the remote server",
34 RunEscip-go gomod github.com/spf13/cobra v1.6.1 `github.com/spf13/cobra`/Command#RunE.: getKeyCmdscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/getKeyCmd().,
35 }
36
37 func initscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/init().() {
38 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().(GetKeyCmdscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/GetKeyCmd.)
39 }
40
41 type keyInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/keyInfo# struct {
42 X509Certificatescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/keyInfo#X509Certificate. string
43 PGPCertificatescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/keyInfo#PGPCertificate. string
44 }
45
46 func getKeyInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/getKeyInfo().(keyName string) (keyInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/keyInfo#, error) {
47 response, err := CallRemotescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/CallRemote().("keys/"+urlscip-go gomod github.com/golang/go/src go1.18 `net/url`/.PathEscapescip-go gomod github.com/golang/go/src go1.18 `net/url`/PathEscape().(keyName), "GET", nil, nil)
48 if err != nil {
49 return keyInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/keyInfo#{}, err
50 }
51 blob, 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.)
52 if err != nil {
53 return keyInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/keyInfo#{}, err
54 }
55 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().()
56 var info keyInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/keyInfo#
57 if 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().(blob, &info); err != nil {
58 return keyInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/keyInfo#{}, err
59 }
60 return info, nil
61 }
62
63 func getKeyCmdscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/getKeyCmd().(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 {
64 if len(args) == 0 {
65 return errorsscip-go gomod github.com/golang/go/src go1.18 errors/.Newscip-go gomod github.com/golang/go/src go1.18 errors/New().("specify one or more key names. See also 'list-keys'")
66 }
67 for _, keyName := range args {
68 info, err := getKeyInfoscip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/getKeyInfo().(keyName)
69 if err != nil {
70 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)
71 }
72 osscip-go gomod github.com/golang/go/src go1.18 os/.Stdoutscip-go gomod github.com/golang/go/src go1.18 os/Stdout..WriteStringscip-go gomod github.com/golang/go/src go1.18 os/File#WriteString().(info.X509Certificatescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/keyInfo#X509Certificate.)
73 osscip-go gomod github.com/golang/go/src go1.18 os/.Stdoutscip-go gomod github.com/golang/go/src go1.18 os/Stdout..WriteStringscip-go gomod github.com/golang/go/src go1.18 os/File#WriteString().(info.PGPCertificatescip-go gomod github.com/sassoftware/relic/v7 . `github.com/sassoftware/relic/v7/cmdline/remotecmd`/keyInfo#PGPCertificate.)
74 }
75 return nil
76 }