utils

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2017 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Copyright 2017 Mirantis

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(socket string, timeout time.Duration) (net.Conn, error)

func GenIsoImage

func GenIsoImage(isoPath string, volumeId string, srcDir string) error

GenIsoImage generates an ISO 9660 filesystem image containing files from srcDir. It uses specified volumeId as the volume id.

func GetBoolFromString added in v0.9.0

func GetBoolFromString(str string) bool

GetBoolFromString returns false if str is an empty string or is equal to one of: "0", "f" or "false". Case doesnt't matter anythging else is true

func GetK8sClientConfig added in v0.9.0

func GetK8sClientConfig(host string) (*rest.Config, error)

GetK8sClientConfig returns config that is needed to access k8s

func GetK8sClientset added in v0.9.0

func GetK8sClientset(config *rest.Config) (*kubernetes.Clientset, error)

GetK8sClientset returns clientset for standard k8s APIs

func GetK8sRestClient added in v0.9.0

func GetK8sRestClient(cfg *rest.Config, scheme *runtime.Scheme, groupVersion *schema.GroupVersion) (*rest.RESTClient, error)

GetK8sRestClient returns k8s ReST client that for the giver API group-version/subset

func MapToJson

func MapToJson(m map[string]interface{}) string

MapToJson converts the specified map object to indented JSON. It panics in case if the map connot be converted.

func MapToJsonUnindented

func MapToJsonUnindented(m map[string]interface{}) string

MapToJson converts the specified map object to unindented JSON. It panics in case if the map connot be converted.

func Merge added in v0.9.0

func Merge(base, override interface{}) interface{}

Merge will take two data sets and merge them together - returning a new data set

func NewFakeDownloader

func NewFakeDownloader(baseDir string) *fakeDownloader

NewFakeDownloader returns a fake downloader that places fake downloaded files under the specified dir. The fake downloader writes the location passed to it into the file instead of actually downloading it.

func NewUuid

func NewUuid() string

func NewUuid5

func NewUuid5(nsUuid, s string) string

func ReadJson

func ReadJson(filename string, v interface{}) error

func Tempfile

func Tempfile() (string, error)

func WaitForProcess added in v0.9.0

func WaitForProcess(procFile string) (int, error)

WaitForProcess waits for the following conditions to be true at the same time:

  • the specified procFile is readable and contains two numeric values separated by space, PID and start time in jiffies (field 22 in /proc/PID/stat, starting from 1)
  • the process with the PID read from procFile exists and has start time equal to the start time read from procFile

This avoids possible problems with stale procFile that could happen if only PID was stored there. The command can be used in shell script to generate the "procfile" for the current shell: /bin/sh -c 'echo "$$ `cut -d" " -f22 /proc/$$/stat`"'

func WaitLoop

func WaitLoop(test func() (bool, error), retryPeriod time.Duration, timeout time.Duration, clock clockwork.Clock) error

WaitLoop executes test func in loop until it returns error, true, or the timeout elapses. clock argument denotes a clock object to use for waiting. When clock is nil, WaitLoop uses clockwork.NewRealClock()

func WriteFiles

func WriteFiles(targetDir string, content map[string][]byte) error

WriteFiles writes the files specified as a map under `targetDir`. The keys of the map are subpaths and values are file contents. WriteFiles automatically creates any non-existing directories mentioned in subpaths.

func WriteJson

func WriteJson(filename string, v interface{}, perm os.FileMode) error

Types

type Downloader

type Downloader interface {
	// DownloadFile downloads the specified file and returns path to it
	DownloadFile(endpoint Endpoint) (string, error)
}

Downloader is an interface for downloading files from web

func NewDownloader

func NewDownloader(protocol string) Downloader

NewDownloader returns the default downloader for 'protocol'. The default downloader downloads a file via an URL constructed as 'protocol://location' and saves it in temporary file in default system directory for temporary files

type Endpoint added in v0.9.0

type Endpoint struct {
	// Url is the image URL
	Url string

	// MaxRedirects is the maximum number of redirects that downloader is allowed to follow. -1 for stdlib default (fails on request #10)
	MaxRedirects int

	// TLS is the TLS config
	TLS *TLSConfig

	// Timeout specifies a time limit for http(s) download request. <= 0 is no timeout (default)
	Timeout time.Duration

	// Proxy is the proxy server to use. Default = use proxy from HTTP_PROXY environment variable
	Proxy string

	// Transport profile name for this endpoint. Provided for logging/debugging
	ProfileName string
}

Endpoint contains all the endpoint parameters needed to download a file

type TLSCertificate added in v0.9.0

type TLSCertificate struct {
	// Certificate is the x509 certificate
	Certificate *x509.Certificate

	// PrivateKey is the private key needed for certificate-based client authentication
	PrivateKey crypto.PrivateKey
}

TLSCertificate is a x509 certificate with optional private key

type TLSConfig added in v0.9.0

type TLSConfig struct {
	// Certificates to use (both CA and for client authentication)
	Certificates []TLSCertificate

	// ServerName is needed when connecting to domain other that certificate was issued for
	ServerName string

	// Insecure skips certificate verification
	Insecure bool
}

TLSConfig has the TLS transport parameters

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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