utils

package
v0.0.0-...-0e9b45f Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: Apache-2.0 Imports: 20 Imported by: 2

Documentation

Overview

qualifiedname.go

qualifiedname.go

Index

Constants

View Source
const (
	MANAGED         = "whisk-managed"
	OPENWHISK       = "OpenWhisk"
	NULL            = "golang\000"
	OW_PROJECT_NAME = "projectName"
	OW_PROJECT_HASH = "projectHash"
	OW_PROJECT_DEPS = "projectDeps"
	OW_File         = "file"
)
View Source
const (
	DEFAULT_HTTP_TIMEOUT = 60
	DEFAULT_PROJECT_PATH = "."
	HTTP_FILE_EXTENSION  = "http"
	// name of manifest and deployment files
	ManifestFileNameYaml   = "manifest.yaml"
	ManifestFileNameYml    = "manifest.yml"
	DeploymentFileNameYaml = "deployment.yaml"
	DeploymentFileNameYml  = "deployment.yml"
)
View Source
const ONE_DIR_UP = "../"
View Source
const PATH_WILDCARD = "*"

Variables

View Source
var LocalLicenseRecords = map[string][]string{
	"APACHE": {"1.0", "1.1", "2.0"},
	"LGPL":   {"2.0", "2.1", "3.0"},
	"GPL":    {"1.0", "2.0", "3.0"},
	"MPL":    {"1.0", "1.1", "2.0", "2.0-no-copyleft-exception"},
	"BSD":    {"2-Clause", "2-Clause-FreeBSD", "2-Clause-NetBSD", "3-Clause", "3-Clause-Clear", "3-Clause-No-Nuclear-License", "3-Clause-No-Nuclear-License-2014", "3-Clause-No-Nuclear-Warranty", "3-Clause-Attribution", "4-Clause", "Protection", "Source-Code", "4-Clause-UC", "3-Clause-LBNL"},
	"0BSD":   {""},
	"GFDL":   {"1.0", "1.2", "1.3"},
	"AGPL":   {"3.0"},
	"MIT":    {"", "feh", "enna", "advertising", "CMU"},
	"AFL":    {"1.1", "1.2", "2.0", "2.1", "3.0"},
	"APSL":   {"1.0", "1.1", "1.2", "2.0"},
	"EPL":    {"1.0"},
	"OSL":    {"1.0", "1.1", "2.0", "2.1", "3.0"},
	"PHP":    {"3.0", "3.01"},
}
View Source
var RemoteLicenseURL = "https://raw.githubusercontent.com/spdx/license-list-data/master/json/licenses.json"

Functions

func AddDependentAnnotation

func AddDependentAnnotation(existingAnnotation map[string]interface{}, dependencyAnnotations whisk.KeyValueArr) (whisk.KeyValue, error)

func CheckLicense

func CheckLicense(license string) bool

Check if the license is valid Check local data record at first Then check remote json data

func ConvertInterfaceMap

func ConvertInterfaceMap(mapIn map[interface{}]interface{}) map[string]interface{}

func ConvertInterfaceValue

func ConvertInterfaceValue(value interface{}) interface{}

func ConvertMapToJSONString

func ConvertMapToJSONString(name string, mapIn interface{}) string

TODO() add a Print function to wskprint that calls this and adds the label

func FileExists

func FileExists(file string) bool

func FormatStructAsJsonString

func FormatStructAsJsonString(a interface{}) string

func GenerateManagedAnnotation

func GenerateManagedAnnotation(projectName string, filePath string) (whisk.KeyValue, error)

func GetActionFromActionRecords

func GetActionFromActionRecords(records []ActionRecord, packageName string, actionName string) *whisk.Action

func GetDeploymentFilePath

func GetDeploymentFilePath(projectPath string) string

func GetHomeDirectory

func GetHomeDirectory() string

func GetJSONFromStrings

func GetJSONFromStrings(content []string, keyValueFormat bool) (interface{}, error)

TODO make generic and put into a separate JSON utils source file

func GetManifestFilePath

func GetManifestFilePath(projectPath string) string

func IsDirectory

func IsDirectory(filePath string) bool

func IsFeedAction

func IsFeedAction(trigger *whisk.Trigger) (string, bool)

func LicenseLocalValidation

func LicenseLocalValidation(license string) bool

Check if the license is in local license record If it is, return ture If it is not, return false

func LicenseRemoteValidation

func LicenseRemoteValidation(license string) bool

Check if license is one of validate license in https://github.com/spdx/license-list-data/blob/master/json/licenses.json If it is, return ture If it is not, return false

func LimitsLogsizeValidation

func LimitsLogsizeValidation(logsize *int) bool

if valid or nil, true or else, false

func LimitsMemoryValidation

func LimitsMemoryValidation(memory *int) bool

if valid or nil, true or else, false

func LimitsTimeoutValidation

func LimitsTimeoutValidation(timeout *int) bool

if valid or nil, true or else, false

func MayExists

func MayExists(file string) bool

func NotSupportLimits

func NotSupportLimits(value *int, name string)

func PrettyJSON

func PrettyJSON(rawData interface{}) (string, error)

func Read

func Read(url string) ([]byte, error)

func ReadProps

func ReadProps(path string) (map[string]string, error)

func WriteFile

func WriteFile(filename string, content string) error

func WriteProps

func WriteProps(path string, props map[string]string) error

Types

type ActionRecord

type ActionRecord struct {
	Action      *whisk.Action
	Packagename string
	Filepath    string
}

ActionRecord is a container to keep track of a whisk action struct and a location filepath we use to map files and manifest declared actions

type Comparable

type Comparable interface {
	HashCode() uint32
	Equals() bool
}

Potentially complex structures(such as DeploymentProject, DeploymentPackage) could implement those interface which is convenient for put, get subtract in containers etc.

type ContentReader

type ContentReader struct {
	URLReader
	LocalReader
}

agnostic util reader to fetch content from web or local path or potentially other places.

type Include

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

type LicenseItem

type LicenseItem struct {
	Name      string `json:"name"`
	LicenseID string `json:"licenseId"`
}

type LicenseJSON

type LicenseJSON struct {
	Description string        `json:"licenseListVersion"`
	Licenses    []LicenseItem `json:"licenses"`
	ReleaseDate string        `json:"releaseDate"`
}

type LocalReader

type LocalReader struct {
}

func (*LocalReader) ReadLocal

func (localReader *LocalReader) ReadLocal(path string) ([]byte, error)

type ManagedAnnotation

type ManagedAnnotation struct {
	ProjectName string            `json:"projectName"`
	ProjectHash string            `json:"projectHash"`
	File        string            `json:"file"`
	Deps        whisk.KeyValueArr `json:"projectDeps"`
}

type QualifiedName

type QualifiedName struct {
	Namespace   string
	PackageName string
	EntityName  string
}

func ParseQualifiedName

func ParseQualifiedName(name string, defaultNamespace string) (QualifiedName, error)

from go whisk cli

Parse a (possibly fully qualified) resource name into namespace and name components. If the given qualified name isNone, then this is a default qualified name and it is resolved from properties. If the namespace is missing from the qualified name, the namespace is also resolved from the property file.

Return a qualifiedName struct

Examples:

foo => qName {namespace: "_", entityName: foo}
pkg/foo => qName {namespace: "_", entityName: pkg/foo}
/ns/foo => qName {namespace: ns, entityName: foo}
/ns/pkg/foo => qName {namespace: ns, entityName: pkg/foo}

type RuleRecord

type RuleRecord struct {
	Rule        *whisk.Rule
	Packagename string
}

type TriggerRecord

type TriggerRecord struct {
	Trigger     *whisk.Trigger
	Packagename string
}

type URLReader

type URLReader struct {
}

func (*URLReader) ReadUrl

func (urlReader *URLReader) ReadUrl(url string) (content []byte, err error)

type WskDeployFlags

type WskDeployFlags struct {
	ApiHost          string // OpenWhisk API host
	Auth             string // OpenWhisk API key
	Namespace        string
	ApiVersion       string // OpenWhisk version
	CfgFile          string
	CliVersion       string
	CliGitCommit     string
	CliBuildDate     string
	ProjectPath      string
	DeploymentPath   string
	ManifestPath     string
	Preview          bool
	Strict           bool // strict flag to support user defined runtime version.
	Key              string
	Cert             string
	Managed          bool   // OpenWhisk Managed Deployments
	ProjectName      string // Project name
	ApigwAccessToken string
	//ApigwTenantId    string // APIGW_TENANT_ID (IAM namespace resource identifier); not avail. as CLI flag yet
	Verbose   bool
	Trace     bool
	Sync      bool
	Report    bool
	Param     []string
	ParamFile string
}
var Flags WskDeployFlags

func (*WskDeployFlags) Format

func (flags *WskDeployFlags) Format() string

TODO turn this into a generic utility for formatting any struct

type ZipWriter

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

func NewZipWriter

func NewZipWriter(src string, des string, include [][]string, exclude []string, manifestFilePath string) *ZipWriter

func (*ZipWriter) Zip

func (zw *ZipWriter) Zip() error

Jump to

Keyboard shortcuts

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