freeipa

package module
v0.0.0-...-98de29c Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 14 Imported by: 0

README

go-freeipa

A FreeIPA API client library for GoLang.

Install

go get github.com/grmrgecko/go-freeipa

Example

import (
    "crypto/tls"
    "log"
    "net/http"
    "github.com/grmrgecko/go-freeipa"
)

func main() {
    // Setup TLS configurations.
    tlsConifg := tls.Config{InsecureSkipVerify: false}
    transportConfig := &http.Transport{
        TLSClientConfig: &tlsConifg,
    }
    // Connect/login to FreeIPA server.
    client, err := freeipa.Connect("ipa.example.com", transportConfig, "username", "password")
    if err!=nil {
        log.Fatalln(err)
    }

    // Make a user.
    params := make(map[string]interface{})
    params["pkey_only"] = true
    params["sizelimit"] = 0
    req := freeipa.NewRequest(
        "user_find",
        []interface{}{""},
        params,
    )

    // Send the request to the test server.
    resp, err := client.Do(req)
    if err != nil {
        log.Fatalln(err)
    }

    // Print information about response.
    log.Println("Found users:", resp.Result.Count)

    dn, ok := resp.GetStringAtIndex(0, "dn")
    if !ok {
        log.Fatalln("Unable to get dn value from FreeIPA")
    }

    log.Println("Got first user DN:", dn)
}

References

If you're looking for help on what API methods there are and the arguments they accept, the documentation at FreeIPA should help:

https://github.com/freeipa/freeipa/tree/master/doc/api

Documentation

Index

Constants

View Source
const (
	PublicErrorCode                           = 900
	VersionErrorCode                          = 901
	UnknownErrorCode                          = 902
	InternalErrorCode                         = 903
	ServerInternalErrorCode                   = 904
	CommandErrorCode                          = 905
	ServerCommandErrorCode                    = 906
	NetworkErrorCode                          = 907
	ServerNetworkErrorCode                    = 908
	JSONErrorCode                             = 909
	XMLRPCMarshallErrorCode                   = 910
	RefererErrorCode                          = 911
	EnvironmentErrorCode                      = 912
	SystemEncodingErrorCode                   = 913
	AuthenticationErrorCode                   = 1000
	KerberosErrorCode                         = 1100
	CCacheErrorCode                           = 1101
	ServiceErrorCode                          = 1102
	NoCCacheErrorCode                         = 1103
	TicketExpiredCode                         = 1104
	BadCCachePermsCode                        = 1105
	BadCCacheFormatCode                       = 1106
	CannotResolveKDCCode                      = 1107
	SessionErrorCode                          = 1200
	InvalidSessionPasswordCode                = 1201
	PasswordExpiredCode                       = 1202
	KrbPrincipalExpiredCode                   = 1203
	UserLockedCode                            = 1204
	AuthorizationErrorCode                    = 2000
	ACIErrorCode                              = 2100
	InvocationErrorCode                       = 3000
	EncodingErrorCode                         = 3001
	BinaryEncodingErrorCode                   = 3002
	ZeroArgumentErrorCode                     = 3003
	MaxArgumentErrorCode                      = 3004
	OptionErrorCode                           = 3005
	OverlapErrorCode                          = 3006
	RequirementErrorCode                      = 3007
	ConversionErrorCode                       = 3008
	ValidationErrorCode                       = 3009
	NoSuchNamespaceErrorCode                  = 3010
	PasswordMismatchCode                      = 3011
	NotImplementedErrorCode                   = 3012
	NotConfiguredErrorCode                    = 3013
	PromptFailedCode                          = 3014
	DeprecationErrorCode                      = 3015
	NotAForestRootErrorCode                   = 3016
	ExecutionErrorCode                        = 4000
	NotFoundCode                              = 4001
	DuplicateEntryCode                        = 4002
	HostServiceCode                           = 4003
	MalformedServicePrincipalCode             = 4004
	RealmMismatchCode                         = 4005
	RequiresRootCode                          = 4006
	AlreadyPosixGroupCode                     = 4007
	MalformedUserPrincipalCode                = 4008
	AlreadyActiveCode                         = 4009
	AlreadyInactiveCode                       = 4010
	HasNSAccountLockCode                      = 4011
	NotGroupMemberCode                        = 4012
	RecursiveGroupCode                        = 4013
	AlreadyGroupMemberCode                    = 4014
	Base64DecodeErrorCode                     = 4015
	RemoteRetrieveErrorCode                   = 4016
	SameGroupErrorCode                        = 4017
	DefaultGroupErrorCode                     = 4018
	DNSNotARecordErrorCode                    = 4019
	ManagedGroupErrorCode                     = 4020
	ManagedPolicyErrorCode                    = 4021
	FileErrorCode                             = 4022
	NoCertificateErrorCode                    = 4023
	ManagedGroupExistsErrorCode               = 4024
	ReverseMemberErrorCode                    = 4025
	AttrValueNotFoundCode                     = 4026
	SingleMatchExpectedCode                   = 4027
	AlreadyExternalGroupCode                  = 4028
	ExternalGroupViolationCode                = 4029
	PosixGroupViolationCode                   = 4030
	EmptyResultCode                           = 4031
	InvalidDomainLevelErrorCode               = 4032
	ServerRemovalErrorCode                    = 4033
	OperationNotSupportedForPrincipalTypeCode = 4034
	HTTPRequestErrorCode                      = 4035
	RedundantMappingRuleCode                  = 4036
	CSRTemplateErrorCode                      = 4037
	AlreadyContainsValueErrorCode             = 4038
	BuiltinErrorCode                          = 4100
	HelpErrorCode                             = 4101
	LDAPErrorCode                             = 4200
	MidairCollisionCode                       = 4201
	EmptyModlistCode                          = 4202
	DatabaseErrorCode                         = 4203
	LimitsExceededCode                        = 4204
	ObjectclassViolationCode                  = 4205
	NotAllowedOnRDNCode                       = 4206
	OnlyOneValueAllowedCode                   = 4207
	InvalidSyntaxCode                         = 4208
	BadSearchFilterCode                       = 4209
	NotAllowedOnNonLeafCode                   = 4210
	DatabaseTimeoutCode                       = 4211
	DNSDataMismatchCode                       = 4212
	TaskTimeoutCode                           = 4213
	TimeLimitExceededCode                     = 4214
	SizeLimitExceededCode                     = 4215
	AdminLimitExceededCode                    = 4216
	CertificateErrorCode                      = 4300
	CertificateOperationErrorCode             = 4301
	CertificateFormatErrorCode                = 4302
	MutuallyExclusiveErrorCode                = 4303
	NonFatalErrorCode                         = 4304
	AlreadyRegisteredErrorCode                = 4305
	NotRegisteredErrorCode                    = 4306
	DependentEntryCode                        = 4307
	LastMemberErrorCode                       = 4308
	ProtectedEntryErrorCode                   = 4309
	CertificateInvalidErrorCode               = 4310
	SchemaUpToDateCode                        = 4311
	DNSErrorCode                              = 4400
	DNSResolverErrorCode                      = 4401
	TrustErrorCode                            = 4500
	TrustTopologyConflictErrorCode            = 4501
	GenericErrorCode                          = 5000
)

Standard FreeIPA error codes.

View Source
const LDAPGeneralizedTimeFormat = "20060102150405Z"

General date/time format in LDAP. https://github.com/freeipa/freeipa/blob/ipa-4-7/ipalib/constants.py#L271

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

The base object for connections to FreeIPA API.

func Connect

func Connect(host string, transport *http.Transport, user, password string) (*Client, error)

Make a new client and login using standard username/password.

func ConnectWithKerberos

func ConnectWithKerberos(host string, transport *http.Transport, options *KerberosConnectOptions) (*Client, error)

Create a new client using Kerberos authentication.

func (*Client) Do

func (c *Client) Do(req *Request) (*Response, error)

Have the client perform the request.

type KerberosConnectOptions

type KerberosConnectOptions struct {
	Krb5ConfigReader io.Reader
	KeytabReader     io.Reader
	User             string
	Realm            string
}

Options for connecting to Kerberos.

type Message

type Message struct {
	Type    string `json:"type"`
	Message string `json:"message"`
	Code    int    `json:"code"`
	Name    string `json:"name"`
}

Used in providing extra messages and error response.

type Request

type Request struct {
	Method string        `json:"method"`
	Params []interface{} `json:"params"`
}

Request format.

func NewRequest

func NewRequest(method string, args []interface{}, parms map[string]interface{}) *Request

Create a new API request.

type Response

type Response struct {
	Error     *Message `json:"error"`
	Result    *Result  `json:"result"`
	Version   string   `json:"version"`
	Principal string   `json:"principal"`
}

Standard response from FreeIPA.

func ParseResponse

func ParseResponse(body io.Reader) (*Response, error)

Parse response from reader.

func (*Response) BoolResult

func (r *Response) BoolResult() bool

Decode results which are boolean formatted, usually used to indicate success or state.

func (*Response) CountResults

func (r *Response) CountResults() int

Count the number of results that this request has.

func (*Response) Dict

func (r *Response) Dict() (map[string]interface{}, bool)

Return dictionary.

func (*Response) DictAtIndex

func (r *Response) DictAtIndex(index int) (map[string]interface{}, bool)

Return dictionary at index.

func (*Response) Get

func (r *Response) Get(key string) ([]interface{}, bool)

Get an interface for a key.

func (*Response) GetAtIndex

func (r *Response) GetAtIndex(index int, key string) ([]interface{}, bool)

Get an interface for a key.

func (*Response) GetBool

func (r *Response) GetBool(key string) (bool, bool)

Get a boolean from a key.

func (*Response) GetBoolAtIndex

func (r *Response) GetBoolAtIndex(index int, key string) (bool, bool)

Get a boolean from a key at an index.

func (*Response) GetData

func (r *Response) GetData(key string) ([]byte, bool)

Get byte array for key.

func (*Response) GetDataAtIndex

func (r *Response) GetDataAtIndex(index int, key string) ([]byte, bool)

Get byte array for key at an index.

func (*Response) GetDatas

func (r *Response) GetDatas(key string) ([][]byte, bool)

Get byte array for key.

func (*Response) GetDatasAtIndex

func (r *Response) GetDatasAtIndex(index int, key string) ([][]byte, bool)

Get byte array for key at an index.

func (*Response) GetDateTime

func (r *Response) GetDateTime(key string) (time.Time, bool)

Get date time value for key.

func (*Response) GetDateTimeAtIndex

func (r *Response) GetDateTimeAtIndex(index int, key string) (time.Time, bool)

Get date time value for key at an index.

func (*Response) GetDateTimes

func (r *Response) GetDateTimes(key string) ([]time.Time, bool)

Get date time value for key.

func (*Response) GetDateTimesAtIndex

func (r *Response) GetDateTimesAtIndex(index int, key string) ([]time.Time, bool)

Get date time value for key at an index.

func (*Response) GetString

func (r *Response) GetString(key string) (string, bool)

Get string value for key.

func (*Response) GetStringAtIndex

func (r *Response) GetStringAtIndex(index int, key string) (string, bool)

Get string value for key at an index.

func (*Response) GetStrings

func (r *Response) GetStrings(key string) ([]string, bool)

Get string value for key.

func (*Response) GetStringsAtIndex

func (r *Response) GetStringsAtIndex(index int, key string) ([]string, bool)

Get string value for key at an index.

func (*Response) Keys

func (r *Response) Keys() ([]string, bool)

Get all keys.

func (*Response) KeysAtIndex

func (r *Response) KeysAtIndex(index int) ([]string, bool)

Get all keys at index.

type Result

type Result struct {
	Count     int        `json:"count"`
	Truncated bool       `json:"truncated"`
	Messages  []*Message `json:"messages,omitempty"`
	// This result differs depending on response,
	// read the API documentation below for information.
	// https://github.com/freeipa/freeipa/tree/master/doc/api
	Result  interface{} `json:"result"`
	Summary string      `json:"summary,omitempty"`
	Value   string      `json:"value,omitempty"`
}

Standard result in response from FreeIPA.

Jump to

Keyboard shortcuts

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