util

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package util contains common routines used throughout the command base

Package util contains common routines used throughout the command base

Index

Constants

View Source
const DateFormat = "2006-01-02 15:04:05 -0700 MST"

DateFormat should be used in date formatting calls to ensure uniformity of output

View Source
const RefreshTokenTime = 86400

RefreshTokenTime represent when a JWT token will be refreshed, based on this many seconds left on the expiry time

Variables

View Source
var (
	// UserAgent will be used as the http user agent when making API calls
	UserAgent string

	// JSON tells us if we should output JSON
	JSON bool

	// Config is a global Config object
	Config *config.ConchConfig

	// ActiveProfile represents, well, the active profile
	ActiveProfile *config.ConchProfile

	// API is a global Conch API object
	API *conch.Conch
)
View Source
var (
	Version   string
	BuildTime string
	GitRev    string
	BuildHost string
)

These variables are provided by the build environment

Functions

func Bail

func Bail(err error)

Bail is a --json aware way of dying

func BuildAPI

func BuildAPI()

BuildAPI builds a Conch object

func BuildAPIAndVerifyLogin

func BuildAPIAndVerifyLogin()

BuildAPIAndVerifyLogin builds a Conch object using the Config data and calls VerifyLogin

func DisplayDevices

func DisplayDevices(devices []conch.Device, fullOutput bool) (err error)

DisplayDevices is an abstraction to make sure that the output of Devices is uniform, be it tables, json, or full json

func FindShortUUID added in v0.3.0

func FindShortUUID(s string, uuids []uuid.UUID) (uuid.UUID, error)

FindShortUUID takes a string and tries to find a UUID in a list of UUIDs that match by prefix (first 4 bytes)

func GenerateDeviceFlags

func GenerateDeviceFlags(d conch.Device) (flags string)

GenerateDeviceFlags is an abstraction to make sure that the 'flags' field for Devices remains uniform

func GetMarkdownTable

func GetMarkdownTable() (table *tablewriter.Table)

GetMarkdownTable returns a tablewriter configured to output markdown compatible text

func InteractiveForcePasswordChange added in v1.4.0

func InteractiveForcePasswordChange()

InteractiveForcePasswordChange is an abstraction for the process of prompting a user for a new password, validating it, and issuing the API calls to execute the change

func IsPasswordSane added in v1.4.0

func IsPasswordSane(password string, profile *config.ConchProfile) error

IsPasswordSane verifies that the given password follows the current rules and restrictions

func JSONOut

func JSONOut(thingy interface{})

JSONOut marshals an interface to JSON

func JSONOutIndent added in v1.2.0

func JSONOutIndent(thingy interface{})

JSONOutIndent marshals an interface to indented JSON

func MagicDBProductID added in v1.3.0

func MagicDBProductID(wat string) (uuid.UUID, error)

MagicDBProductID takes a string and tries to find a valid UUID. If the string is a UUID, it doesn't get checked further. If not, we dig through GetHardwareProducts() looking for UUIDs that match up to the first hyphen or where the product name or SKU matches the string

func MagicDeviceRoleID added in v0.3.0

func MagicDeviceRoleID(wat string) (id uuid.UUID, err error)

MagicDeviceRoleID takes a string and tries to find a valid UUID. If the string is a UUID, it doesn't get checked further. If not, we dig through GetDeviceRoles() looking for UUIDs that match up to the first hyphen

func MagicDeviceServiceID added in v0.3.0

func MagicDeviceServiceID(wat string) (id uuid.UUID, err error)

MagicDeviceServiceID takes a string and tries to find a valid UUID. If the string is a UUID, it doesn't get checked further. If not, we dig through GetDeviceServices() looking for UUIDs that match up to the first hyphen or where the device service name matches the string

func MagicGlobalDatacenterID added in v1.2.0

func MagicGlobalDatacenterID(wat string) (uuid.UUID, error)

MagicGlobalDatacenterID takes a string and tries to find a valid global datacenter UUID. If the string is a UUID, it doesn't get checked further. If it's not a UUID, we dig through GetGlobalDatacenters() looking for UUIDs that match up to the first hyphen. *NOTE*: This will fail if the user is not a global admin

func MagicGlobalRackID added in v1.2.0

func MagicGlobalRackID(wat string) (uuid.UUID, error)

MagicGlobalRackID takes a string and tries to find a valid global rack UUID. If the string is a UUID, it doesn't get checked further. If it's not a UUID, we dig through GetGlobalRacks() looking for UUIDs that match up to the first hyphen. *NOTE*: This will fail if the user is not a global admin

func MagicGlobalRackLayoutSlotID added in v1.2.0

func MagicGlobalRackLayoutSlotID(wat string) (uuid.UUID, error)

MagicGlobalRackLayoutSlotID takes a string and tries to find a valid UUID. If the string is a UUID, it doesn't get checked further. If it's not a UUID, we dig through GetGlobalRackLayoutSlots�() looking for UUIDs that match up to the first hyphen. *NOTE*: This will fail if the user is not a global admin

func MagicGlobalRackRoleID added in v1.2.0

func MagicGlobalRackRoleID(wat string) (id uuid.UUID, err error)

MagicGlobalRackRoleID takes a string and tries to find a valid UUID. If the string is a UUID, it doesn't get checked further. If not, we dig through GetGlobalRackRoles() looking for UUIDs that match up to the first hyphen or where the role name matches the string *NOTE*: This will fail if the user is not a global admin

func MagicGlobalRoomID added in v1.2.0

func MagicGlobalRoomID(wat string) (uuid.UUID, error)

MagicGlobalRoomID takes a string and tries to find a valid global UUID. If the string is a UUID, it doesn't get checked further. If it's not a UUID, we dig through GetGlobalRooms() looking for UUIDs that match up to the first hyphen. *NOTE*: This will fail if the user is not a global admin

func MagicProductID

func MagicProductID(wat string) (uuid.UUID, error)

MagicProductID takes a string and tries to find a valid UUID. If the string is a UUID, it doesn't get checked further. If not, we dig through GetHardwareProducts() looking for UUIDs that match up to the first hyphen or where the product name or SKU matches the string

func MagicRackID

func MagicRackID(workspace fmt.Stringer, wat string) (uuid.UUID, error)

MagicRackID takes a workspace UUID and a string and tries to find a valid rack UUID. If the string is a UUID, it doesn't get checked further. If it's not a UUID, we dig through GetWorkspaceRacks() looking for UUIDs that match up to the first hyphen or where the name matches the string.

func MagicValidationID added in v0.3.0

func MagicValidationID(s string) (uuid.UUID, error)

MagicValidationID takes a string and tries to find a valid UUID. If the string is a UUID, it doesn't get checked further. Otherwise, we use FindShortUUID to see if the string matches an existing Validation ID

func MagicValidationPlanID added in v0.3.0

func MagicValidationPlanID(s string) (uuid.UUID, error)

MagicValidationPlanID takes a string and tries to find a valid UUID. If the string is a UUID, it doesn't get checked further. Otherwise, we use FindShortUUID to see if the string matches an existing Validation Plan ID

func MagicWorkspaceID

func MagicWorkspaceID(wat string) (id uuid.UUID, err error)

MagicWorkspaceID takes a string and tries to find a valid UUID. If the string is a UUID, it doesn't get checked further. If not, we dig through GetWorkspaces() looking for UUIDs that match up to the first hyphen or where the workspace name matches the string

func TableizeMinimalDevices

func TableizeMinimalDevices(devices []MinimalDevice, fullOutput bool, table *tablewriter.Table) *tablewriter.Table

TableizeMinimalDevices is an abstraction to make sure that tables of Devices-turned-MinimalDevices are uniform

func TimeStr

func TimeStr(t time.Time) string

TimeStr ensures that all Times are formatted using .Local() and DateFormat

func WriteConfig added in v0.2.0

func WriteConfig()

WriteConfig serializes the Config struct to disk

Types

type GithubAsset added in v1.1.0

type GithubAsset struct {
	URL                string `json:"url"`
	Name               string `json:"name"`
	State              string `json:"state"`
	BrowserDownloadURL string `json:"browser_download_url"`
}

GithubAsset represents a file inside of a github release

type GithubRelease

type GithubRelease struct {
	URL     string         `json:"html_url"`
	TagName string         `json:"tag_name"`
	SemVer  semver.Version `json:"-"` // Will be set to 0.0.0 if no releases are found
	Body    string         `json:"body"`
	Name    string         `json:"name"`
	Assets  []GithubAsset  `json:"assets"`
}

GithubRelease represents a 'release' for a Github project

func LatestGithubRelease

func LatestGithubRelease(owner string, repo string) (*GithubRelease, error)

LatestGithubRelease returns some fields from the latest Github Release object for the given owner and repo via "https://api.github.com/repos/:owner/:repo/releases/latest"

type MinimalDevice

type MinimalDevice struct {
	ID       string        `json:"id"`
	AssetTag string        `json:"asset_tag"`
	Created  pgtime.PgTime `json:"created"`
	LastSeen pgtime.PgTime `json:"last_seen"`
	Health   string        `json:"health"`
	Flags    string        `json:"flags"`
	AZ       string        `json:"az"`
	Rack     string        `json:"rack"`
}

MinimalDevice represents a limited subset of Device data, that which we are going to present to the user

Jump to

Keyboard shortcuts

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