Debian Codegraph @

rundeck/project.go

raw symbols SCIP
1 package rundeck
2
3 import (
4 "encoding/xml"
5 )
6
7 // ProjectSummary provides the basic identifying information for a project within Rundeck.
8 type ProjectSummary struct {
9 Name string `xml:"name"`
10 Description string `xml:"description,omitempty"`
11 URL string `xml:"url,attr"`
12 }
13
14 // Project represents a project within Rundeck.
15 type Project struct {
16 Name string `xml:"name"`
17 Description string `xml:"description,omitempty"`
18
19 // Config is the project configuration.
20 //
21 // When making requests, Config and RawConfigItems are combined to produce
22 // a single set of configuration settings. Thus it isn't necessary and
23 // doesn't make sense to duplicate the same properties in both properties.
24 Config ProjectConfig `xml:"config"`
25
26 // URL is used only to represent server responses. It is ignored when
27 // making requests.
28 URL string `xml:"url,attr"`
29
30 // XMLName is used only in XML unmarshalling and doesn't need to
31 // be set when creating a Project to send to the server.
32 XMLName xml.Name `xml:"project"`
33 }
34
35 // ProjectConfig is a specialized map[string]string representing Rundeck project configuration
36 type ProjectConfig map[string]string
37
38 type projects struct {
39 XMLName xml.Name `xml:"projects"`
40 Count int64 `xml:"count,attr"`
41 Projects []ProjectSummary `xml:"project"`
42 }
43
44 // GetAllProjects retrieves and returns all of the projects defined in the Rundeck server.
45 func (c *Client) GetAllProjects() ([]ProjectSummary, error) {
46 p := &projects{}
47 err := c.get([]string{"projects"}, nil, p)
48 return p.Projects, err
49 }
50
51 // GetProject retrieves and returns the named project.
52 func (c *Client) GetProject(name string) (*Project, error) {
53 p := &Project{}
54 err := c.get([]string{"project", name}, nil, p)
55 return p, err
56 }
57
58 // CreateProject creates a new, empty project.
59 func (c *Client) CreateProject(project *Project) (*Project, error) {
60 p := &Project{}
61 err := c.post([]string{"projects"}, nil, project, p)
62 return p, err
63 }
64
65 // DeleteProject deletes a project and all of its jobs.
66 func (c *Client) DeleteProject(name string) error {
67 return c.delete([]string{"project", name})
68 }
69
70 // SetProjectConfig replaces the configuration of the named project.
71 func (c *Client) SetProjectConfig(projectName string, config ProjectConfig) error {
72 return c.put(
73 []string{"project", projectName, "config"},
74 config,
75 nil,
76 )
77 }
78
79 func (c ProjectConfig) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
80 rc := map[string]string(c)
81 return marshalMapToXML(&rc, e, start, "property", "key", "value")
82 }
83
84 func (c *ProjectConfig) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
85 rc := (*map[string]string)(c)
86 return unmarshalMapFromXML(rc, d, start, "property", "key", "value")
87 }