jcapi

package module
v0.0.0-...-45efc78 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2018 License: MPL-2.0 Imports: 12 Imported by: 16

README

jcapi

This older Go Repository only supports JumpCloud's V1 API endpoints and is not currently up to date with our API functionality. For current V1 & V2 API Support please refer to jcapi-go

The scripts under the 'examples' folder in this repo are now deprecated. Please refer to the support repository for the maintained examples scripts.

Binaries for these scripts can be found in the releases for the support repository.

JumpCloud's Go (golang) REST API SDK (BETA) Copyright (C) 2015 JumpCloud

This JumpCloud SDK is in beta form. The only available documentation comes in the form of the included examples and from jcapi_test.go

This API exposes several JumpCloud REST APIs:

Documentation

Index

Constants

View Source
const (
	COMMAND_PATH     string = "/commands"
	RUN_COMMAND_PATH string = "/runCommand"

	COMMAND_ROOT_USER string = "000000000000000000000000"
)
View Source
const (
	BAD_FIELD_NAME      = -3
	OBJECT_NOT_FOUND    = -2
	BAD_COMPARISON_TYPE = -1
)
View Source
const (
	AUTHENTICATE_PATH string = "/authenticate"
)
View Source
const (
	COMMAND_RESULTS_PATH string = "/commandresults"
)
View Source
const (
	IDSOURCES_PATH string = "/idsources"
)
View Source
const (
	RADIUS_SERVERS_PATH string = "/radiusservers"
)
View Source
const (
	SYSTEMS_PATH string = "/systems"
)
View Source
const (
	StdUrlBase = "https://console.jumpcloud.com/api"
)
View Source
const (
	TAGS_PATH string = "/tags"
)

Variables

This section is empty.

Functions

func FindObject

func FindObject(sourceArray []interface{}, fieldName string, compareData interface{}) (index int)

func FindObjectByStringRegex

func FindObjectByStringRegex(sourceArray []interface{}, fieldName string, regex string) (index int, err error)

func GetInterfaceArrayFromJCCommand

func GetInterfaceArrayFromJCCommand(commands []JCCommand) (interfaceArray []interface{})

func GetInterfaceArrayFromJCCommandResults

func GetInterfaceArrayFromJCCommandResults(commandResults []JCCommandResult) (interfaceArray []interface{})

func GetInterfaceArrayFromJCRadiusServer

func GetInterfaceArrayFromJCRadiusServer(radiusServers []JCRadiusServer) (interfaceArray []interface{})

func GetInterfaceArrayFromJCSystems

func GetInterfaceArrayFromJCSystems(systems []JCSystem) (interfaceArray []interface{})

func GetTagNames

func GetTagNames(tags []JCTag) []string

func GetTrueOrFalse

func GetTrueOrFalse(input interface{}) bool

func MapJCOpToHTTP

func MapJCOpToHTTP(op JCOp) string

func SystemsToString

func SystemsToString(systems []JCSystem) string

func UsersToString

func UsersToString(users []JCUser) string

Types

type JCAPI

type JCAPI struct {
	ApiKey  string
	UrlBase string
}

func NewJCAPI

func NewJCAPI(apiKey string, urlBase string) JCAPI

func (JCAPI) AddUpdateCommand

func (jc JCAPI) AddUpdateCommand(op JCOp, command JCCommand) (commandResult JCCommand, err JCError)

Add or Update a command in place on JumpCloud

AddUpdateCommand returns an entire struct, so that the workflow ID can be obtained for running commands. This is a departure from other AddUpdate*() functions in this API, which generally just return the ID, because that is sufficient for most use cases.

func (JCAPI) AddUpdateIDSource

func (jc JCAPI) AddUpdateIDSource(op JCOp, idSource JCIDSource) (string, JCError)

Add or Update an ID source in place on JumpCloud

func (JCAPI) AddUpdateRadiusServer

func (jc JCAPI) AddUpdateRadiusServer(op JCOp, radiusServer JCRadiusServer) (id string, err JCError)

Add or Update a radiusserver in place on JumpCloud

func (JCAPI) AddUpdateTag

func (jc JCAPI) AddUpdateTag(op JCOp, tag JCTag) (tagId string, err JCError)

Add or Update a tag in place on JumpCloud

func (JCAPI) AddUpdateUser

func (jc JCAPI) AddUpdateUser(op JCOp, user JCUser) (userId string, err JCError)

Add or Update a new user to JumpCloud

func (JCAPI) AuthUser

func (jc JCAPI) AuthUser(username, password, tag string) (userAuthenticated bool, err error)

func (JCAPI) Delete

func (jc JCAPI) Delete(url string) (interface{}, JCError)

func (JCAPI) DeleteCommand

func (jc JCAPI) DeleteCommand(command JCCommand) JCError

func (JCAPI) DeleteCommandResult

func (jc JCAPI) DeleteCommandResult(id string) (err JCError)

func (JCAPI) DeleteIDSource

func (jc JCAPI) DeleteIDSource(idSource JCIDSource) JCError

func (JCAPI) DeleteRadiusServer

func (jc JCAPI) DeleteRadiusServer(radiusServer JCRadiusServer) JCError

func (JCAPI) DeleteSystem

func (jc JCAPI) DeleteSystem(system JCSystem) JCError
!!!!!!!!!!!!WARNING!!!!!!!!!!!!

This will cause JumpCloud to uninstall the agent on this system.

You will lose control of the system after the call returns.

func (JCAPI) DeleteTag

func (jc JCAPI) DeleteTag(tag JCTag) JCError

func (JCAPI) DeleteUser

func (jc JCAPI) DeleteUser(user JCUser) JCError

func (JCAPI) Do

func (jc JCAPI) Do(op, url string, data []byte) (interface{}, JCError)

DEPRECATED: This version of Do() will be replaced by the code in DoBytes() in the future, when the jcapi-systemuser issue is corrected to allow for marshalling and unmarshalling using the same object.

func (JCAPI) DoBytes

func (jc JCAPI) DoBytes(op, urlQuery string, data []byte) ([]byte, JCError)

func (JCAPI) Get

func (jc JCAPI) Get(url string) (interface{}, JCError)

func (JCAPI) GetAllCommands

func (jc JCAPI) GetAllCommands() (commandList []JCCommand, err JCError)

func (JCAPI) GetAllIDSources

func (jc JCAPI) GetAllIDSources() (idSources []JCIDSource, err JCError)

func (JCAPI) GetAllRadiusServers

func (jc JCAPI) GetAllRadiusServers() (radiusServers []JCRadiusServer, err JCError)

func (JCAPI) GetAllTags

func (jc JCAPI) GetAllTags() (tagList []JCTag, err JCError)

func (JCAPI) GetCommandResultDetailsById

func (jc JCAPI) GetCommandResultDetailsById(id string) (commandResult JCCommandResult, err JCError)

func (JCAPI) GetCommandResultsByName

func (jc JCAPI) GetCommandResultsByName(name string) (commandResultList []JCCommandResult, err JCError)

func (JCAPI) GetCommandResultsBySavedCommandID

func (jc JCAPI) GetCommandResultsBySavedCommandID(id string) (commandResults []JCCommandResult, err JCError)

func (JCAPI) GetIDSourceByName

func (jc JCAPI) GetIDSourceByName(name string) (idSource JCIDSource, exists bool, err JCError)

func (JCAPI) GetSystemByHostName

func (jc JCAPI) GetSystemByHostName(hostname string, withTags bool) ([]JCSystem, JCError)

Executes a search by hostname via the JumpCloud API

func (JCAPI) GetSystemById

func (jc JCAPI) GetSystemById(systemId string, withTags bool) (system JCSystem, err JCError)

func (JCAPI) GetSystemUserBindingsById

func (jc JCAPI) GetSystemUserBindingsById(systemId string) (systemUserBindings []SystemUserBinding, err JCError)

GetSystemUserBindingsById returns all the user bindings for the given system Id: this includes the direct system-user bindings as well as the bindings made via tags

func (JCAPI) GetSystemUserByEmail

func (jc JCAPI) GetSystemUserByEmail(email string, withTags bool) ([]JCUser, JCError)

Executes a search by email via the JumpCloud API

func (JCAPI) GetSystemUserById

func (jc JCAPI) GetSystemUserById(userId string, withTags bool) (user JCUser, err JCError)

func (JCAPI) GetSystemUsers

func (jc JCAPI) GetSystemUsers(withTags bool) (userList []JCUser, err JCError)

func (JCAPI) GetSystems

func (jc JCAPI) GetSystems(withTags bool) (systems []JCSystem, err JCError)

func (JCAPI) GetTagByName

func (jc JCAPI) GetTagByName(tagName string) (tag JCTag, err JCError)

func (JCAPI) GetTagsByUrl

func (jc JCAPI) GetTagsByUrl(urlPath string) (tagList []JCTag, err JCError)

func (JCAPI) HandleCommand

func (jc JCAPI) HandleCommand(path string, op JCOp, command JCCommand) (commandResult JCCommand, err JCError)

func (JCAPI) List

func (jc JCAPI) List(url string) (interface{}, JCError)

func (JCAPI) Post

func (jc JCAPI) Post(url string, data []byte) (interface{}, JCError)

func (JCAPI) Put

func (jc JCAPI) Put(url string, data []byte) (interface{}, JCError)

func (JCAPI) RunCommand

func (jc JCAPI) RunCommand(command JCCommand) JCError

func (JCAPI) SendUserActivationEmail

func (jc JCAPI) SendUserActivationEmail(userList []JCUser) (err JCError)

Resend user email

func (JCAPI) UpdateSystem

func (jc JCAPI) UpdateSystem(system JCSystem) (systemId string, err JCError)

Update a system

type JCCommand

type JCCommand struct {
	Id               string   `json:"_id,omitempty"`            // unique database ID
	Name             string   `json:"name"`                     // a title for display in the UI
	Command          string   `json:"command"`                  // the actual command string to execute
	CommandRunners   []string `json:"commandRunners,omitempty"` // Command Runner user IDs able to run this command
	CommandType      string   `json:"commandType"`              // linux/windows/mac
	User             string   `json:"user,omitempty"`           // user to run as (000000000000000000000000 for root)
	Files            []string `json:"files,omitempty"`          // list of files uploaded by the command
	Systems          []string `json:"systems,omitempty"`        // systems to run the command on
	Tags             []string `json:"tags,omitempty"`           // tags to run the command on (tags and systems are mutually exclusive)
	LaunchType       string   `json:"launchType"`               // manual/add-delete-user/repeated/scheduled
	ListensTo        string   `json:"listensTo"`                // AddUser/DeleteUser (when launchType is add-delete-user)
	Schedule         string   `json:"schedule,omitempty"`       // immediate/agentEvent (launchType=add-delete-user)/a crontab(5) time entry as in "0 0 2 * * 6"
	ScheduledRunDate string   `json:"scheduledRunDate"`         // when LaunchType='scheduled', set to the date on which to start the command
	ScheduledRunTime string   `json:"scheduledRunTime"`         // when LaunchType='scheduled', set to the time at which to start the command
	Trigger          string   `json:"trigger,omitempty"`        // generate trigger (No longer supported)
	Timeout          string   `json:"timeout"`                  // Command time out in seconds, after which it will be killed
	Organization     string   `json:"organization,omitempty"`   // organization ID for this command (auto-populated)
	Sudo             bool     `json:"sudo"`                     // Indicates whether the command should be run with sudo
	Shell            string   `json:"shell"`                    // Shell needed for Windows only, with which to execute the command (powershell/cmd)

	Skip  int `json:"skip"`  // Objects to skip on /search POST
	Limit int `json:"limit"` // Max objects to return on /search POST
}

func FindCommandById

func FindCommandById(commands []JCCommand, id string) (result *JCCommand, index int)

func (JCCommand) ToString

func (e JCCommand) ToString() string

type JCCommandResult

type JCCommandResult struct {
	Id                 string     `json:"_id,omitempty"`                // unique database ID
	Name               string     `json:"name"`                         // a title for display in the UI
	Command            string     `json:"command"`                      // the actual command string to execute
	RequestTime        string     `json:"requestTime,omitempty"`        // The time the command started
	ResponseTime       string     `json:"responseTime,omitempty"`       // The time the command exited
	Organization       string     `json:"organization,omitempty"`       // organization ID for this command (auto-populated)
	Sudo               bool       `json:"sudo"`                         // Indicates whether the command should be run with sudo
	System             string     `json:"system,omitempty"`             // The hostname of the system from which this result came
	WorkflowId         string     `json:"workflowId,omitempty"`         // The ID of the workflow of which this command was a part
	WorkflowInstanceId string     `json:"workflowInstanceId,omitempty"` // The instance ID of the workflow of which this command was a part
	Response           JCResponse `json:"response,omitempty"`           // Response data, including command output, and exit code
	Files              []string   `json:"files,omitempty"`              // Names of files uploaded for this command to use during execution
}

func FindCommandResultById

func FindCommandResultById(commandResults []JCCommandResult, id string) (result *JCCommandResult, index int)

func (JCCommandResult) ToString

func (e JCCommandResult) ToString() string

type JCCommandResultResults

type JCCommandResultResults struct {
	Results []JCCommandResult `json:"results"`
}

type JCCommandResults

type JCCommandResults struct {
	Results []JCCommand `json:"results"`
}

type JCData

type JCData struct {
	Output   string `json:"output,omitempty"`
	ExitCode int    `json:"exitCode"`
}

type JCError

type JCError interface {
	Error() string
}

type JCIDSource

type JCIDSource struct {
	Id             string `json:"_id,omitempty"`
	Name           string `json:"name"`
	Organization   string `json:"organization,omitempty"`
	Type           string `json:type`
	Version        string `json:version`
	IpAddress      string `json:ipAddress`
	LastUpdateTime string `json:lastUpdateTime,omitempty`
	DN             string `json:dn`
	Active         bool   `json:active,omitempty`
}

func (JCIDSource) ToString

func (e JCIDSource) ToString() string

type JCIDSourceResults

type JCIDSourceResults struct {
	Results []JCIDSource `json:"results"`
}

type JCNetworkInterface

type JCNetworkInterface struct {
	Name     string `json:"name"`
	Internal bool   `json:"internal"`
	Family   string `json:"family"`
	Address  string `json:"address"`
}

type JCOp

type JCOp uint8
const (
	Read   JCOp = 1
	Insert JCOp = 2
	Update JCOp = 3
	Delete JCOp = 4
	List   JCOp = 5
)

type JCRadiusServer

type JCRadiusServer struct {
	Id              string   `json:"_id,omitempty"`
	Name            string   `json:"name,omitempty"`
	NetworkSourceIP string   `json:"networkSourceIp,omitempty"`
	SharedSecret    string   `json:"sharedSecret,omitempty"`
	TagList         []string `json:"tags,omitempty"`
}

func FindRadiusServerById

func FindRadiusServerById(radiusServers []JCRadiusServer, id string) (radiusServer *JCRadiusServer)

func (JCRadiusServer) ToString

func (e JCRadiusServer) ToString() string

type JCRadiusServerResults

type JCRadiusServerResults struct {
	Results []JCRadiusServer `json:"results"`
}

type JCResponse

type JCResponse struct {
	Id    string `json:"id,omitempty"`
	Data  JCData `json:"data,omitempty"`
	Error string `json:"error,omitempty"`
}

type JCRestAuth

type JCRestAuth struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Tag      string `json:"tag"`
}

func (JCRestAuth) ToString

func (e JCRestAuth) ToString() string

type JCSSHDParam

type JCSSHDParam struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type JCSystem

type JCSystem struct {
	Os                             string  `json:"os,omitempty"`
	TemplateName                   string  `json:"templateName,omitempty"`
	AllowSshRootLogin              bool    `json:"allowSshRootLogin"`
	Id                             string  `json:"_id"`
	LastContact                    string  `json:"lastContact,omitempty"`
	RemoteIP                       string  `json:"remoteIP,omitempty"`
	Active                         bool    `json:"active,omitempty"`
	SshRootEnabled                 bool    `json:"sshRootEnabled"`
	AmazonInstanceID               string  `json:"amazonInstanceID,omitempty"`
	SshPassEnabled                 bool    `json:"sshPassEnabled,omitempty"`
	Version                        string  `json:"version,omitempty"`
	AgentVersion                   string  `json:"agentVersion,omitempty"`
	AllowPublicKeyAuth             bool    `json:"allowPublicKeyAuthentication"`
	Organization                   string  `json:"organization,omitempty"`
	Created                        string  `json:"created,omitempty"`
	Arch                           string  `json:"arch,omitempty"`
	SystemTimezone                 float64 `json:"systemTimeZone,omitempty"`
	AllowSshPasswordAuthentication bool    `json:"allowSshPasswordAuthentication"`
	DisplayName                    string  `json:"displayName"`
	ModifySSHDConfig               bool    `json:"modifySSHDConfig"`
	AllowMultiFactorAuthentication bool    `json:"allowMultiFactorAuthentication"`
	Hostname                       string  `json:"hostname,omitempty"`

	ConnectionHistoryList []string             `json:"connectionHistory,omitempty"`
	SshdParams            []JCSSHDParam        `json:"sshdParams,omitempty"`
	NetworkInterfaces     []JCNetworkInterface `json:"networkInterfaces, omitempty"`

	// Derived by JCAPI
	TagList []string `json:"tags,omitempty"`
	Tags    []JCTag
}

func (*JCSystem) AddJCTagsToSystem

func (system *JCSystem) AddJCTagsToSystem(tags []JCTag)

Add all the tags of which the system is a part to the JCSystem object

func (JCSystem) SystemHasTag

func (jcsystem JCSystem) SystemHasTag(tagName string) (hasTag bool, tagId string)

func (JCSystem) ToString

func (jcsystem JCSystem) ToString() string

type JCSystemResults

type JCSystemResults struct {
	Results []JCSystem `json:"results"`
}

type JCTag

type JCTag struct {
	Id                 string   `json:"_id,omitempty"`
	Name               string   `json:"name"`
	GroupName          string   `json:"groupname"`
	Systems            []string `json:"systems"`
	SystemUsers        []string `json:"systemusers"`
	RegularExpressions []string `json:"regularExpressions"`
	ExpirationTime     string   `json:"expirationTime"`
	Expired            bool     `json:"expired"`
	Selected           bool     `json:"selected"`

	//
	// For identification as an external user directory source
	//
	ExternallyManaged  bool   `json:"externallyManaged"`
	ExternalDN         string `json:"externalDN,omitempty"`
	ExternalSourceType string `json:"externalSourceType,omitempty"`

	ApplyToJumpCloud bool
}

func (JCTag) ToString

func (tag JCTag) ToString() string

type JCTagResults

type JCTagResults struct {
	Results []JCTag `json:"results"`
}

type JCUser

type JCUser struct {
	Id                          string    `json:"_id,omitempty"`
	UserName                    string    `json:"username,omitempty"`
	FirstName                   string    `json:"firstname,omitempty"`
	LastName                    string    `json:"lastname,omitempty"`
	Email                       string    `json:"email"`
	Password                    string    `json:"password,omitempty"`
	PasswordDate                string    `json:"password_date,omitempty"`
	Activated                   bool      `json:"activated"`
	ActivationKey               string    `json:"activation_key"`
	ExpiredWarned               bool      `json:"expired_warned"`
	PasswordExpired             bool      `json:"password_expired"`
	PasswordExpirationDate      time.Time `json:"password_expiration_date,omitempty"`
	PendingProvisioning         bool      `json:"pendingProvisioning,omitempty"`
	Sudo                        bool      `json:"sudo"`
	Uid                         string    `json:"unix_uid"`
	Gid                         string    `json:"unix_guid"`
	EnableManagedUid            bool      `json:"enable_managed_uid"`
	EnableUserPortalMultifactor bool      `json:"enable_user_portal_multifactor"`
	TotpEnabled                 bool      `json:"totp_enabled"`

	Attributes []JCUserAttribute `json:"attributes,omitempty"`

	TagIds []string `json:"tags,omitempty"` // the list of tag IDs that this user should be put in

	//
	// For identification as an external user directory source
	//
	ExternallyManaged  bool   `json:"externally_managed"`
	ExternalDN         string `json:"external_dn,omitempty"`
	ExternalSourceType string `json:"external_source_type,omitempty"`

	Tags []JCTag // the list of actual tags the user is in
}

If you add a field here make sure to add corresponding logic to getJCUserFieldsFromInterface

func (*JCUser) AddJCTags

func (user *JCUser) AddJCTags(tags []JCTag)

Add all the tags of which the user is a part to the JCUser object

func (JCUser) ToString

func (jcuser JCUser) ToString() string

type JCUserAttribute

type JCUserAttribute struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

func (JCUserAttribute) ToString

func (attribute JCUserAttribute) ToString() string

type JCUserEmailRequest

type JCUserEmailRequest struct {
	IsSelectAll bool     `json:"isSelectAll"`
	Models      []JCUser `json:"models"`
}

Special request structure for sending activation emails

type SystemUserBinding

type SystemUserBinding struct {
	UserId   string   `json:"id,omitempty"`
	Username string   `json:"username,omitempty"`
	Tags     []string `json:"tags,omitempty"`
}

this struct describes a system user binding :

Jump to

Keyboard shortcuts

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