Documentation ¶
Index ¶
- Constants
- Variables
- func SimplifyAttributes(attrs Attributes) map[string]string
- type API
- func (api *API) DeleteGroupAttributes(groupName, attrName string) error
- func (api *API) DeleteUserAttributes(userName, attrName string) error
- func (api *API) GetGroup(groupName string, withAttributes bool) (*Group, error)
- func (api *API) GetGroupAttributes(groupName string) (Attributes, error)
- func (api *API) GetGroupDirectUsers(groupName string, options ...ListingOptions) ([]*User, error)
- func (api *API) GetGroupNestedUsers(groupName string, options ...ListingOptions) ([]*User, error)
- func (api *API) GetGroupUsers(groupName, groupType string, options ...ListingOptions) ([]*User, error)
- func (api *API) GetMemberships() ([]*Membership, error)
- func (api *API) GetUser(userName string, withAttributes bool) (*User, error)
- func (api *API) GetUserAttributes(userName string) (Attributes, error)
- func (api *API) GetUserDirectGroups(userName string, options ...ListingOptions) ([]*Group, error)
- func (api *API) GetUserGroups(userName, groupType string, options ...ListingOptions) ([]*Group, error)
- func (api *API) GetUserNestedGroups(userName string, options ...ListingOptions) ([]*Group, error)
- func (api *API) Login(userName, passWord string) (*User, error)
- func (api *API) SearchGroups(cql string, options ...ListingOptions) ([]*Group, error)
- func (api *API) SearchUsers(cql string, options ...ListingOptions) ([]*User, error)
- func (api *API) SetGroupAttributes(groupName string, attrs *GroupAttributes) error
- func (api *API) SetUserAgent(app, version string)
- func (api *API) SetUserAttributes(userName string, attrs *UserAttributes) error
- type Attribute
- type Attributes
- type Group
- type GroupAttributes
- type ListingOptions
- type Membership
- type User
- type UserAttributes
- type UserInfo
Examples ¶
- API.GetGroup
- API.GetGroupAttributes
- API.GetGroupDirectUsers
- API.GetGroupNestedUsers
- API.GetGroupUsers
- API.GetMemberships
- API.GetUser
- API.GetUserAttributes
- API.GetUserDirectGroups
- API.GetUserGroups
- API.GetUserNestedGroups
- API.Login
- API.SearchGroups
- API.SearchUsers
- API.SetUserAgent
- NewAPI
- SimplifyAttributes
Constants ¶
const ( GROUP_DIRECT = "direct" GROUP_NESTED = "nested" )
Groups types
Variables ¶
var ( ErrInitEmptyURL = errors.New("URL can't be empty") ErrInitEmptyApp = errors.New("App can't be empty") ErrInitEmptyPassword = errors.New("Password can't be empty") ErrNoPerms = errors.New("Application does not have permission to use Crowd") ErrUserNoFound = errors.New("User could not be found") ErrGroupNoFound = errors.New("Group could not be found") )
API errors
Functions ¶
func SimplifyAttributes ¶
func SimplifyAttributes(attrs Attributes) map[string]string
SimplifyAttributes converts slice with attributes to map name->value
Example ¶
attrs := Attributes{ &Attribute{Name: "test", Values: []string{"1", "2"}}, &Attribute{Name: "abcd", Values: []string{"test", "100"}}, } attrsMap := SimplifyAttributes(attrs) fmt.Println(attrsMap["test"])
Output: 1 2
Types ¶
type API ¶
type API struct { Client *fasthttp.Client // Client is client for http requests // contains filtered or unexported fields }
API is Confluence API struct
func NewAPI ¶
NewAPI creates new API struct
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } api.SetUserAgent("MyApp", "1.2.3") user, err := api.GetUser("john", true) if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("%#v\n", user)
Output:
func (*API) DeleteGroupAttributes ¶
DeleteGroupAttributes deletes a group attribute
func (*API) DeleteUserAttributes ¶
DeleteUserAttributes deletes a user attribute
func (*API) GetGroup ¶
GetGroup returns a group
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } group, err := api.GetGroup("my_group", true) if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("%#v\n", group)
Output:
func (*API) GetGroupAttributes ¶
func (api *API) GetGroupAttributes(groupName string) (Attributes, error)
GetGroupAttributes returns a list of group attributes
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } attrs, err := api.GetGroupAttributes("my_group") if err != nil { fmt.Printf("Error: %v\n", err) return } attrsMap := SimplifyAttributes(attrs) fmt.Printf("%#v\n", attrsMap)
Output:
func (*API) GetGroupDirectUsers ¶
func (api *API) GetGroupDirectUsers(groupName string, options ...ListingOptions) ([]*User, error)
GetGroupDirectUsers returns the users that are direct members of the specified group
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } users, err := api.GetGroupDirectUsers("my_group") // with listing options users, err = api.GetGroupDirectUsers( "my_group", ListingOptions{StartIndex: 100, MaxResults: 50}, ) if err != nil { fmt.Printf("Error: %v\n", err) return } if len(users) > 0 { for _, user := range users { fmt.Printf("%#v\n", user) } }
Output:
func (*API) GetGroupNestedUsers ¶
func (api *API) GetGroupNestedUsers(groupName string, options ...ListingOptions) ([]*User, error)
GetGroupNestedUsers returns the users that are nested members of the specified group
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } users, err := api.GetGroupNestedUsers("my_group") // with listing options users, err = api.GetGroupNestedUsers( "my_group", ListingOptions{StartIndex: 100, MaxResults: 50}, ) if err != nil { fmt.Printf("Error: %v\n", err) return } if len(users) > 0 { for _, user := range users { fmt.Printf("%#v\n", user) } }
Output:
func (*API) GetGroupUsers ¶
func (api *API) GetGroupUsers(groupName, groupType string, options ...ListingOptions) ([]*User, error)
GetGroupUsers returns the users that are members of the specified group
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } users, err := api.GetGroupUsers("my_group", GROUP_DIRECT) // with listing options users, err = api.GetGroupUsers( "my_group", GROUP_DIRECT, ListingOptions{StartIndex: 100, MaxResults: 50}, ) if err != nil { fmt.Printf("Error: %v\n", err) return } if len(users) > 0 { for _, user := range users { fmt.Printf("%#v\n", user) } }
Output:
func (*API) GetMemberships ¶
func (api *API) GetMemberships() ([]*Membership, error)
GetMemberships returns full details of all group memberships, with users and nested groups
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } membership, err := api.GetMemberships() if err != nil { fmt.Printf("Error: %v\n", err) return } for _, group := range membership { fmt.Printf("Group: %v\n", group.Group) for _, userInfo := range group.Users { fmt.Printf(" - %v\n", userInfo.Name) } fmt.Println("") }
Output:
func (*API) GetUser ¶
GetUser returns a user
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } user, err := api.GetUser("john", true) if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("%#v\n", user)
Output:
func (*API) GetUserAttributes ¶
func (api *API) GetUserAttributes(userName string) (Attributes, error)
GetUserAttributes returns a list of user attributes
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } attrs, err := api.GetUserAttributes("john") if err != nil { fmt.Printf("Error: %v\n", err) return } attrsMap := SimplifyAttributes(attrs) fmt.Printf("%#v\n", attrsMap)
Output:
func (*API) GetUserDirectGroups ¶
func (api *API) GetUserDirectGroups(userName string, options ...ListingOptions) ([]*Group, error)
GetUserDirectGroups returns the groups that the user is a direct member of
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } groups, err := api.GetUserDirectGroups("john") // with listing options groups, err = api.GetUserDirectGroups( "john", ListingOptions{StartIndex: 100, MaxResults: 50}, ) if err != nil { fmt.Printf("Error: %v\n", err) return } if len(groups) > 0 { for _, group := range groups { fmt.Printf("%#v\n", group) } }
Output:
func (*API) GetUserGroups ¶
func (api *API) GetUserGroups(userName, groupType string, options ...ListingOptions) ([]*Group, error)
GetUserGroups returns the groups that the user is a member of
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } groups, err := api.GetUserGroups("john", GROUP_DIRECT) // with listing options groups, err = api.GetUserGroups( "john", GROUP_DIRECT, ListingOptions{StartIndex: 100, MaxResults: 50}, ) if err != nil { fmt.Printf("Error: %v\n", err) return } if len(groups) > 0 { for _, group := range groups { fmt.Printf("%#v\n", group) } }
Output:
func (*API) GetUserNestedGroups ¶
func (api *API) GetUserNestedGroups(userName string, options ...ListingOptions) ([]*Group, error)
GetUserNestedGroups returns the groups that the user is a nested member of
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } groups, err := api.GetUserNestedGroups("john") // with listing options groups, err = api.GetUserNestedGroups( "john", ListingOptions{StartIndex: 100, MaxResults: 50}, ) if err != nil { fmt.Printf("Error: %v\n", err) return } if len(groups) > 0 { for _, group := range groups { fmt.Printf("%#v\n", group) } }
Output:
func (*API) Login ¶ added in v3.1.0
Login attempts to authenticate a user with the given username and password. It constructs a URL with the given username and sends a POST request to the usermanagement authentication API with the provided password. It returns a pointer to a User object with the user's information on successful authentication, or an error if authentication failed or an unknown error occurred.
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } currentUser, err := api.Login("john", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Printf("%#v\n", currentUser)
Output:
func (*API) SearchGroups ¶
func (api *API) SearchGroups(cql string, options ...ListingOptions) ([]*Group, error)
SearchGroups searches for groups with the specified search restriction
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } groups, err := api.SearchGroups(`name = "admin*" and active = false`) // with listing options groups, err = api.SearchGroups( `name = "admin*" and active = false`, ListingOptions{StartIndex: 100, MaxResults: 50}, ) if err != nil { fmt.Printf("Error: %v\n", err) return } if len(groups) > 0 { for _, group := range groups { fmt.Printf("%#v\n", group) } }
Output:
func (*API) SearchUsers ¶
func (api *API) SearchUsers(cql string, options ...ListingOptions) ([]*User, error)
SearchUsers searches for users with the specified search restriction
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } users, err := api.SearchUsers(`createdDate > 2010-12 or firstName = Jo*`) // with listing options users, err = api.SearchUsers( `createdDate > 2010-12 or firstName = Jo*`, ListingOptions{StartIndex: 100, MaxResults: 50}, ) if err != nil { fmt.Printf("Error: %v\n", err) return } if len(users) > 0 { for _, user := range users { fmt.Printf("%#v\n", user) } }
Output:
func (*API) SetGroupAttributes ¶
func (api *API) SetGroupAttributes(groupName string, attrs *GroupAttributes) error
SetGroupAttributes stores all the group attributes
func (*API) SetUserAgent ¶
SetUserAgent configures user-agent string based on app name and version
Example ¶
api, err := NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd") if err != nil { fmt.Printf("Error: %v\n", err) return } api.SetUserAgent("MyApp", "1.2.3")
Output:
func (*API) SetUserAttributes ¶
func (api *API) SetUserAttributes(userName string, attrs *UserAttributes) error
SetUserAttributes stores all the user attributes for an existing user
type Attributes ¶
type Attributes []*Attribute
Attributes it is slice with attributes
func (Attributes) Get ¶
func (a Attributes) Get(name string) string
Get returns merged values for attribute with given name
func (Attributes) GetList ¶
func (a Attributes) GetList(name string) []string
GetList returns slice with values for attribute with given name
func (Attributes) Has ¶
func (a Attributes) Has(name string) bool
Has returns true if slice contains attribute with given name
type Group ¶
type Group struct { Name string `xml:"name,attr"` Description string `xml:"description"` Type string `xml:"type"` IsActive bool `xml:"active"` }
Group contains info about group
type GroupAttributes ¶
type GroupAttributes struct { XMLName xml.Name `xml:"attributes"` Attributes []*Attribute `xml:"attribute"` }
GroupAttributes contains group attributes
type ListingOptions ¶ added in v3.2.0
ListingOptions contains options for request with listing objects
func (ListingOptions) Encode ¶ added in v3.2.0
func (l ListingOptions) Encode() string
Encode encodes listing options to URL query string part
type Membership ¶
Membership contains membership info
type User ¶
type User struct { Attributes Attributes `xml:"attributes>attribute"` Name string `xml:"name,attr"` FirstName string `xml:"first-name"` LastName string `xml:"last-name"` DisplayName string `xml:"display-name"` Email string `xml:"email"` Key string `xml:"key,omitempty"` Password string `xml:"password>value,omitempty"` IsActive bool `xml:"active"` }
User contains info about user
type UserAttributes ¶
type UserAttributes struct { XMLName xml.Name `xml:"attributes,omitempty"` Attributes []*Attribute `xml:"attribute"` }
UserAttributes contains user attributes