http

package
v0.0.0-...-f6b2f6e Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 28 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// 15 minutes
	DefaultDownloadLinkExpire = 15 * time.Minute
	// 10 Mb
	DefaultMaxMetaSize         = 1024 * 1024 * 10
	DefaultMaxImageSize        = 10 * 1024 * 1024 * 1024 // 10GiB
	DefaultMaxGenerateDataSize = 512 * 1024 * 1024       // 512MiB

	// Pagination
	DefaultPerPage                      = 20
	MaximumPerPage                      = 500
	MaximumPerPageListDeviceDeployments = 20
)
View Source
const (
	// Common HTTP form parameters
	ParamArtifactName = "artifact_name"
	ParamDeviceType   = "device_type"
	ParamUpdateType   = "update_type"
	ParamDeploymentID = "deployment_id"
	ParamDeviceID     = "device_id"
	ParamTenantID     = "tenant_id"
	ParamName         = "name"
	ParamTag          = "tag"
	ParamDescription  = "description"
	ParamPage         = "page"
	ParamPerPage      = "per_page"
	ParamSort         = "sort"
	ParamID           = "id"
)

storage keys

View Source
const (
	HTTPHeaderAuthorization       = "Authorization"
	HTTPHeaderAuthorizationBearer = "Bearer"
)

JWT token

View Source
const (
	ApiUrlInternal   = "/api/internal/v1/deployments"
	ApiUrlManagement = "/api/management/v1/deployments"
	ApiUrlDevices    = "/api/devices/v1/deployments"

	ApiUrlManagementArtifacts               = ApiUrlManagement + "/artifacts"
	ApiUrlManagementArtifactsList           = ApiUrlManagement + "/artifacts/list"
	ApiUrlManagementArtifactsGenerate       = ApiUrlManagement + "/artifacts/generate"
	ApiUrlManagementArtifactsDirectUpload   = ApiUrlManagement + "/artifacts/directupload"
	ApiUrlManagementArtifactsCompleteUpload = ApiUrlManagementArtifactsDirectUpload +
		"/#id/complete"
	ApiUrlManagementArtifactsId         = ApiUrlManagement + "/artifacts/#id"
	ApiUrlManagementArtifactsIdDownload = ApiUrlManagement + "/artifacts/#id/download"

	ApiUrlManagementDeployments                   = ApiUrlManagement + "/deployments"
	ApiUrlManagementMultipleDeploymentsStatistics = ApiUrlManagement +
		"/deployments/statistics/list"
	ApiUrlManagementDeploymentsGroup       = ApiUrlManagement + "/deployments/group/#name"
	ApiUrlManagementDeploymentsId          = ApiUrlManagement + "/deployments/#id"
	ApiUrlManagementDeploymentsStatistics  = ApiUrlManagement + "/deployments/#id/statistics"
	ApiUrlManagementDeploymentsStatus      = ApiUrlManagement + "/deployments/#id/status"
	ApiUrlManagementDeploymentsDevices     = ApiUrlManagement + "/deployments/#id/devices"
	ApiUrlManagementDeploymentsDevicesList = ApiUrlManagement + "/deployments/#id/devices/list"
	ApiUrlManagementDeploymentsLog         = ApiUrlManagement +
		"/deployments/#id/devices/#devid/log"
	ApiUrlManagementDeploymentsDeviceId      = ApiUrlManagement + "/deployments/devices/#id"
	ApiUrlManagementDeploymentsDeviceHistory = ApiUrlManagement + "/deployments/devices/#id/history"
	ApiUrlManagementDeploymentsDeviceList    = ApiUrlManagement + "/deployments/#id/device_list"

	ApiUrlManagementReleases     = ApiUrlManagement + "/deployments/releases"
	ApiUrlManagementReleasesList = ApiUrlManagement + "/deployments/releases/list"

	ApiUrlManagementLimitsName = ApiUrlManagement + "/limits/#name"

	ApiUrlManagementV2                      = "/api/management/v2/deployments"
	ApiUrlManagementV2Releases              = ApiUrlManagementV2 + "/deployments/releases"
	ApiUrlManagementV2ReleasesName          = ApiUrlManagementV2Releases + "/#name"
	ApiUrlManagementV2ReleaseTags           = ApiUrlManagementV2Releases + "/#name/tags"
	ApiUrlManagementV2ReleaseAllTags        = ApiUrlManagementV2 + "/releases/all/tags"
	ApiUrlManagementV2ReleaseAllUpdateTypes = ApiUrlManagementV2 + "/releases/all/types"

	ApiUrlDevicesDeploymentsNext  = ApiUrlDevices + "/device/deployments/next"
	ApiUrlDevicesDeploymentStatus = ApiUrlDevices + "/device/deployments/#id/status"
	ApiUrlDevicesDeploymentsLog   = ApiUrlDevices + "/device/deployments/#id/log"
	ApiUrlDevicesDownloadConfig   = ApiUrlDevices +
		"/download/configuration/#deployment_id/#device_type/#device_id"

	ApiUrlInternalAlive                    = ApiUrlInternal + "/alive"
	ApiUrlInternalHealth                   = ApiUrlInternal + "/health"
	ApiUrlInternalTenants                  = ApiUrlInternal + "/tenants"
	ApiUrlInternalTenantDeployments        = ApiUrlInternal + "/tenants/#tenant/deployments"
	ApiUrlInternalTenantDeploymentsDevices = ApiUrlInternal + "/tenants/#tenant/deployments/devices"
	ApiUrlInternalTenantDeploymentsDevice  = ApiUrlInternal +
		"/tenants/#tenant/deployments/devices/#id"
	ApiUrlInternalTenantArtifacts       = ApiUrlInternal + "/tenants/#tenant/artifacts"
	ApiUrlInternalTenantStorageSettings = ApiUrlInternal +
		"/tenants/#tenant/storage/settings"
	ApiUrlInternalDeviceConfigurationDeployments = ApiUrlInternal +
		"/tenants/#tenant/configuration/deployments/#deployment_id/devices/#device_id"
	ApiUrlInternalDeviceDeploymentLastStatusDeployments = ApiUrlInternal +
		"/tenants/#tenant/devices/deployments/last"
)
View Source
const Redacted = "REDACTED"

Variables

View Source
var (
	ErrIDNotUUID                      = errors.New("ID is not a valid UUID")
	ErrEmptyID                        = errors.New("id: cannot be blank")
	ErrArtifactUsedInActiveDeployment = errors.New("Artifact is used in active deployment")
	ErrInvalidExpireParam             = errors.New("Invalid expire parameter")
	ErrArtifactNameMissing            = errors.New(
		"request does not contain the name of the artifact",
	)
	ErrArtifactTypeMissing = errors.New(
		"request does not contain the type of artifact",
	)
	ErrArtifactDeviceTypesCompatibleMissing = errors.New(
		"request does not contain the list of compatible device types",
	)
	ErrArtifactFileMissing       = errors.New("request does not contain the artifact file")
	ErrModelArtifactFileTooLarge = errors.New("Artifact file too large")

	ErrInternal                   = errors.New("Internal error")
	ErrDeploymentAlreadyFinished  = errors.New("Deployment already finished")
	ErrUnexpectedDeploymentStatus = errors.New("Unexpected deployment status")
	ErrMissingIdentity            = errors.New("Missing identity data")
	ErrMissingSize                = errors.New("missing size form-data")
	ErrMissingGroupName           = errors.New("Missing group name")

	ErrInvalidSortDirection = fmt.Errorf("invalid form value: must be one of \"%s\" or \"%s\"",
		model.SortDirectionAscending, model.SortDirectionDescending)
)

Errors

View Source
var (
	ErrReleaseNameNotProvided        = errors.New("at least one release name has to be provided")
	ErrReleaseUsedInActiveDeployment = errors.New("release(s) used in active deployment")
)

Errors

Functions

func FMTConfigURL

func FMTConfigURL(scheme, hostname, deploymentID, deviceType, deviceID string) string

func InternalRoutes

func InternalRoutes(controller *DeploymentsApiHandlers) []*rest.Route

func NewDeploymentsResourceRoutes

func NewDeploymentsResourceRoutes(controller *DeploymentsApiHandlers) []*rest.Route

func NewHandler

func NewHandler(
	ctx context.Context,
	app app.App,
	ds store.DataStore,
	cfg *Config,
) (http.Handler, error)

NewRouter defines all REST API routes.

func NewImagesResourceRoutes

func NewImagesResourceRoutes(controller *DeploymentsApiHandlers, cfg *Config) []*rest.Route

func NewLimitsResourceRoutes

func NewLimitsResourceRoutes(controller *DeploymentsApiHandlers) []*rest.Route

func ParseLookupQuery

func ParseLookupQuery(vals url.Values) (model.Query, error)

func ReleasesRoutes

func ReleasesRoutes(controller *DeploymentsApiHandlers) []*rest.Route

func ServiceUnavailable

func ServiceUnavailable(w rest.ResponseWriter, r *rest.Request)

Types

type Config

type Config struct {

	// PresignSecret holds the secret value used by the signature algorithm.
	PresignSecret []byte
	// PresignExpire duration until the link expires.
	PresignExpire time.Duration
	// PresignHostname is the signed url hostname.
	PresignHostname string
	// PresignScheme is the URL scheme used for generating signed URLs.
	PresignScheme string
	// MaxImageSize is the maximum image size
	MaxImageSize        int64
	MaxGenerateDataSize int64

	EnableDirectUpload bool
	// EnableDirectUploadSkipVerify allows turning off the verification of uploaded artifacts
	EnableDirectUploadSkipVerify bool

	// DisableNewReleasesFeature is a flag that turns off the new API end-points
	// related to releases; helpful in performing long-running maintenance and data
	// migrations on the artifacts and releases collections.
	DisableNewReleasesFeature bool
}

func NewConfig

func NewConfig() *Config

func (*Config) SetDisableNewReleasesFeature

func (conf *Config) SetDisableNewReleasesFeature(disable bool) *Config

func (*Config) SetEnableDirectUpload

func (conf *Config) SetEnableDirectUpload(enable bool) *Config

func (*Config) SetEnableDirectUploadSkipVerify

func (conf *Config) SetEnableDirectUploadSkipVerify(enable bool) *Config

func (*Config) SetMaxGenerateDataSize

func (conf *Config) SetMaxGenerateDataSize(size int64) *Config

func (*Config) SetMaxImageSize

func (conf *Config) SetMaxImageSize(size int64) *Config

func (*Config) SetPresignExpire

func (conf *Config) SetPresignExpire(duration time.Duration) *Config

func (*Config) SetPresignHostname

func (conf *Config) SetPresignHostname(hostname string) *Config

func (*Config) SetPresignScheme

func (conf *Config) SetPresignScheme(scheme string) *Config

func (*Config) SetPresignSecret

func (conf *Config) SetPresignSecret(key []byte) *Config

type DeploymentsApiHandlers

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

func NewDeploymentsApiHandlers

func NewDeploymentsApiHandlers(
	store store.DataStore,
	view RESTView,
	app app.App,
	config ...*Config,
) *DeploymentsApiHandlers

func (*DeploymentsApiHandlers) AbortDeployment

func (d *DeploymentsApiHandlers) AbortDeployment(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) AbortDeviceDeployments

func (d *DeploymentsApiHandlers) AbortDeviceDeployments(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) AbortDeviceDeploymentsInternal

func (d *DeploymentsApiHandlers) AbortDeviceDeploymentsInternal(w rest.ResponseWriter,
	r *rest.Request)

func (*DeploymentsApiHandlers) AliveHandler

func (d *DeploymentsApiHandlers) AliveHandler(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) CompleteUpload

func (d *DeploymentsApiHandlers) CompleteUpload(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) DeleteDeviceDeploymentsHistory

func (d *DeploymentsApiHandlers) DeleteDeviceDeploymentsHistory(w rest.ResponseWriter,
	r *rest.Request)

func (*DeploymentsApiHandlers) DeleteImage

func (d *DeploymentsApiHandlers) DeleteImage(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) DeleteReleases

func (d *DeploymentsApiHandlers) DeleteReleases(
	w rest.ResponseWriter,
	r *rest.Request,
)

func (*DeploymentsApiHandlers) DeployToGroup

func (d *DeploymentsApiHandlers) DeployToGroup(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) DeploymentsPerTenantHandler

func (d *DeploymentsApiHandlers) DeploymentsPerTenantHandler(
	w rest.ResponseWriter,
	r *rest.Request,
)

func (*DeploymentsApiHandlers) DownloadConfiguration

func (d *DeploymentsApiHandlers) DownloadConfiguration(w rest.ResponseWriter, r *rest.Request)
func (d *DeploymentsApiHandlers) DownloadLink(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) EditImage

func (*DeploymentsApiHandlers) GenerateImage

func (d *DeploymentsApiHandlers) GenerateImage(w rest.ResponseWriter, r *rest.Request)

GenerateImage s the multipart Raw Data/Meta upload handler. Request should be of type "multipart/form-data". The parts are key/valyue pairs of metadata information except the last one, which must contain the file containing the raw data to be processed into an artifact.

func (*DeploymentsApiHandlers) GetDeployment

func (d *DeploymentsApiHandlers) GetDeployment(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) GetDeploymentDeviceList

func (d *DeploymentsApiHandlers) GetDeploymentDeviceList(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) GetDeploymentForDevice

func (d *DeploymentsApiHandlers) GetDeploymentForDevice(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) GetDeploymentLogForDevice

func (d *DeploymentsApiHandlers) GetDeploymentLogForDevice(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) GetDeploymentStats

func (d *DeploymentsApiHandlers) GetDeploymentStats(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) GetDeploymentsStats

func (d *DeploymentsApiHandlers) GetDeploymentsStats(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) GetDeviceDeploymentLastStatus

func (d *DeploymentsApiHandlers) GetDeviceDeploymentLastStatus(
	w rest.ResponseWriter,
	r *rest.Request,
)

device deployments last status handler

func (*DeploymentsApiHandlers) GetDeviceStatusesForDeployment

func (d *DeploymentsApiHandlers) GetDeviceStatusesForDeployment(
	w rest.ResponseWriter,
	r *rest.Request,
)

func (*DeploymentsApiHandlers) GetDevicesListForDeployment

func (d *DeploymentsApiHandlers) GetDevicesListForDeployment(
	w rest.ResponseWriter,
	r *rest.Request,
)

func (*DeploymentsApiHandlers) GetImage

func (*DeploymentsApiHandlers) GetImages

func (*DeploymentsApiHandlers) GetLimit

func (*DeploymentsApiHandlers) GetReleaseTagKeys

func (d *DeploymentsApiHandlers) GetReleaseTagKeys(
	w rest.ResponseWriter,
	r *rest.Request,
)

func (*DeploymentsApiHandlers) GetReleases

func (d *DeploymentsApiHandlers) GetReleases(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) GetReleasesUpdateTypes

func (d *DeploymentsApiHandlers) GetReleasesUpdateTypes(
	w rest.ResponseWriter,
	r *rest.Request,
)

func (*DeploymentsApiHandlers) GetTenantStorageSettingsHandler

func (d *DeploymentsApiHandlers) GetTenantStorageSettingsHandler(
	w rest.ResponseWriter,
	r *rest.Request,
)

func (*DeploymentsApiHandlers) HealthHandler

func (d *DeploymentsApiHandlers) HealthHandler(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) ListDeviceDeployments

func (d *DeploymentsApiHandlers) ListDeviceDeployments(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) ListDeviceDeploymentsByIDsInternal

func (d *DeploymentsApiHandlers) ListDeviceDeploymentsByIDsInternal(w rest.ResponseWriter,
	r *rest.Request)

func (*DeploymentsApiHandlers) ListDeviceDeploymentsInternal

func (d *DeploymentsApiHandlers) ListDeviceDeploymentsInternal(w rest.ResponseWriter,
	r *rest.Request)

func (*DeploymentsApiHandlers) ListImages

func (d *DeploymentsApiHandlers) ListImages(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) ListReleases

func (d *DeploymentsApiHandlers) ListReleases(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) ListReleasesV2

func (d *DeploymentsApiHandlers) ListReleasesV2(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) LookupDeployment

func (d *DeploymentsApiHandlers) LookupDeployment(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) NewImage

NewImage is the Multipart Image/Meta upload handler. Request should be of type "multipart/form-data". The parts are key/value pairs of metadata information except the last one, which must contain the artifact file.

func (*DeploymentsApiHandlers) NewImageForTenantHandler

func (d *DeploymentsApiHandlers) NewImageForTenantHandler(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) ParseGenerateImageMultipart

func (d *DeploymentsApiHandlers) ParseGenerateImageMultipart(
	r *multipart.Reader,
) (*model.MultipartGenerateImageMsg, error)

ParseGenerateImageMultipart parses multipart/form-data message.

func (*DeploymentsApiHandlers) ParseMultipart

ParseMultipart parses multipart/form-data message.

func (*DeploymentsApiHandlers) PatchRelease

func (d *DeploymentsApiHandlers) PatchRelease(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) PostDeployment

func (d *DeploymentsApiHandlers) PostDeployment(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) PostDeviceConfigurationDeployment

func (d *DeploymentsApiHandlers) PostDeviceConfigurationDeployment(
	w rest.ResponseWriter,
	r *rest.Request,
)

device configuration deployment handler

func (*DeploymentsApiHandlers) ProvisionTenantsHandler

func (d *DeploymentsApiHandlers) ProvisionTenantsHandler(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) PutDeploymentLogForDevice

func (d *DeploymentsApiHandlers) PutDeploymentLogForDevice(w rest.ResponseWriter, r *rest.Request)

func (*DeploymentsApiHandlers) PutDeploymentStatusForDevice

func (d *DeploymentsApiHandlers) PutDeploymentStatusForDevice(
	w rest.ResponseWriter,
	r *rest.Request,
)

func (*DeploymentsApiHandlers) PutReleaseTags

func (d *DeploymentsApiHandlers) PutReleaseTags(
	w rest.ResponseWriter,
	r *rest.Request,
)

func (*DeploymentsApiHandlers) PutTenantStorageSettingsHandler

func (d *DeploymentsApiHandlers) PutTenantStorageSettingsHandler(
	w rest.ResponseWriter,
	r *rest.Request,
)
func (d *DeploymentsApiHandlers) UploadLink(w rest.ResponseWriter, r *rest.Request)

type RESTView

type RESTView interface {
	RenderSuccessGet(w rest.ResponseWriter, object interface{})
	RenderError(w rest.ResponseWriter, r *rest.Request, err error, status int, l *log.Logger)
	RenderInternalError(w rest.ResponseWriter, r *rest.Request, err error, l *log.Logger)
	RenderNoUpdateForDevice(w rest.ResponseWriter)
	RenderSuccessPost(w rest.ResponseWriter, r *rest.Request, id string)
	RenderEmptySuccessResponse(w rest.ResponseWriter)
	RenderErrorNotFound(w rest.ResponseWriter, r *rest.Request, l *log.Logger)
	RenderDeploymentLog(w rest.ResponseWriter, dlog model.DeploymentLog)
	RenderSuccessDelete(w rest.ResponseWriter)
	RenderSuccessPut(w rest.ResponseWriter)
}

Jump to

Keyboard shortcuts

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