common

package
v0.0.0-...-187e736 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

* Copyright (C) 2011-2020 Red Hat, Inc. * * 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 (
	ContentTypePlain = "text/plain"
	ContentTypeHTML  = "text/html"

	ContentTypeJSON = "application/json"
	ContentTypeXML  = "application/xml"

	ContentTypeZip    = "application/zip"
	ContentTypeStream = "application/octet-stream"
	CottentTypeJar    = "application/java-archive"
)

ContentType for RFC http content type (parts)

View Source
const (
	StatusOK        = http.StatusOK
	StatusCreated   = http.StatusCreated
	StatusAccepted  = http.StatusAccepted
	StatusNoContent = http.StatusNoContent

	StatusMultipleChoices  = http.StatusMultipleChoices
	StatusMovedPermanently = http.StatusMovedPermanently
	StatusFound            = http.StatusFound
	StatusSeeOther         = http.StatusSeeOther
	StatusNotModified      = http.StatusNotModified
	StatusUseProxy         = http.StatusUseProxy

	StatusBadRequest        = http.StatusBadRequest
	StatusUnauthorized      = http.StatusUnauthorized
	StatusForbidden         = http.StatusForbidden
	StatusNotFound          = http.StatusNotFound
	StatusMethodNotAllowed  = http.StatusMethodNotAllowed
	StatusNotAcceptable     = http.StatusNotAcceptable
	StatusProxyAuthRequired = http.StatusProxyAuthRequired
	StatusRequestTimeout    = http.StatusRequestTimeout
	StatusConflict          = http.StatusConflict

	StatusInternalServerError = http.StatusInternalServerError
	StatusNotImplemented      = http.StatusNotImplemented
	StatusBadGateway          = http.StatusBadGateway
	StatusServiceUnavailable  = http.StatusServiceUnavailable
	StatusGatewayTimeout      = http.StatusGatewayTimeout

	StatusUnknown = -1
)

Status code for RFC http response status code (parts)

View Source
const (
	MethodGet     = http.MethodGet
	MethodHead    = http.MethodHead
	MethodPost    = http.MethodPost
	MethodPut     = http.MethodPut
	MethodPatch   = http.MethodPatch
	MethodDelete  = http.MethodDelete
	MethodOptions = http.MethodOptions
)

Methods for RFC http methods

View Source
const (
	KeycloakServer     = "KEYCLOAK_SERVER_URL"
	KeycloakRealm      = "KEYCLOAK_REALM"
	KeycloakResource   = "KEYCLOAK_CLIENT_ID"
	KeycloakCredential = "KEYCLOAK_CLIENT_CREDENTIAL"
)
View Source
const (
	BUILD_TEST_           = "build-test-"
	ENVAR_TEST_MOUNT_PATH = "TEST_MOUNT_PATH"
	MAVEN_METADATA_XML    = "maven-metadata.xml"
	REDHAT_               = "redhat-"
)
View Source
const DATA_TIME = "2006-01-02 15:04:05"
View Source
const NotStoreFile = ""
View Source
const (
	TRACKING_SUFFIX = "+tracking"
)

Variables

This section is empty.

Functions

func AlterUploadPath

func AlterUploadPath(rawPath, storeKey, newReleaseNumber string) string

func ByteCountSI

func ByteCountSI(b int64) string

func ConcurrentRun

func ConcurrentRun(numWorkers int, artifacts map[string][]string, job func(md5, originalURL, targetURL string) bool) bool

func Contains

func Contains(s []string, str string) bool

func DefaultAuthenticator

func DefaultAuthenticator(request *http.Request) error

func DeleteFoloRecord

func DeleteFoloRecord(indyURL, foloRecordId string) bool

func DownloadFile

func DownloadFile(url, storeFileName string) (bool, int)

func DownloadFileByProxy

func DownloadFileByProxy(url, storeFileName, indyProxyUrl, user, pass string) bool

func DownloadRepo

func DownloadRepo(gitURL string) string

func DownloadUploadFileForCache

func DownloadUploadFileForCache(url, cacheFileName string) bool

func FileOrDirExists

func FileOrDirExists(name string) bool

func FileSize

func FileSize(fileLoc string) int64

func GenerateRandomBuildName

func GenerateRandomBuildName() string

generate a random 5 digit number for a build repo like "build-test-9xxxx"

func GetAlignLog

func GetAlignLog(pncBaseUrl, buildId string) string

func GetFileContentType

func GetFileContentType(out *os.File) (string, error)

func GetFoloRecordAsString

func GetFoloRecordAsString(indyURL, foloRecordId string) string

func GetHost

func GetHost(URLString string) string

GetHost gets the hostname from a url string

func GetIndyContentUrl

func GetIndyContentUrl(indyBaseUrl, packageType, repoType, repoName, aPath string) string

func GetPort

func GetPort(URLString string) string

GetPort gets the port from a url string

func GetRespAsJSONType

func GetRespAsJSONType(url string, jsonType interface{}) error

func GetRespAsPlaintext

func GetRespAsPlaintext(url string) (string, error)

func HTTPRequest

func HTTPRequest(url, method string, auth Authenticate, needResult bool, dataPayload io.Reader, headers map[string]string, filename string, verbose bool) (string, int, bool)

HTTPRequest do raw http request with method, input data and headers. If url is trying to access bin content(like file), can use filename parameter to specify where to store this file as. Parameters: request url; request method; authentication method; if need response content; data payload to send(POST or PUT); headers to send; the file location to store if response is a binary download; if print verbose log message for debugging Returns: content as string, response status code as int, if succeeded as bool

func HttpExists

func HttpExists(url string) bool

func IsEmptyString

func IsEmptyString(str string) bool

IsEmptyString Check if string is empty

func IsMetadata

func IsMetadata(path, storeKey string) bool

func IsRegularFile

func IsRegularFile(fileLoc string) bool

func KeycloakAuthenticator

func KeycloakAuthenticator(request *http.Request) error

func Md5Check

func Md5Check(fileLoc, md5str string) bool

func RePanic

func RePanic(e error)

func ReadByteFromFile

func ReadByteFromFile(fileLoc string) []byte

func SealFoloRecord

func SealFoloRecord(indyURL, foloRecordId string) bool

func StoreKeyToPath

func StoreKeyToPath(storeKey string) string

func UploadFile

func UploadFile(uploadUrl, cacheFile string) bool

func ValidateTargetIndy

func ValidateTargetIndy(targetIndy string) (string, bool)

func ValidateTargetIndyOrExit

func ValidateTargetIndyOrExit(targetIndy string) (string, bool)

Types

type AccessToken

type AccessToken struct {
	Token            string `json:"access_token"`
	ExpiresIn        int64  `json:"expires_in"`
	RefreshExpiresIn int64  `json:"refresh_expires_in,omitempty"`
	TokenType        string `json:"token_type"`
	NotBeforePolicy  int    `json:"not-before-policy,omitempty"`
	Scope            string `json:"scope,omitempty"`
}

type Authenticate

type Authenticate func(request *http.Request) error

func DecideAuthenticator

func DecideAuthenticator() Authenticate

type HTTPError

type HTTPError struct {
	Message    string
	StatusCode int
}

HTTPError represents a generic http problem

func (HTTPError) Error

func (err HTTPError) Error() string

type MultiError

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

func (*MultiError) Append

func (e *MultiError) Append(err string)

func (*MultiError) Error

func (e *MultiError) Error() string

type ProxyConfig

type ProxyConfig struct {
	ProxyUrl, User, Pass string
}

type TrackedContent

type TrackedContent struct {
	Uploads     []TrackedContentEntry `json:"uploads"`
	Downloads   []TrackedContentEntry `json:"downloads"`
	TrackingKey TrackingKey           `json:"key"`
}

func GetFoloRecord

func GetFoloRecord(indyURL, foloRecordId string) TrackedContent

func GetFoloRecordFromFile

func GetFoloRecordFromFile(fileLoc string) TrackedContent

type TrackedContentEntry

type TrackedContentEntry struct {
	AccessChannel string  `json:"accessChannel"`
	Path          string  `json:"path"`
	OriginUrl     string  `json:"originUrl"`
	LocalUrl      string  `json:"localUrl"`
	Effect        string  `json:"effect"`
	Md5           string  `json:"md5"`
	Sha256        string  `json:"sha256"`
	Sha1          string  `json:"sha1"`
	Size          int64   `json:"size"`
	Timestamps    []int64 `json:"timestamps"`
	StoreKey      string  `json:"storeKey"`
}

type TrackingKey

type TrackingKey struct {
	Id string `json:"id"`
}

Jump to

Keyboard shortcuts

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