opsmanager

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package opsmanager hosts a HTTP client which abstracts communication with Ops Manager instances.

To create a new client, you have to call the following code:

resolver := httpclient.NewURLResolverWithPrefix("http://OPS-MANAGER-INSTANCE", opsmanager.PublicApiPrefix)
client := opsmanager.NewClient(WithResolver(resolver))

The client can then be used to issue requests such as:

user := User{Username: ..., Password: ..., ...}
globalOwner := client.CreateFirstUser(user, WhitelistAllowAll)

See the Client interface below for a list of all the support operations. If however, you need one that is not currently supported, the _opsManagerApi_ struct extends _httpclient.BasicHTTPOperation_, allowing you to issue raw HTTP requests to the specified Ops Manager instance.

url := resolver.Of("/path/to/a/resource/%s", id)
resp:= client.GetJSON(url)
useful.PanicOnUnrecoverableError(resp.Err)
defer useful.LogError(resp.Response.Body.Close)
var data SomeType
decoder := json.NewDecoder(resp.Response.Body)
err := decoder.Decode(&result)
useful.PanicOnUnrecoverableError(err)
// do something with _data_

You can create an authenticated client as follows:

resolver := httpclient.NewURLResolverWithPrefix("http://OPS-MANAGER-INSTANCE", PublicAPIPrefix)
client:= opsmanager.NewClientWithDigestAuth(resolver, "username", "password")

The code above is a simplification of the following (which can be used for a more configurable set-up):

withResolver := opsmanager.WithResolver(httpclient.NewURLResolverWithPrefix("http://OPS-MANAGER-INSTANCE", PublicAPIPrefix))
withDigestAuth := httpclient.WithDigestAuthentication(publicKey, privateKey)
withHTTPClient := opsmanager.WithHTTPClient(httpclient.NewClient(withDigestAuth))
client := opsmanager.NewClient(withResolver, withHTTPClient)

The following can be used for authentication:

  • Ops Manager user credentials: (username, password) - only works with some APIs and should not be used
  • Programmatic API keys: (publicKey, privateKey) - preferred credentials pair
  • Ops Manager user and a Personal API Key: (username, personalAPIKey) - deprecated

You can read more about this topic here: https://docs.opsmanager.mongodb.com/master/tutorial/configure-public-api-access/#configure-public-api-access

Index

Constants

View Source
const PublicAPIPrefix = "/api/public/v1.0"

PublicAPIPrefix prefix

Variables

This section is empty.

Functions

func AddProcessToDeployment

func AddProcessToDeployment(process Process, automationConfig map[string]interface{}) map[string]interface{}

AddProcessToDeployment adds the specified Process to the processes list of the given deployment

func WithHTTPClient

func WithHTTPClient(basicClient httpclient.BasicClient) func(*opsManagerClient)

WithHTTPClient configures an Ops Manager which delegates basic HTTP operations to the specified client

func WithResolver

func WithResolver(resolver httpclient.URLResolver) func(*opsManagerClient)

WithResolver configures an Ops Manager client which relies on the specified resolver

Types

type AgentResult

type AgentResult struct {
	ConfCount int    `json:"confCount,omitempty"`
	Hostname  string `json:"hostname,omitempty"`
	LastConf  string `json:"lastConf,omitempty"`
	StateName string `json:"stateName,omitempty"`
	TypeName  string `json:"typeName,omitempty"`
}

AgentResult represents an agent returned by the GetAgentsByType() call

type Args26

type Args26 struct {
	NET       *Net       `json:"net,omitempty"`
	Storage   *Storage   `json:"storage,omitempty"`
	SystemLog *SystemLog `json:"systemLog,omitempty"`
}

Args26 part of the internal Process struct

type AutomationConfig

type AutomationConfig struct {
	Auth               map[string]interface{}   `json:"auth,omitempty"`
	LDAP               map[string]interface{}   `json:"ldap,omitempty"`
	Processes          []*Process               `json:"processes,omitempty"`
	ReplicaSets        []map[string]interface{} `json:"replicaSets,omitempty"`
	Roles              []map[string]interface{} `json:"roles,omitempty"`
	MonitoringVersions []*VersionHostnamePair   `json:"monitoringVersions,omitempty"`
	BackupVersions     []*VersionHostnamePair   `json:"backupVersions,omitempty"`
	MongoSQLDs         []map[string]interface{} `json:"mongosqlds,omitempty"`
	MongoDBVersions    []*MongoDBVersion        `json:"mongoDbVersions,omitempty"`
	AgentVersion       map[string]interface{}   `json:"agentVersion,omitempty"`
	Balancer           map[string]interface{}   `json:"balancer,omitempty"`
	CPSModules         []map[string]interface{} `json:"cpsModules,omitempty"`
	IndexConfigs       []map[string]interface{} `json:"indexConfigs,omitempty"`
	Kerberos           map[string]interface{}   `json:"kerberos,omitempty"`
	MongoTs            []map[string]interface{} `json:"mongots,omitempty"`
	Options            map[string]interface{}   `json:"options,omitempty"`
	SSL                map[string]interface{}   `json:"ssl,omitempty"`
	Version            int                      `json:"version,omitempty"`
	Sharding           []map[string]interface{} `json:"sharding,omitempty"`
	UIBaseURL          string                   `json:"uiBaseUrl,omitempty"`
}

AutomationConfig represents a cluster definition within an automation config object NOTE: this struct is mutable

type AutomationStatusResponse

type AutomationStatusResponse struct {
	Processes   []Process `json:"processes"`
	GoalVersion int       `json:"goalVersion"`
}

AutomationStatusResponse automation status

type Build

type Build struct {
	Architecture       string   `json:"architecture"`
	Bits               int      `json:"bits"`
	Flavor             string   `json:"flavor,omitempty"`
	GitVersion         string   `json:"gitVersion,omitempty"`
	MaxOsVersion       string   `json:"maxOsVersion,omitempty"`
	MinOsVersion       string   `json:"minOsVersion,omitempty"`
	Platform           string   `json:"platform,omitempty"`
	URL                string   `json:"url,omitempty"`
	Modules            []string `json:"modules,omitempty"`
	Win2008plus        bool     `json:"win2008plus,omitempty"`
	WinVCRedistDll     string   `json:"winVCRedistDll,omitempty"`
	WinVCRedistOptions []string `json:"winVCRedistOptions,omitempty"`
	WinVCRedistURL     string   `json:"winVCRedistUrl,omitempty"`
	WinVCRedistVersion string   `json:"winVCRedistVersion,omitempty"`
}

Build a MongoDB build

type Client

type Client interface {
	httpclient.BasicClient

	// https://docs.opsmanager.mongodb.com/master/reference/api/user-create-first/
	CreateFirstUser(user User, whitelistIP string) (CreateFirstUserResponse, error)
	// https://docs.opsmanager.mongodb.com/master/reference/api/groups/get-all-groups-for-current-user/
	GetAllProjects() (ProjectsResponse, error)
	// https://docs.opsmanager.mongodb.com/master/reference/api/groups/create-one-group/
	CreateOneProject(name string, orgID string) (CreateOneProjectResponse, error)
	// https://docs.opsmanager.mongodb.com/master/reference/api/automation-config/#get-the-automation-configuration
	GetAutomationConfig(projectID string) (AutomationConfig, error)
	// https://docs.opsmanager.mongodb.com/master/reference/api/automation-config/#update-the-automation-configuration
	UpdateAutomationConfig(projectID string, config AutomationConfig) (AutomationConfig, error)
	// GET /agents/api/automation/conf/v1/{projectID}
	GetRawAutomationConfig(projectID string) (RawAutomationConfig, error)
	// https://docs.opsmanager.mongodb.com/master/reference/api/automation-status/
	GetAutomationStatus(projectID string) (AutomationStatusResponse, error)
	// https://docs.opsmanager.mongodb.com/master/reference/api/agents-get-by-type/
	GetAgentsByType(projectID string, agentType string) (GetAgentsByTypeResponse, error)
	// https://docs.opsmanager.mongodb.com/master/reference/api/automation-config/#update-the-automation-configuration
	UpdateDeployments(projectID string, body io.Reader) (map[string]interface{}, error)
	// https://docs.opsmanager.mongodb.com/master/reference/api/agentapikeys/create-one-agent-api-key/
	CreateAgentAPIKEY(projectID string, desc string) (CreateAgentAPIKEYResponse, error)
}

Client defines the API actions implemented in this client

func NewClient

func NewClient(configs ...func(*opsManagerClient)) Client

NewClient builds a new API client for connecting to Ops Manager

func NewClientWithDigestAuth

func NewClientWithDigestAuth(resolver httpclient.URLResolver, username string, password string) Client

NewClientWithDigestAuth builds a new API client with default configurations, which uses digest authentication

func NewDefaultClient

func NewDefaultClient(resolver httpclient.URLResolver) Client

NewDefaultClient builds a new, unauthenticated, API client with default configurations

type CreateAgentAPIKEYResponse

type CreateAgentAPIKEYResponse struct {
	ID            string `json:"_id,omitempty"`
	CreatedBy     string `json:"createdBy,omitempty"`
	CreatedIPAddr string `json:"createdIpAddr,omitempty"`
	CreatedTime   int    `json:"createdTime,omitempty"`
	CreatedUserID string `json:"createdUserId,omitempty"`
	Desc          string `json:"desc,omitempty"`
	Key           string `json:"key,omitempty"`
}

CreateAgentAPIKEYResponse API response for the CreateAgentAPIKEY() call

type CreateFirstUserResponse

type CreateFirstUserResponse struct {
	APIKey string       `json:"apiKey"`
	User   UserResponse `json:"user"`
}

CreateFirstUserResponse API response for the CreateFirstUser() call

type CreateOneProjectResponse

type CreateOneProjectResponse struct {
	ID                string             `json:"id"`
	Name              string             `json:"name,omitempty"`
	AgentAPIKey       string             `json:"agentApiKey,omitempty"`
	ActiveAgentCount  int                `json:"activeAgentCount,omitempty"`
	HostCounts        map[string]int     `json:"hostCounts,omitempty"`
	LastActiveAgent   string             `json:"lastActiveAgent,omitempty"`
	LDAPGroupMappings []LDAPGroupMapping `json:"ldapGroupMappings,omitempty"`
	Links             []Link             `json:"links,omitempty"`
	OrgID             string             `json:"orgId,omitempty"`
	PublicAPIEnabled  bool               `json:"publicApiEnabled,omitempty"`
	ReplicaSetCount   int                `json:"replicaSetCount,omitempty"`
	ShardCount        int                `json:"shardCount,omitempty"`
	Tags              []string           `json:"tags,omitempty"`
}

CreateOneProjectResponse API response for the CreateOneProject() call

type GetAgentsByTypeResponse

type GetAgentsByTypeResponse struct {
	Links      []Link        `json:"links,omitempty"`
	Results    []AgentResult `json:"results,omitempty"`
	TotalCount int           `json:"totalCount,omitempty"`
}

GetAgentsByTypeResponse API response for the GetAgentsByType() call

type HostCounts

type HostCounts struct {
	Arbiter   int `json:"arbiter"`
	Config    int `json:"config"`
	Primary   int `json:"primary"`
	Secondary int `json:"secondary"`
	Mongos    int `json:"mongos"`
	Master    int `json:"master"`
	Slave     int `json:"slave"`
}

HostCounts for the project

type LDAPGroupMapping

type LDAPGroupMapping struct {
	RoleName   string   `json:"roleName,omitempty"`
	LdapGroups []string `json:"ldapGroups,omitempty"`
}

LDAPGroupMapping holds a single mapping of role to LDAP groups

type Link struct {
	HREF string `json:"href"`
	Rel  string `json:"rel"`
}

Link holder for links returned by the API

type LogRotate

type LogRotate struct {
	SizeThresholdMB  float64 `json:"sizeThresholdMB,omitempty"`
	TimeThresholdHrs int     `json:"timeThresholdHrs,omitempty"`
}

LogRotate part of the internal Process struct

type MongoDBVersion

type MongoDBVersion struct {
	Name   string  `json:"name,omitempty"`
	Builds []Build `json:"builds,omitempty"`
}

MongoDBVersion ways to install MongoDB

type Net

type Net struct {
	Port int `json:"port,omitempty"`
}

Net part of the internal Process struct

type Process

type Process struct {
	Name                        string     `json:"name,omitempty"`
	ProcessType                 string     `json:"processType,omitempty"`
	Version                     string     `json:"version,omitempty"`
	AuthSchemaVersion           int        `json:"authSchemaVersion,omitempty"`
	FeatureCompatibilityVersion string     `json:"featureCompatibilityVersion,omitempty"`
	Disabled                    bool       `json:"disabled,omitempty"`
	ManualMode                  bool       `json:"manualMode,omitempty"`
	Hostname                    string     `json:"hostname,omitempty"`
	Args26                      *Args26    `json:"args2_6,omitempty"`
	LogRotate                   *LogRotate `json:"logRotate,omitempty"`
	Plan                        []string   `json:"plan,omitempty"`
	LastGoalVersionAchieved     int        `json:"lastGoalVersionAchieved,omitempty"`
}

Process represents a single process in a deployment

type ProjectResponse

type ProjectResponse struct {
	ID               string     `json:"id"`
	OrgID            string     `json:"orgId"`
	Name             string     `json:"name"`
	LastActiveAgent  string     `json:"lastActiveAgent,omitempty"`
	AgentAPIKey      string     `json:"agentApiKey,omitempty"`
	ActiveAgentCount int        `json:"activeAgentCount"`
	HostCounts       HostCounts `json:"hostCounts,omitempty"`
	PublicAPIEnabled bool       `json:"publicApiEnabled"`
	ReplicaSetCount  int        `json:"replicaSetCount"`
	ShardCount       int        `json:"shardCount"`
	Tags             []string   `json:"tags,omitempty"`
	Links            []Link     `json:"links,omitempty"`
}

ProjectResponse represents the structure of a project

type ProjectsResponse

type ProjectsResponse struct {
	Links      []Link            `json:"links"`
	Results    []ProjectResponse `json:"results"`
	TotalCount int               `json:"totalCount"`
}

ProjectsResponse represents a array of project

type RawAutomationConfig

type RawAutomationConfig struct {
	IDCounter                        int                    `json:"idCounter,omitempty"`
	State                            string                 `json:"state,omitempty"`
	Version                          int                    `json:"version,omitempty"`
	GroupID                          string                 `json:"groupId,omitempty"`
	UserID                           string                 `json:"userId,omitempty"`
	PublishTimestamp                 int                    `json:"publishTimestamp,omitempty"`
	PublishedVersion                 string                 `json:"publishedVersion,omitempty"`
	SaveTimestamp                    int                    `json:"saveTimestamp,omitempty"`
	LatestAutomationAgentVersionName string                 `json:"latestAutomationAgentVersionName,omitempty"`
	LatestMonitoringAgentVersionName string                 `json:"latestMonitoringAgentVersionName,omitempty"`
	LatestBackupAgentVersionName     string                 `json:"latestBackupAgentVersionName,omitempty"`
	LatestBiConnectorVersionName     string                 `json:"latestBiConnectorVersionName,omitempty"`
	Cluster                          *AutomationConfig      `json:"cluster,omitempty"`
	VersionConfig                    map[string]interface{} `json:"versionConfig,omitempty"`
	LogRotate                        map[string]interface{} `json:"logRotate,omitempty"`
	MonitoringAgentTemplate          map[string]interface{} `json:"monitoringAgentTemplate,omitempty"`
	BackupAgentTemplate              map[string]interface{} `json:"backupAgentTemplate,omitempty"`
	CPSModuleTemplate                map[string]interface{} `json:"cpsModuleTemplate,omitempty"`
	DeploymentJobStatuses            []interface{}
}

RawAutomationConfig represents a raw automation config NOTE: this struct is mutable

type Result

type Result struct {
	Links     []Link   `json:"links"`
	RoleNames []string `json:"roleNames"`
	TeamID    string   `json:"teamId"`
}

Result is part of TeamsAssigned structure

type Storage

type Storage struct {
	DBPath string `json:"dbPath,omitempty"`
}

Storage part of the internal Process struct

type SystemLog

type SystemLog struct {
	Destination string `json:"destination,omitempty"`
	Path        string `json:"path,omitempty"`
}

SystemLog part of the internal Process struct

type User

type User struct {
	Username     string `json:"username"`
	Password     string `json:"password,omitempty"`
	FirstName    string `json:"firstName"`
	LastName     string `json:"lastName"`
	EmailAddress string `json:"emailAddress,omitempty"`
}

User request object which identifies a user

type UserResponse

type UserResponse struct {
	User

	ID    string     `json:"id"`
	Links []Link     `json:"links,omitempty"`
	Roles []UserRole `json:"roles,omitempty"`
}

UserResponse wrapper for a user response, augmented with a few extra fields

type UserRole

type UserRole struct {
	RoleName string `json:"roleName"`
	GroupID  string `json:"groupId,omitempty"`
	OrgID    string `json:"orgId,omitempty"`
}

UserRole denotes a single user role

type VersionHostnamePair

type VersionHostnamePair struct {
	Name     string `json:"name"`
	Hostname string `json:"hostname"`
}

VersionHostnamePair represents a pair of version name and hostname strings

Jump to

Keyboard shortcuts

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