pkiadm/location.go
Gibheer bc84bc4a28 add location support
This commit adds basic support for adding, deleting, ... locations. This
needed a bit of rework for the ResourceName, as it was kind of stupid to
have different implementations server internally and in the lib.

There is still some need for cleanup, but it works basically.
2017-05-31 21:03:51 +02:00

62 lines
1.4 KiB
Go

package pkiadm
type (
Location struct {
ID string
Path string
Dependencies []ResourceName
PreCommand string
PostCommand string
Checksum []byte
}
LocationChange struct {
Location Location
FieldList []string
}
ResultLocations struct {
Result Result
Locations []Location
}
)
func (c *Client) CreateLocation(loc Location) error {
return c.exec("CreateLocation", loc)
}
func (c *Client) DeleteLocation(id string) error {
loc := ResourceName{ID: id, Type: RTLocation}
return c.exec("DeleteLocation", loc)
}
func (c *Client) SetLocation(loc Location, fieldList []string) error {
changeset := LocationChange{loc, fieldList}
return c.exec("SetLocation", changeset)
}
func (c *Client) ShowLocation(id string) (Location, error) {
loc := ResourceName{ID: id, Type: RTLocation}
result := &ResultLocations{}
if err := c.query("ShowLocation", loc, result); err != nil {
return Location{}, err
}
if result.Result.HasError {
return Location{}, result.Result.Error
}
for _, location := range result.Locations {
return location, nil
}
return Location{}, nil
}
func (c *Client) ListLocation() ([]Location, error) {
result := &ResultLocations{}
if err := c.query("ListLocation", Filter{}, result); err != nil {
return []Location{}, err
}
if result.Result.HasError {
return []Location{}, result.Result.Error
}
return result.Locations, nil
}