obs

package module
v0.0.0-...-d182bfe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

OBS API client in Go

go-obs is an API client for OBS, Open Build Service.

go-obs currently only covers a tiny part of the OBS API. It also provides a very basic command-line client tool.

Please note that this project has nothing to do with another OBS which is short for Open Broadcaster Software. If you’re looking for a Go client for that OBS, have a look at obsws.

API coverage

The client currently only supports most of the user and group manipulation operations.

License

Licensed under the Apache License, Version 2.0 (the ‘License’); you may not use this software except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0; it is also included as LICENSE with this software.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present.

Types

type Client

type Client struct {

	// User agent used when communicating with the OBS API.
	UserAgent string

	// Don’t verify server’s TLS certificates
	InsecureSkipVerify bool
	// contains filtered or unexported fields
}

func NewClient

func NewClient(username, password string, options ...ClientOptionFunc) (*Client, error)

NewAPI returns a new OBS API client. To use API methods which require authentication, provide a valid username and password.

func (*Client) AddGroupMember

func (c *Client) AddGroupMember(group string, user string) error

AddGroupMember adds a user to a group.

func (*Client) BaseURL

func (c *Client) BaseURL() *url.URL

BaseURL returns a copy of the baseURL.

func (*Client) DeleteGroup

func (c *Client) DeleteGroup(name string) error

DeleteGroup deletes a group of users. On some OBS versions the group must be empty before it can be deleted.

func (*Client) DeleteUser

func (c *Client) DeleteUser(name string) error

DeleteUser marks the user as deleted and deletes their projects.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is XML-decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) GetGroup

func (c *Client) GetGroup(name string) (*Group, error)

GetGroup retrieves the details of the group (maintainer, members etc).

func (*Client) GetUser

func (c *Client) GetUser(name string) (*User, error)

GetUser retrieves the details of the user (email, real name etc).

func (*Client) GetUserByEmail

func (c *Client) GetUserByEmail(email string) (*User, error)

GetUserByEmail returns the details of the only user matching given email address If more than one user with given email address exist, an error is returned.

func (*Client) GetUserGroups

func (c *Client) GetUserGroups(name string) ([]string, error)

GetUserGroups retrieves a list of groups the user is a member of.

func (*Client) GetUsersByEmail

func (c *Client) GetUsersByEmail(email string) ([]User, error)

GetUsersByEmail returns the details of the users matching given email address.

func (*Client) ListGroups

func (c *Client) ListGroups() ([]string, error)

ListGroups gets a list of names of all groups. Use GetGroup to retrieve the details of each group.

func (*Client) ListUsers

func (c *Client) ListUsers(prefix string) ([]string, error)

ListUsers gets a list of names of all users. Use GetUser to retrieve the details of each user.

func (*Client) LockUser

func (c *Client) LockUser(name string) error

LockUser locks the user and their projects.

func (*Client) NewGroup

func (c *Client) NewGroup(name string) error

NewGroup creates a new empty group.

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, opt interface{}, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL path can be provided in path, in which case it is resolved relative to the base URL of the Client. If specified, the value pointed to by body is XML-encoded and included as the request body.

func (*Client) RemoveGroupMember

func (c *Client) RemoveGroupMember(group string, user string) error

RemoveGroupMember removes a user from a group.

func (*Client) SetGroupEmail

func (c *Client) SetGroupEmail(group string, email string) error

SetGroupEmail sets the email address of a group.

func (*Client) SetUserPassword

func (c *Client) SetUserPassword(name string, password string) error

SetUserPassword sets the password of the user.

func (*Client) UpdateGroup

func (c *Client) UpdateGroup(g *Group) error

UpdateGroup updates an existing group. The user calling this must have necessary access rights to be able to perform this call.

type ClientOptionFunc

type ClientOptionFunc func(*Client) error

func WithBaseURL

func WithBaseURL(urlStr string) ClientOptionFunc

WithBaseURL sets the base URL for API requests to a custom endpoint.

type ErrorResponse

type ErrorResponse struct {
	Body     []byte         `xml:"-"`
	Response *http.Response `xml:"-"`
	Message  string         `xml:"summary"`
	Code     string         `xml:"code,attr"`
	XMLName  xml.Name       `xml:"status"`
}

An ErrorResponse reports one or more errors caused by an API request.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type Group

type Group struct {
	XMLName    xml.Name  `xml:"group"           json:"-"`
	ID         string    `xml:"title"           json:"name"`
	Email      string    `xml:"email,omitempty" json:"email,omitempty"`
	Maintainer UserRef   `xml:"maintainer"      json:"maintainer"`
	Members    []UserRef `xml:"person>person"   json:"members"`
}

Group represents a named group of users.

type ProjectRef

type ProjectRef struct {
	Name string `xml:"name,attr" json:"name"`
}

ProjectRef represents a project referred by its name. This is used e.g. to represent a project in a watchlist.

type SearchOptions

type SearchOptions struct {
	Match string `url:"match,omitempty"`
}

type User

type User struct {
	XMLName   xml.Name     `xml:"person"               json:"-"`
	ID        string       `xml:"login"                json:"username"`
	Email     string       `xml:"email"                json:"email"`
	Realname  string       `xml:"realname"             json:"realname"`
	State     string       `xml:"state"                json:"state"`
	Owner     *UserRef     `xml:"owner,omitempty"      json:"owner,omitempty"`
	Roles     []string     `xml:"globalrole,omitempty" json:"globalrole,omitempty"`
	Watchlist []ProjectRef `xml:"watchlist>project"    json:"watchlist,omitempty"`
}

User represents a user (a person in OBS terminology).

type UserOptions

type UserOptions struct {
	Command string `url:"cmd,omitempty"`
	User    string `url:"userid,omitempty"`
	Email   string `url:"email,omitempty"`
	Prefix  string `url:"prefix,omitempty"`
}

type UserRef

type UserRef struct {
	ID string `xml:"userid,attr" json:"username"`
}

UserRef represents a user referred by their username. This is used e.g. to represent members of a group.

func (UserRef) MarshalJSON

func (u UserRef) MarshalJSON() ([]byte, error)

func (UserRef) MarshalXML

func (u UserRef) MarshalXML(e *xml.Encoder, start xml.StartElement) error

type XPathPredicate

type XPathPredicate struct {
	// contains filtered or unexported fields
}

func XPathAttrEquals

func XPathAttrEquals(name string, value string) *XPathPredicate

func (*XPathPredicate) String

func (p *XPathPredicate) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL