util

package
v1.12.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2019 License: MPL-2.0 Imports: 20 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

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 GhOrg = "joyent"
View Source
const GhRepo = "conch-shell"
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

	IgnoreConfig bool
	Token        string
	BaseURL      string

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

	ConfigPath string

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

	// API is a global Conch API object
	API *conch.Conch

	// Debug decides if we should put the API in debug mode
	// Yes, this is a bit of a kludge
	Debug bool

	// Trace decides if we should trace the HTTP transactions
	// Yes, this is a bit of a kludge
	Trace bool
)
View Source
var (
	Version    string
	GitRev     string
	SemVersion semver.Version

	FlagsDisableApiVersionCheck string // Used in shell development
	FlagsDisableApiTokenCRUD    string // Useful for preventing automations from creating and deleting tokens
	FlagsNoAdmin                string // Useful for preventing automations from accessing admin commands

)

These variables are provided by the build environment

View Source
var ErrNoGithubRelease = errors.New("no appropriate github release found")

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 CleanVersion added in v1.11.0

func CleanVersion(version string) semver.Version

CleanVersion removes a "v" prefix, and anything after a dash For example, pass in v2.99.10-abcde-dirty and get back a semver containing 2.29.10 Why? Git and Semver differ in their notions of what those extra bits mean. In Git, they mean "v2.99.10, plus some other stuff that happend". In semver, they indicate that this is a prerelease of v2.99.10. Obviously this screws up comparisions. This function lets us clean that stuff out so we can get a clean comparison

func DDP added in v1.11.0

func DDP(v interface{})

DDP pretty prints a structure to stderr. "Deep Data Printer"

func DisableApiTokenCRUD added in v1.12.0

func DisableApiTokenCRUD() bool

func DisableApiVersionCheck added in v1.11.0

func DisableApiVersionCheck() bool

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 GetMarkdownTable

func GetMarkdownTable() (table *tablewriter.Table)

GetMarkdownTable returns a tablewriter configured to output markdown compatible text

func GithubReleaseCheck added in v1.12.0

func GithubReleaseCheck()

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 MagicDatacenterID added in v1.11.0

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

MagicDatacenterID 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 GetDatacenters() 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(wat string) (uuid.UUID, error)

MagicRackID 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 GetRacks() looking for UUIDs that match up to the first hyphen.

func MagicRackLayoutSlotID added in v1.12.0

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

MagicRackLayoutSlotID 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 GetRackLayoutSlots�() looking for UUIDs that match up to the first hyphen.

func MagicRackRoleID added in v1.12.0

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

MagicRackRoleID 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 GetRackRoles() looking for UUIDs that match up to the first hyphen or where the role name matches the string

func MagicRoomID added in v1.12.0

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

MagicRoomID 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 GetRooms() looking for UUIDs that match up to the first hyphen.

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 MagicWorkspaceRackID added in v1.12.0

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

MagicWorkspaceRackID 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 NoAdmin added in v1.12.0

func NoAdmin() bool

func TimeStr

func TimeStr(t time.Time) string

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

func UserIsRoot added in v1.11.0

func UserIsRoot() bool

func WriteConfig added in v0.2.0

func WriteConfig()

WriteConfig serializes the Config struct to disk

func WriteConfigForce added in v1.12.0

func WriteConfigForce()

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"`
	PreRelease bool           `json:"prerelease"`
	Upgrade    bool           `json:"-"`
}

GithubRelease represents a 'release' for a Github project

func LatestGithubRelease

func LatestGithubRelease() (gh GithubRelease, err error)

LatestGithubRelease returns some fields from the latest Github Release that matches our major version

type GithubReleases added in v1.11.0

type GithubReleases []GithubRelease

func GithubReleasesSince added in v1.11.0

func GithubReleasesSince(start semver.Version) GithubReleases

func (GithubReleases) Len added in v1.11.0

func (g GithubReleases) Len() int

func (GithubReleases) Less added in v1.11.0

func (g GithubReleases) Less(i, j int) bool

func (GithubReleases) Swap added in v1.11.0

func (g GithubReleases) Swap(i, j int)

Notes

Bugs

  • for back compat AZ and Rack were not ported over since they are always zero-value without fullOutput

Jump to

Keyboard shortcuts

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