crowd

package module
v3.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

README

PkgGoDev GoReportCard GitHub Actions CI Status GitHub Actions CodeQL Status Codebeat badge

InstallationUsage exampleBuild StatusLicense


go-crowd is a Go package for working with Crowd REST API.

Note, that this is beta software, so it's entirely possible that there will be some significant bugs. Please report bugs so that we are aware of the issues.

Installation

Make sure you have a working Go 1.15+ workspace (instructions), then:

go get -d pkg.re/essentialkaos/go-crowd.v3

For update to latest stable release, do:

go get -d -u pkg.re/essentialkaos/go-crowd.v3

Usage example

package main

import (
  "fmt"
  "pkg.re/essentialkaos/go-crowd.v3"
)

func main() {
  api, err := crowd.NewAPI("https://crowd.domain.com/crowd/", "myapp", "MySuppaPAssWOrd")
  api.SetUserAgent("MyApp", "1.2.3")

  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.Println("%-v\n", user)
}

Build Status

Branch Status
master (Stable) CI
develop (Unstable) CI

License

Apache License, Version 2.0

Documentation

Index

Constants

View Source
const (
	GROUP_DIRECT = "direct"
	GROUP_NESTED = "nested"
)

Groups types

View Source
const (
	// NAME is package name
	NAME = "Go-Crowd"

	// VERSION is package version
	VERSION = "3.0.2"
)

Variables

View Source
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 convert slice with attributes to map name->value

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

func NewAPI(url, app, password string) (*API, error)

NewAPI create new API struct

func (*API) DeleteGroupAttributes

func (api *API) DeleteGroupAttributes(groupName, attrName string) error

DeleteGroupAttributes deletes a group attribute

func (*API) DeleteUserAttributes

func (api *API) DeleteUserAttributes(userName, attrName string) error

DeleteUserAttributes deletes a user attribute

func (*API) GetGroup

func (api *API) GetGroup(groupName string, withAttributes bool) (*Group, error)

GetGroup returns a group

func (*API) GetGroupAttributes

func (api *API) GetGroupAttributes(groupName string) (Attributes, error)

GetGroupAttributes returns a list of group attributes

func (*API) GetGroupDirectUsers

func (api *API) GetGroupDirectUsers(groupName string) ([]*User, error)

GetGroupDirectUsers returns the users that are direct members of the specified group

func (*API) GetGroupNestedUsers

func (api *API) GetGroupNestedUsers(groupName string) ([]*User, error)

GetGroupNestedUsers returns the users that are nested members of the specified group

func (*API) GetGroupUsers

func (api *API) GetGroupUsers(groupName, groupType string) ([]*User, error)

GetGroupUsers returns the users that are members of the specified group

func (*API) GetMemberships

func (api *API) GetMemberships() ([]*Membership, error)

GetMemberships returns full details of all group memberships, with users and nested groups

func (*API) GetUser

func (api *API) GetUser(userName string, withAttributes bool) (*User, error)

GetUser returns a user

func (*API) GetUserAttributes

func (api *API) GetUserAttributes(userName string) (Attributes, error)

GetUserAttributes returns a list of user attributes

func (*API) GetUserDirectGroups

func (api *API) GetUserDirectGroups(userName string) ([]*Group, error)

GetUserDirectGroups returns the groups that the user is a direct member of

func (*API) GetUserGroups

func (api *API) GetUserGroups(userName, groupType string) ([]*Group, error)

GetUserGroups returns the groups that the user is a member of

func (*API) GetUserNestedGroups

func (api *API) GetUserNestedGroups(userName string) ([]*Group, error)

GetUserNestedGroups returns the groups that the user is a nested member of

func (*API) SearchGroups

func (api *API) SearchGroups(cql string) ([]*Group, error)

SearchGroups searches for groups with the specified search restriction

func (*API) SearchUsers

func (api *API) SearchUsers(cql string) ([]*User, error)

SearchUsers searches for users with the specified search restriction

func (*API) SetGroupAttributes

func (api *API) SetGroupAttributes(groupName string, attrs *GroupAttributes) error

SetGroupAttributes stores all the group attributes

func (*API) SetUserAgent

func (api *API) SetUserAgent(app, version string)

SetUserAgent set user-agent string based on app name and version

func (*API) SetUserAttributes

func (api *API) SetUserAttributes(userName string, attrs *UserAttributes) error

SetUserAttributes stores all the user attributes for an existing user

type Attribute

type Attribute struct {
	Name   string   `xml:"name,attr"`
	Values []string `xml:"values>value"`
}

Attribute contains attribute info

func (*Attribute) String

func (a *Attribute) String() string

String convert attribute to string

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 Membership

type Membership struct {
	Group string      `xml:"group,attr"`
	Users []*UserInfo `xml:"users>user"`
}

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

type UserInfo

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

UserInfo contains basic user info (username)

func (*UserInfo) String

func (u *UserInfo) String() string

String convert user info to string

Jump to

Keyboard shortcuts

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