libpvr

package
v0.0.0-...-5d366ab Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 67 Imported by: 2

Documentation

Overview

Copyright 2022 Pantacor Ltd.

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

View Source
const (
	SRC_FILE                    = "src.json"
	SRC_SPEC                    = "service-manifest-src@1"
	TEMPLATE_BUILTIN_LXC_DOCKER = "builtin-lxc-docker"
)
View Source
const (
	MKDIR_CMD                      = "mkdir"
	RM_CMD                         = "rm"
	TAR_CMD                        = "tar"
	TOUCH_CMD                      = "touch"
	MAKE_SQUASHFS_CMD              = "mksquashfs"
	SQUASH_FILE                    = "root.squashfs"
	SQUASH_OVL_FILE                = "root.ovl.squashfs"
	DOCKER_DIGEST_SUFFIX           = ".docker-digest"
	ROOTFS_DIGEST_SUFFIX           = ".rootfs-digest"
	DOCKER_DOMAIN                  = "docker.io"
	DOCKER_DOMAIN_URL              = "https://" + DOCKER_DOMAIN
	DOCKER_REGISTRY                = "https://index.docker.io/v1/"
	DOCKER_REGISTRY_SERVER_ADDRESS = "https://registry-1.docker.io"
)
View Source
const (
	// PhTrailsEp constant defining pantahub /trails
	PhTrailsEp = "/trails"

	// PhTrailsSummaryEp constant defines pantahub /trails/summary EP
	PhTrailsSummaryEp = PhTrailsEp + "/summary"

	// PhAccountsEp constant defines pantahub /accounts endpoint
	PhAccountsEp = "/auth/accounts"

	// PhLogsEp constant defining pantahub /logs/
	PhLogsEp = "/logs/"

	// PhLogsEpCursor constant defines path to /logs/cursor
	PhLogsEpCursor = PhLogsEp + "cursor"
)
View Source
const (
	SigKeyFilename    = "key.default.pem"
	SigX5cFilename    = "x5c.default.pem"
	SigCacertFilename = "cacerts.default.pem"
)
View Source
const (
	ConfigurationFile = "config.json"
)
View Source
const (
	DmVolumes = "_dm"
)
View Source
const (
	PoolSize = 5
)
View Source
const (
	PvrCheckpointFilename = "checkpoint.json"
)

Variables

View Source
var (
	ErrInvalidVolumeFormat = errors.New("invalid volume format")
	ErrEmptyAppName        = errors.New("empty app name")
	ErrEmptyFrom           = errors.New("empty from")
	ErrEmptyPart           = errors.New("empty part on the pvr url PVR_URL#part")
	ErrNeedBeRoot          = errors.New("please run this command as root or use fakeroot utility")
)
View Source
var (
	ErrMakeSquashFSNotFound    = errors.New("mksquashfs not found in your PATH, please install before continue")
	ErrTarNotFound             = errors.New("tar not found in your PATH, please install before continue")
	ErrImageNotFound           = errors.New("image not found or you do not have access")
	ErrDownloadedLayerDiffSize = errors.New("size of downloaded layer is different from expected")
)
View Source
var IsDebugEnabled bool

Variable set in main() to enable/disable debug

View Source
var (
	RuntimeDefaultMetadata = map[string]interface{}{
		"PVR_BASEURL":      "https://api.pantahub.com",
		"PVR_REPO_BASEURL": "https://pvr.pantahub.com",
		"PVR_AUTH":         "",
	}
)

Functions

func AddDockerApp

func AddDockerApp(p *Pvr, app *AppData) error

func AddFragsToState

func AddFragsToState(srcState, patchState map[string]interface{}, frags string) map[string]interface{}

func AddPvApp

func AddPvApp(p *Pvr, app *AppData) error

func AddRootFsApp

func AddRootFsApp(p *Pvr, app *AppData) error

func AskForConfirmation

func AskForConfirmation(question string) bool

AskForConfirmation ask the user for confirmation action

func CleanPatchSignedPkg

func CleanPatchSignedPkg(src, patch, target *PvrMap) error

func CleanRemovedSignatures

func CleanRemovedSignatures(initialState, finalState *PvrMap) error

func Copy

func Copy(dst, src string) error

func Create

func Create(path string) error

func CreateFolder

func CreateFolder(path string) error

func CreateTrail

func CreateTrail(baseURL string,
	deviceAccessToken string,
	state map[string]interface{},
) (
	*resty.Response,
	error,
)

CreateTrail : Create Trail

func DownloadFile

func DownloadFile(uri *url.URL) (string, error)

func DownloadLayersFromLocalDocker

func DownloadLayersFromLocalDocker(digest string) (io.ReadCloser, error)

DownloadLayersFromLocalDocker : Download Layers From Local Docker

func DownloadSigningCert

func DownloadSigningCert(url, path string) error

func DownloadSigningCertWithConfirmation

func DownloadSigningCertWithConfirmation(url, path string) error

DownloadSigningCertWithConfirmation ask for confirmation to download signing certs

func ExpandPath

func ExpandPath(path string) (string, error)

func ExtractFiles

func ExtractFiles(files []string, extractPath string) error

func FileHasSameSha

func FileHasSameSha(path, sha string) (bool, error)

func FiletoSha

func FiletoSha(path string) (string, error)

func FilterByFrags

func FilterByFrags(state map[string]interface{}, frags string) (map[string]interface{}, error)

func FindWhiteoutsFromLayer

func FindWhiteoutsFromLayer(layerPath string) ([]string, error)

FindWhiteoutsFromLayer : Find Whiteout Files From a Layer

func FixupRepoRef

func FixupRepoRef(repoUri string) (string, error)

func FormatJson

func FormatJson(data []byte) ([]byte, error)

func FormatJsonC

func FormatJsonC(data []byte) ([]byte, error)

func GetDockerConfigFile

func GetDockerConfigFile(p *Pvr, app *AppData) (map[string]interface{}, error)

func GetFileContentType

func GetFileContentType(src string) (string, error)

GetFileContentType : Get File Content Type of a file

func GetFromConfigPvs

func GetFromConfigPvs(url, configPath, name string) (string, error)

func GetFromRootFs

func GetFromRootFs(app *AppData) (string, error)

func GetPersistence

func GetPersistence(app *AppData) (map[string]string, error)

func GetPhAuthHeaderTokenKey

func GetPhAuthHeaderTokenKey(authHeader string) (string, error)

func GetPlatform

func GetPlatform() string

GetPlatform get string with the full platform name

func GetStatePatch

func GetStatePatch(initialState, endState []byte) (*[]byte, error)
func Hardlink(dst, src string) error

func InstallDockerApp

func InstallDockerApp(p *Pvr, app *AppData, appManifest *Source) error

func InstallPVApp

func InstallPVApp(p *Pvr, app *AppData, appManifest *Source) error

func InstallRootFsApp

func InstallRootFsApp(p *Pvr, app *AppData, appManifest *Source) error

func IsFileExists

func IsFileExists(filePath string) (bool, error)

IsFileExists : Check if File Exists or not

func IsSha

func IsSha(sha string) bool

func IsValidUrl

func IsValidUrl(value string) bool

IsValidUrl tests a string to determine if it is a well-structured url or not.

func LoadLocalImage

func LoadLocalImage(app *AppData) error

LoadLocalImage : To check whether Image Exist In Local Docker Or Not

func LoginDevice

func LoginDevice(
	baseURL string,
	prn string,
	secret string,
) (
	string,
	error,
)

LoginDevice : Login Device

func MakeSquash

func MakeSquash(rootfsPath string, app *AppData) error

func Max

func Max(x, y int) int

func MergePatch

func MergePatch(srcData, target []byte) ([]byte, error)

func Min

func Min(x, y int) int

func Mkdir

func Mkdir(path string, perm os.FileMode) error

func MkdirAll

func MkdirAll(path string, perm os.FileMode) error

func OverwriteState

func OverwriteState(state PvrMap, newState PvrMap)

func ParseRFC3339

func ParseRFC3339(date string) (time.Time, error)

ParseRFC3339 : Parse RFC3339 string : 2006-01-02T15:04:05+07:00

func PatchState

func PatchState(srcBuff, patchBuff []byte, srcFrags, patchFrag string, merge bool, state *PvrMap) ([]byte, map[string]interface{}, error)

PatchState update a json with a patch

func PrintDebugf

func PrintDebugf(format string, a ...interface{}) (n int, err error)

PrintDebugf forwards to Printfs if IsDebugEnabled

func PrintDebugln

func PrintDebugln(a ...interface{}) (n int, err error)

PrintDebugln forwards to Printfs if IsDebugEnabled

func ProcessWhiteouts

func ProcessWhiteouts(extractPath string, layerPath string, layerNumber int) error

ProcessWhiteouts : FInd Whiteouts from a layer and process it in a given extract path

func ReadArgsFile

func ReadArgsFile(filePath string) (map[string]interface{}, error)

func ReadOrCreateFile

func ReadOrCreateFile(filePath string) (*[]byte, error)

ReadOrCreateFile read a file from file system if is not avaible creates the file

func Remove

func Remove(path string) error

Remove remove a path, a file

func RemoveAll

func RemoveAll(path string) error

RemoveAll remove a path, could be a file or a folder

func RemoveDirContents

func RemoveDirContents(dir string) error

func RenameFile

func RenameFile(src string, dst string) (err error)

func ReportDockerManifestError

func ReportDockerManifestError(err error, image string) error

func ReportError

func ReportError(err error, knowSolutions ...string) error

func Scan

func Scan()

func SetTempFilesInterrupHandler

func SetTempFilesInterrupHandler(tempdir string)

SetTempFilesInterrupHandler : Set Temp Files Interrup Handler

This function will capture Interrupt signals and delete all temp files

func ShowOrOpenRegisterLink(baseAPIURL, email, username, password string) error

ShowOrOpenRegisterLink show or open the user the registration link

func SliceContainsItem

func SliceContainsItem(slice []string, item string) bool

SliceContainsItem : checks if an item exists in a string array or not

func SortObjects

func SortObjects(objects map[string]string) []string

func SprintTmpl

func SprintTmpl(format string, obj interface{}) (string, error)

func StructToMap

func StructToMap(s interface{}) (map[string]interface{}, error)

func Untar

func Untar(dst string, src string, options []string) error

Untar : Untar a file or folder

func UpdateDockerApp

func UpdateDockerApp(p *Pvr, app *AppData, appManifest *Source) (err error)

func UpdateIfNecessary

func UpdateIfNecessary(c *cli.Context) error

UpdateIfNecessary update pvr if is necesary but only check on time at the day

func UpdatePvApp

func UpdatePvApp(p *Pvr, app *AppData, appManifest *Source) error

func UpdateRootFSApp

func UpdateRootFSApp(p *Pvr, app *AppData, appManifest *Source) error

func ValidateSourceFlag

func ValidateSourceFlag(source string) error

ValidateSourceFlag : Validate Source Flag

func WriteConfiguration

func WriteConfiguration(filePath string, config *PvrGlobalConfig) error

WriteConfiguration write ~/.pvr/config.json with new data

func WriteTxtFile

func WriteTxtFile(filePath string, content string) error

Types

type Account

type Account struct {
	Email    string `json:"email" bson:"email"`
	Nick     string `json:"nick" bson:"nick"`
	Password string `json:"password,omitempty" bson:"password"`
}

Account data model

type ApiError

type ApiError struct {
	Cod   int    `json:"cod"`
	Error string `json:"error"`
	Msg   string `json:"msg"`
}

func LogPrettyJSON

func LogPrettyJSON(content []byte) (ApiError, error)

LogPrettyJSON : Pretty print Json content

type AppData

type AppData struct {
	SquashFile      string
	Appname         string
	DockerURL       string
	Username        string
	Password        string
	Appmanifest     *Source
	TemplateArgs    map[string]interface{}
	Config          map[string]interface{}
	DestinationPath string
	LocalImage      DockerImage
	RemoteImage     DockerImage
	From            string
	Source          string
	Platform        string
	ConfigFile      string
	Volumes         []string
	FormatOptions   string
	SourceType      string
	DoOverlay       bool
	Base            string
	ManifestType    string
}

AppData : To hold all required App Information

type AsyncBody

type AsyncBody struct {
	Delegate io.ReadCloser
	// contains filtered or unexported fields
}

func (*AsyncBody) Read

func (a *AsyncBody) Read(p []byte) (n int, err error)

type DmSource

type DmSource struct {
	Source
	DmVolumes []string `json:"dm_volumes,omitempty"`
}

type DmVerityJson

type DmVerityJson struct {
	DataDevice string `json:"data_device"`
	HashDevice string `json:"hash_device"`
	RootHash   string `json:"root_hash"`
}

type DockerImage

type DockerImage struct {
	Exists         bool
	DockerDigest   string
	DockerConfig   map[string]interface{}
	DockerManifest *Manifest
	DockerRegistry *registry.Registry
	ImagePath      string
	DockerPlatform string
}

DockerImage : return type of ImageExistsInLocalDocker()

type DockerManifest

type DockerManifest map[string]interface{}

type DockerSource

type DockerSource struct {
	DockerName      string                 `json:"docker_name,omitempty"`
	DockerTag       string                 `json:"docker_tag,omitempty"`
	DockerDigest    string                 `json:"docker_digest,omitempty"`
	DockerOvlDigest string                 `json:"docker_ovl_digest,omitempty"`
	DockerSource    string                 `json:"docker_source,omitempty"`
	DockerConfig    map[string]interface{} `json:"docker_config,omitempty"`
	DockerPlatform  string                 `json:"docker_platform,omitempty"`
	FormatOptions   string                 `json:"format_options,omitempty"`
}

type EncryptedAccountData

type EncryptedAccountData struct {
	Token       string `json:"token"`
	RedirectURI string `json:"redirect-uri"`
}

EncryptedAccountData Encrypted account response

func GetEncryptedAccount

func GetEncryptedAccount(authEp, email, username, password string) (*EncryptedAccountData, error)

GetEncryptedAccount encrypt account data in order to open the browser to finish the registration process

type FilePut

type FilePut struct {
	// contains filtered or unexported fields
}

type JwsVerifySummary

type JwsVerifySummary struct {
	Protected       []string      `json:"protected,omitempty"`
	Excluded        []string      `json:"excluded,omitempty"`
	NotSeen         []string      `json:"notseen,omitempty"`
	FullJSONWebSigs []interface{} `json:"sigs,omitempty"`
}

type LogFilter

type LogFilter struct {
	Devices   string
	Sources   string
	Levels    string
	Platforms string
}

LogFilter : Log Filter

type LogFormatter

type LogFormatter interface {
	Init(template string) error
	DoLog(m *logs.Entry) error
}

type LogFormatterJson

type LogFormatterJson struct{}

func (*LogFormatterJson) DoLog

func (s *LogFormatterJson) DoLog(m *logs.Entry) error

func (*LogFormatterJson) Init

func (s *LogFormatterJson) Init(format string) error

type LogFormatterTemplate

type LogFormatterTemplate struct {
	// contains filtered or unexported fields
}

func (*LogFormatterTemplate) DoLog

func (s *LogFormatterTemplate) DoLog(v *logs.Entry) error

func (*LogFormatterTemplate) Init

func (s *LogFormatterTemplate) Init(template string) error

type Manifest

type Manifest struct {
	manifest.Versioned

	// Config references the image configuration as a blob.
	Config distribution.Descriptor `json:"config"`

	// Layers lists descriptors for the layers referenced by the
	// configuration.
	Layers []distribution.Descriptor `json:"layers"`

	// Annotations contains arbitrary metadata for the image manifest.
	Annotations map[string]string `json:"annotations,omitempty"`
}

func GetManifest

func GetManifest(dockerReg *registry.Registry, version, path, digest string) (manifest *Manifest, err error)

type Object

type Object struct {
	Id         string `json:"id" bson:"id"`
	StorageId  string `json:"storage-id" bson:"_id"`
	Owner      string `json:"owner"`
	ObjectName string `json:"objectname"`
	Sha        string `json:"sha256sum"`
	Size       string `json:"size"`
	MimeType   string `json:"mime-type"`
}

type ObjectWithAccess

type ObjectWithAccess struct {
	Object       `bson:",inline"`
	SignedPutUrl string `json:"signed-puturl"`
	SignedGetUrl string `json:"signed-geturl"`
	Now          string `json:"now"`
	ExpireTime   string `json:"expire-time"`
}

type PVZeroConf

type PVZeroConf struct {
	Hostname string
	AddrIPv4 []net.IP
	AddrIPv6 []net.IP
	Port     int

	Pantahub  string
	DeviceId  string
	Challenge string
}

func (PVZeroConf) ClaimCmd

func (p PVZeroConf) ClaimCmd() string

func (PVZeroConf) String

func (p PVZeroConf) String() string

type PantahubDevice

type PantahubDevice struct {
	Id               string    `json:"deviceid"`
	Prn              string    `json:"device"`
	Nick             string    `json:"device-nick"`
	Revision         int       `json:"revision"`
	ProgressRevision int       `json:"progress-revision"`
	RealIP           string    `json:"real-ip"`
	Timestamp        time.Time `json:"timestamp"`
	StateSha         string    `json:"state-sha"`
	Status           string    `json:"status"`
	StatusMsg        string    `json:"status-msg"`
}

type Pvr

type Pvr struct {
	Initialized     bool
	Dir             string
	Pvrdir          string
	Pvdir           string
	Objdir          string
	Pvrconfig       PvrConfig
	PristineJson    []byte
	PristineJsonMap PvrMap
	NewFiles        PvrIndex
	Session         *Session
}

func NewPvr

func NewPvr(s *Session, dir string) (*Pvr, error)

func NewPvrInit

func NewPvrInit(s *Session, dir string) (*Pvr, error)

func (*Pvr) AddApplication

func (p *Pvr) AddApplication(app *AppData, addonly bool) (err error)

AddApplication : Add application from several types of sources

func (*Pvr) AddFile

func (p *Pvr) AddFile(globs []string, forceObject bool) error

XXX: make this git style

func (*Pvr) AuthConfig

func (p *Pvr) AuthConfig(username, password, registry string) (types.AuthConfig, error)

func (*Pvr) CheckIfIsRunningAsRoot

func (p *Pvr) CheckIfIsRunningAsRoot() error

func (*Pvr) Cleanup

func (p *Pvr) Cleanup() error

func (*Pvr) Commit

func (p *Pvr) Commit(msg string, isCheckpoint bool) (err error)
func (p *Pvr) DeployPvLinks() error

DeployPvLinks sets up the hardlinks for the .pv/ files

func (*Pvr) Diff

func (p *Pvr) Diff() (*[]byte, error)

func (*Pvr) DmCVerityApply

func (p *Pvr) DmCVerityApply(prefix string) error

func (*Pvr) DmCVerityConvert

func (p *Pvr) DmCVerityConvert(container string, volume string) error

func (*Pvr) DmCryptApply

func (p *Pvr) DmCryptApply() error

func (*Pvr) DoClaim

func (p *Pvr) DoClaim(deviceEp, challenge string) error

func (*Pvr) Export

func (p *Pvr) Export(parts []string, dst string) error

Export will put the 'json' file first into the archive to allow for stream parsing and validation of json before processing objects

func (*Pvr) FindDockerImage

func (p *Pvr) FindDockerImage(app *AppData) (err error)

FindDockerImage : Find Docker Image

func (*Pvr) GenerateApplicationSquashFS

func (p *Pvr) GenerateApplicationSquashFS(app *AppData, appManifest *Source) error

func (*Pvr) GenerateApplicationTemplateFiles

func (p *Pvr) GenerateApplicationTemplateFiles(appname string, dockerConfig map[string]interface{}, appManifest *Source) error

func (*Pvr) GetAppDockerDigest

func (p *Pvr) GetAppDockerDigest(appname string) (string, error)

GetAppDockerDigest : Get App Docker Digest

func (*Pvr) GetAppDockerName

func (p *Pvr) GetAppDockerName(appname string) (string, error)

GetAppDockerName : Get App Docker Name

func (*Pvr) GetApplicationInfo

func (p *Pvr) GetApplicationInfo(appname string) error

GetApplicationInfo : Get Application Info

func (*Pvr) GetApplicationManifest

func (p *Pvr) GetApplicationManifest(appname string) (*Source, error)

func (*Pvr) GetApplications

func (p *Pvr) GetApplications() ([]AppData, error)

ListApplications : List Applications

func (*Pvr) GetCPristineJson

func (p *Pvr) GetCPristineJson() ([]byte, error)

func (*Pvr) GetDefaultGroup

func (p *Pvr) GetDefaultGroup() string

func (*Pvr) GetDockerConfig

func (p *Pvr) GetDockerConfig(manifest *Manifest, image registry.Image, auth types.AuthConfig) (map[string]interface{}, error)

func (*Pvr) GetDockerImageRepoDigest

func (p *Pvr) GetDockerImageRepoDigest(image registry.Image, auth types.AuthConfig) (string, error)

GetDockerImageRepoDigest : Get Docker Image Repo Digest

func (*Pvr) GetDockerManifest

func (p *Pvr) GetDockerManifest(image registry.Image, auth types.AuthConfig, digest, version string) (*Manifest, error)

func (*Pvr) GetDockerRegistry

func (p *Pvr) GetDockerRegistry(image registry.Image, auth types.AuthConfig) (*registry.Registry, error)

func (*Pvr) GetFromRepo

func (p *Pvr) GetFromRepo(app *AppData) (string, *Source, error)

func (*Pvr) GetGroup

func (p *Pvr) GetGroup(name string) (result string, err error)

func (*Pvr) GetJson

func (p *Pvr) GetJson(uri string) (
	state map[string]interface{},
	err error,
)

func (*Pvr) GetRepo

func (p *Pvr) GetRepo(uri string, merge bool, showFilenames bool, state *PvrMap) (
	objectsCount int,
	err error,
)

func (*Pvr) GetRepoLocal

func (p *Pvr) GetRepoLocal(getPath string, merge bool, showFilenames bool, state *PvrMap) (
	objectsCount int,
	err error)

func (*Pvr) GetRepoRemote

func (p *Pvr) GetRepoRemote(url *url.URL, merge bool, showFilenames bool, state *PvrMap) (
	objectsCount int,
	err error,
)

func (*Pvr) GetSquashFSDigest

func (p *Pvr) GetSquashFSDigest(squashFile, appName string) (string, error)

func (*Pvr) GetStateJson

func (p *Pvr) GetStateJson(uri string) (
	state map[string]interface{},
	err error,
)

func (*Pvr) GetTrackURL

func (p *Pvr) GetTrackURL(appname string) (string, error)

GetTrackURL : Get Track URL

func (*Pvr) GetWorkingGroupsJson

func (p *Pvr) GetWorkingGroupsJson() (result []interface{}, err error)

func (*Pvr) GetWorkingJson

func (p *Pvr) GetWorkingJson() ([]byte, []string, error)

create the canonical json for the working directory

func (*Pvr) GetWorkingJsonMap

func (p *Pvr) GetWorkingJsonMap() (resMap map[string]interface{}, untracked []string, err error)

func (*Pvr) HasGroup

func (p *Pvr) HasGroup(name string) bool

func (*Pvr) HasGroups

func (p *Pvr) HasGroups() bool

func (*Pvr) Import

func (p *Pvr) Import(src string) error

func (*Pvr) Init

func (p *Pvr) Init(objectsDir string) error

func (*Pvr) InitCustom

func (p *Pvr) InitCustom(customInitJson string, objectsDir string) error

func (*Pvr) InstallApplication

func (p *Pvr) InstallApplication(app *AppData) (err error)

InstallApplication : Install Application from any type of source

func (*Pvr) JSONDiff

func (p *Pvr) JSONDiff() (*[]byte, error)

func (*Pvr) JwsSign

func (p *Pvr) JwsSign(name string,
	privKeyPath string,
	match *PvsMatch,
	options *PvsOptions) error

JwsSign will add or update a signature based using a private key provided.

The payload will be assembled from the prinstine system state JSON using the match rule provided in PvsMatch struct.

PvsOptions allow to pass additional JoseHeader options to include in the Signature.

func (*Pvr) JwsSignAuto

func (p *Pvr) JwsSignAuto(keyPath string, part string, options *PvsOptions) error

func (*Pvr) JwsSignPvs

func (p *Pvr) JwsSignPvs(privKeyPath string,
	pvsPath string,
	options *PvsOptions) error

JwsSignPvs will parse a pvs@s json provided as argument and use the included PvsMatch section to invoke JwsSign

func (*Pvr) JwsVerifyPvs

func (p *Pvr) JwsVerifyPvs(keyPath string, caCerts string, pvsPath string, includePayload bool) (*JwsVerifySummary, error)

JwsVerify will add or update a signature based using a private key provided.

The payload will be assembled from the prinstine system state JSON using the match rule provided in PvsMatch struct included in the pvs.

special value for caCerts "_system_" hints at using the system cacert store. Can be configured using SSH_CERT_FILE and SSH_CERTS_DIR on linux

func (*Pvr) ListApplications

func (p *Pvr) ListApplications() error

ListApplications : List Applications

func (*Pvr) LoadRemoteImage

func (p *Pvr) LoadRemoteImage(app *AppData) error

LoadRemoteImage : To check whether Image Exist In Remote Docker Or Not

func (*Pvr) Post

func (p *Pvr) Post(uri string, envelope string, commitMsg string, rev string, force bool) error

make a json post to a REST endpoint. You can provide metainfo etc. in post argument as json. postKey if set will be used as key that refers to the posted json. Example usage: json blog post, json revision repo with commit message etc

func (*Pvr) Put

func (p *Pvr) Put(uri string, force bool) error

func (*Pvr) PutLocal

func (p *Pvr) PutLocal(repoPath string) error

func (*Pvr) PutObjects

func (p *Pvr) PutObjects(uri string, force bool) error

func (*Pvr) PutRemote

func (p *Pvr) PutRemote(repoPath *url.URL, force bool) error

func (*Pvr) RemoteCopy

func (p *Pvr) RemoteCopy(pvrSrc string, pvrDest string, merge bool,
	envelope string, commitMsg string, rev string, force bool) error

RemoteCopy will perform a remote only copy by taking the json, select elements that have the #fragement of a provided url as Prefix of their key and replace all elements in pvrDest that match that prefix. The target prefix can be overloaded through providing a #fragment in destination URL as well. It is an illegal input if pvrSrc has no fragement, but pvrDest has one. It is however legal input if pvrSrc has a fragement, but pvrDest does not have one. In that case the same fragement is implicitely appended to pvrDest

func (*Pvr) RemoteInfo

func (p *Pvr) RemoteInfo(pvrRef string) (*pvrapi.PvrRemote, error)

func (*Pvr) RemoveApplication

func (p *Pvr) RemoveApplication(appname string) error

RemoveApplication : Remove Application

func (*Pvr) Reset

func (p *Pvr) Reset(canonicalJson bool) error
func (p *Pvr) ResetWithHardlink() error

func (*Pvr) ResetWithState

func (p *Pvr) ResetWithState(state *PvrMap) error

func (*Pvr) RunAsRoot

func (p *Pvr) RunAsRoot() error

func (*Pvr) SaveConfig

func (p *Pvr) SaveConfig() error

func (*Pvr) SetConfiguration

func (pvr *Pvr) SetConfiguration(arguments []string) (*PvrGlobalConfig, error)

SetConfiguration read arguments and write new configuration, merging with the previous configuration on the file

func (*Pvr) SetSourceTypeFromManifest

func (p *Pvr) SetSourceTypeFromManifest(app *AppData, options *models.GetSTOptions) error

func (*Pvr) Status

func (p *Pvr) Status() (*PvrStatus, error)

func (*Pvr) String

func (p *Pvr) String() string

func (*Pvr) UnpackRepo

func (p *Pvr) UnpackRepo(repoPath, outDir string, options []string) error

func (*Pvr) UpdateApplication

func (p *Pvr) UpdateApplication(app AppData) error

UpdateApplication : Update any application and any type

func (*Pvr) UpdatePvr

func (pvr *Pvr) UpdatePvr(username, password string, silent, force bool) error

UpdatePvr Take the username, password and configuration File (aka: ~/.pvr) and update the pvr binary

func (*Pvr) Verify

func (p *Pvr) Verify(keyPath string) error

type PvrAuthConfig

type PvrAuthConfig struct {
	Spec   string                   `json:"spec"`
	Tokens map[string]PvrAuthTokens `json:"tokens"`
	// contains filtered or unexported fields
}

func LoadConfig

func LoadConfig(filePath string) (*PvrAuthConfig, error)

func (*PvrAuthConfig) DoRefresh

func (p *PvrAuthConfig) DoRefresh(authEp, token string) (string, string, error)

func (*PvrAuthConfig) Save

func (p *PvrAuthConfig) Save() error

type PvrAuthTarget

type PvrAuthTarget struct {
	// Name is the name of the target; 'default' for api.pantahub.com
	Name     string
	TargetEp *url.URL
}

type PvrAuthTokens

type PvrAuthTokens struct {
	Name string
	// Name is the name of the target; 'default' for api.pantahub.com
	AccessToken  string `json:"access-token"`
	RefreshToken string `json:"refresh-token"`
}

type PvrConfig

type PvrConfig struct {
	DefaultGetUrl  string
	DefaultPutUrl  string
	DefaultPostUrl string
	ObjectsDir     string

	// tokens by realm
	AccessTokens  map[string]string
	RefreshTokens map[string]string
}

type PvrFileAddInfo

type PvrFileAddInfo struct {
	Sha         string
	ForceObject bool
}

type PvrGlobalConfig

type PvrGlobalConfig struct {
	Spec            string `json:"Spec"`
	AutoUpgrade     bool   `json:"AutoUpgrade"`
	DistributionTag string `json:"DistributionTag"`
}

PvrGlobalConfig define all the posible general configuration for pvr

func LoadConfiguration

func LoadConfiguration(filePath string) (*PvrGlobalConfig, error)

LoadConfiguration read configuration from ~/.pvr/config.json or return default configuration

type PvrIndex

type PvrIndex map[string]PvrFileAddInfo

type PvrMap

type PvrMap map[string]interface{}

type PvrSource

type PvrSource struct {
	PvrUrl    string `json:"pvr,omitempty"`
	PvrDigest bool   `json:"pvr_digest,omitempty"`
}

type PvrStatus

type PvrStatus struct {
	NewFiles       []string
	RemovedFiles   []string
	ChangedFiles   []string
	UntrackedFiles []string
	JsonDiff       *[]byte
}

func (*PvrStatus) String

func (p *PvrStatus) String() string

stringify of file status for "pvr status" list...

type PvsCertPool

type PvsCertPool struct {
	// contains filtered or unexported fields
}

func NewPvsCertPool

func NewPvsCertPool() *PvsCertPool

func (*PvsCertPool) AppendCertsFromPEM

func (s *PvsCertPool) AppendCertsFromPEM(pemCerts []byte) (ok bool)

func (*PvsCertPool) GetCertsRaw

func (s *PvsCertPool) GetCertsRaw() [][]byte

type PvsMatch

type PvsMatch struct {
	Include []string `json:"include"`
	Exclude []string `json:"exclude"`
}

type PvsOptions

type PvsOptions struct {
	Algorithm      gojose.SignatureAlgorithm
	X5cPath        string
	ExtraHeaders   map[string]interface{}
	IncludePayLoad bool
	OutputFile     *os.File
}

type PvsPartSelection

type PvsPartSelection struct {
	Selected    map[string]interface{}
	NotSelected map[string]interface{}
	NotSeen     map[string]interface{}
}

type RootFsSource

type RootFsSource struct {
	RootFsURL    string `json:"rootfs_url,omitempty"`
	RootFsDigest string `json:"rootfs_digest,omitempty"`
}

type Session

type Session struct {
	Configuration *PvrGlobalConfig
	// contains filtered or unexported fields
}

func DefaultSession

func DefaultSession() *Session

func NewSession

func NewSession(app *cli.App) (*Session, error)

func (*Session) CreateDevice

func (s *Session) CreateDevice(baseURL string, deviceNick string) (
	*resty.Response,
	error,
)

CreateDevice : Create Device

func (*Session) DoAuthCall

func (s *Session) DoAuthCall(withAnon bool, fn WrappableRestyCallFunc) (*resty.Response, error)

func (*Session) DoLogs

func (p *Session) DoLogs(
	baseurl string,
	deviceIds []string,
	rev int,
	startTime *time.Time,
	endTime *time.Time,
	cursor bool,
	logFilter LogFilter,
) (logEntries []*logs.Entry, cursorID string, err error)

func (*Session) DoLogsCursor

func (p *Session) DoLogsCursor(baseurl string, cursor string) (logEntries []*logs.Entry, cursorID string, err error)

func (*Session) DoPs

func (p *Session) DoPs(baseurl string) ([]PantahubDevice, error)

func (*Session) GetApp

func (s *Session) GetApp() *cli.App

func (*Session) GetAuthStatus

func (s *Session) GetAuthStatus(baseURL string) (
	*resty.Response,
	error,
)

GetAuthStatus : Get Auth Status, GET /auth/auth_status

func (*Session) GetConfigDir

func (s *Session) GetConfigDir() string

func (*Session) GetDevice

func (s *Session) GetDevice(baseURL string,
	deviceNick string,
	ownerNick string,
) (
	*resty.Response,
	error,
)

GetDevice : Get Device

func (*Session) GetDevices

func (s *Session) GetDevices(baseURL string,
	ownerNick string,
	deviceNick string,
) (
	*resty.Response,
	error,
)

GetDevices : Get Devices

func (*Session) GetUserProfiles

func (s *Session) GetUserProfiles(baseURL string,
	userNick string,
) (
	*resty.Response,
	error,
)

GetUserProfiles : Get User Profiles

func (*Session) GetWhoami

func (s *Session) GetWhoami() (nick string, err error)

func (*Session) IsUserLoggedIn

func (session *Session) IsUserLoggedIn(baseURL string) (bool, error)

IsUserLoggedIn : To check if a user is logged in or not

func (*Session) Login

func (s *Session) Login(APIURL string, withAnon bool) (*resty.Response, error)

Login : Login to a given URL

func (*Session) SuggestDeviceNicks

func (s *Session) SuggestDeviceNicks(userNick, searchTerm string, baseURL string)

SuggestDeviceNicks : Suggest Device Nicks

func (*Session) SuggestNicks

func (s *Session) SuggestNicks(searchTerm string, baseURL string)

SuggestNicks : Suggest Nicks (Either user nicks or device nicks)

func (*Session) SuggestUserNicks

func (s *Session) SuggestUserNicks(searchTerm string, baseURL string)

SuggestUserNicks : Suggest User Nicks

func (*Session) UpdateDevice

func (s *Session) UpdateDevice(
	baseURL string,
	deviceNick string,
	data map[string]interface{},
	updateField string,
) (
	*resty.Response,
	error,
)

UpdateDevice : Update user-meta or device-meta field of a device

func (*Session) Whoami

func (s *Session) Whoami() (err error)

Whoami : List all loggedin nick names

type Source

type Source struct {
	Base         string                   `json:"base,omitempty"`
	Name         string                   `json:"name,omitempty"`
	Spec         string                   `json:"#spec"`
	Template     string                   `json:"template,omitempty"`
	TemplateArgs map[string]interface{}   `json:"args,omitempty"`
	DmEnabled    map[string]bool          `json:"dm_enabled,omitempty"`
	Logs         []map[string]interface{} `json:"logs,omitempty"`
	Exports      []string                 `json:"exports,omitempty"`
	Config       map[string]interface{}   `json:"config,omitempty"`
	DockerSource
	PvrSource
	RootFsSource
	Persistence map[string]string `json:"persistence,omitempty"`
}

type TreeDiff

type TreeDiff struct {
	A       string
	B       string
	Errors  []error
	InA     []string
	InB     []string
	OnlyInA []string
	OnlyInB []string
	Differ  []string
}

func MkTreeDiff

func MkTreeDiff(dir1, dir2 string) TreeDiff

func (*TreeDiff) MkOvl

func (tree *TreeDiff) MkOvl(ovlDir string)

func (*TreeDiff) String

func (tree *TreeDiff) String() string

type WrappableRestyCallFunc

type WrappableRestyCallFunc func(req *resty.Request) (*resty.Response, error)

Jump to

Keyboard shortcuts

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