Debian Codegraph @

rundeck/key.go

raw symbols SCIP
1 package rundeck
2
3 // KeyMeta is the metadata associated with a resource in the Rundeck key store.
4 type KeyMeta struct {
5 XMLName string `xml:"resource"`
6 Name string `xml:"name,attr,omitempty"`
7 Path string `xml:"path,attr,omitempty"`
8 ResourceType string `xml:"type,attr,omitempty"`
9 URL string `xml:"url,attr,omitempty"`
10 ContentType string `xml:"resource-meta>Rundeck-content-type"`
11 ContentSize string `xml:"resource-meta>Rundeck-content-size"`
12 ContentMask string `xml:"resource-meta>Rundeck-content-mask"`
13 KeyType string `xml:"resource-meta>Rundeck-key-type"`
14 LastModifiedByUserName string `xml:"resource-meta>Rundeck-auth-modified-username"`
15 CreatedByUserName string `xml:"resource-meta>Rundeck-auth-created-username"`
16 CreatedTimestamp string `xml:"resource-meta>Rundeck-content-creation-time"`
17 LastModifiedTimestamp string `xml:"resource-meta>Rundeck-content-modify-time"`
18 }
19
20 type keyMetaListContents struct {
21 Keys []KeyMeta `xml:"contents>resource"`
22 }
23
24 // GetKeyMeta returns the metadata for the key at the given keystore path.
25 func (c *Client) GetKeyMeta(path string) (*KeyMeta, error) {
26 k := &KeyMeta{}
27 err := c.get([]string{"storage", "keys", path}, nil, k)
28 return k, err
29 }
30
31 // GetKeysInDirMeta returns the metadata for the keys and subdirectories within
32 // the directory at the given keystore path.
33 func (c *Client) GetKeysInDirMeta(path string) ([]KeyMeta, error) {
34 r := &keyMetaListContents{}
35 err := c.get([]string{"storage", "keys", path}, nil, r)
36 if err != nil {
37 return nil, err
38 }
39 return r.Keys, nil
40 }
41
42 // GetKeyContent retrieves and returns the content of the key at the given keystore path.
43 // Private keys are write-only, so they cannot be retrieved via this interface.
44 func (c *Client) GetKeyContent(path string) (string, error) {
45 return c.rawGet([]string{"storage", "keys", path}, nil, "application/pgp-keys")
46 }
47
48 func (c *Client) CreatePublicKey(path string, content string) error {
49 return c.createOrReplacePublicKey("POST", path, "application/pgp-keys", content)
50 }
51
52 func (c *Client) ReplacePublicKey(path string, content string) error {
53 return c.createOrReplacePublicKey("PUT", path, "application/pgp-keys", content)
54 }
55
56 func (c *Client) CreatePrivateKey(path string, content string) error {
57 return c.createOrReplacePublicKey("POST", path, "application/octet-stream", content)
58 }
59
60 func (c *Client) ReplacePrivateKey(path string, content string) error {
61 return c.createOrReplacePublicKey("PUT", path, "application/octet-stream", content)
62 }
63
64 func (c *Client) CreatePassword(path string, content string) error {
65 return c.createOrReplacePublicKey("POST", path, "application/x-rundeck-data-password", content)
66 }
67
68 func (c *Client) ReplacePassword(path string, content string) error {
69 return c.createOrReplacePublicKey("PUT", path, "application/x-rundeck-data-password", content)
70 }
71
72 func (c *Client) createOrReplacePublicKey(method string, path string, contentType string, content string) error {
73 req := &request{
74 Method: method,
75 PathParts: []string{"storage", "keys", path},
76 Headers: map[string]string{
77 "Content-Type": contentType,
78 },
79 BodyBytes: []byte(content),
80 }
81
82 _, err := c.rawRequest(req)
83
84 return err
85 }
86
87 func (c *Client) DeleteKey(path string) error {
88 return c.delete([]string{"storage", "keys", path})
89 }