File: project.go

package info (click to toggle)
golang-github-apparentlymart-go-rundeck-api 0.0.1%2Bgit20170705.2c962ac-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 120 kB
  • sloc: makefile: 2
file content (87 lines) | stat: -rw-r--r-- 2,731 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package rundeck

import (
	"encoding/xml"
)

// ProjectSummary provides the basic identifying information for a project within Rundeck.
type ProjectSummary struct {
	Name        string `xml:"name"`
	Description string `xml:"description,omitempty"`
	URL         string `xml:"url,attr"`
}

// Project represents a project within Rundeck.
type Project struct {
	Name        string `xml:"name"`
	Description string `xml:"description,omitempty"`

	// Config is the project configuration.
	//
	// When making requests, Config and RawConfigItems are combined to produce
	// a single set of configuration settings. Thus it isn't necessary and
	// doesn't make sense to duplicate the same properties in both properties.
	Config ProjectConfig `xml:"config"`

	// URL is used only to represent server responses. It is ignored when
	// making requests.
	URL string `xml:"url,attr"`

	// XMLName is used only in XML unmarshalling and doesn't need to
	// be set when creating a Project to send to the server.
	XMLName xml.Name `xml:"project"`
}

// ProjectConfig is a specialized map[string]string representing Rundeck project configuration
type ProjectConfig map[string]string

type projects struct {
	XMLName  xml.Name         `xml:"projects"`
	Count    int64            `xml:"count,attr"`
	Projects []ProjectSummary `xml:"project"`
}

// GetAllProjects retrieves and returns all of the projects defined in the Rundeck server.
func (c *Client) GetAllProjects() ([]ProjectSummary, error) {
	p := &projects{}
	err := c.get([]string{"projects"}, nil, p)
	return p.Projects, err
}

// GetProject retrieves and returns the named project.
func (c *Client) GetProject(name string) (*Project, error) {
	p := &Project{}
	err := c.get([]string{"project", name}, nil, p)
	return p, err
}

// CreateProject creates a new, empty project.
func (c *Client) CreateProject(project *Project) (*Project, error) {
	p := &Project{}
	err := c.post([]string{"projects"}, nil, project, p)
	return p, err
}

// DeleteProject deletes a project and all of its jobs.
func (c *Client) DeleteProject(name string) error {
	return c.delete([]string{"project", name})
}

// SetProjectConfig replaces the configuration of the named project.
func (c *Client) SetProjectConfig(projectName string, config ProjectConfig) error {
	return c.put(
		[]string{"project", projectName, "config"},
		config,
		nil,
	)
}

func (c ProjectConfig) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	rc := map[string]string(c)
	return marshalMapToXML(&rc, e, start, "property", "key", "value")
}

func (c *ProjectConfig) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	rc := (*map[string]string)(c)
	return unmarshalMapFromXML(rc, d, start, "property", "key", "value")
}