api

package
v0.0.0-...-9073158 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultRateLimit  = "10-M"
	EnableAdminAPIs   = false
	LighthouseClient  pb.LighthouseServiceClient
	LighthouseClients map[string]pb.LighthouseServiceClient
	ApiUrl            string
	GCPProject        = ""
	GCPRegion         = ""
	GCPTaskQueue      = ""
	Scheduler         = ""
	Auth              = ""
)
View Source
var (
	SmtpHost     = ""
	SmtpPort     = 465
	SmtpUsername = ""
	SmtpPassword = ""
	FromEmail    = "info@websu.io"
)
View Source
var (
	DB           *mongo.Client
	DatabaseName = "websu"
)
View Source
var FirebaseApp *firebase.App

Functions

func ConnectLHLocations

func ConnectLHLocations()

func ConnectToLighthouseServer

func ConnectToLighthouseServer(address string, secure bool) pb.LighthouseServiceClient

func CreateGCPCloudTask

func CreateGCPCloudTask(projectID, locationID, queueID, url string, body []byte) (*taskspb.Task, error)

func CreateMemRateLimiter

func CreateMemRateLimiter(rate string) *mhttp.Middleware

func CreateMongoClient

func CreateMongoClient(mongoURI string)

func CreateMongoIndexes

func CreateMongoIndexes()

func CreateRedisClient

func CreateRedisClient(url string) *libredis.Client

func CreateRedisRateLimiter

func CreateRedisRateLimiter(rate string, prefix string, rClient *libredis.Client) *mhttp.Middleware

func GetAllReportsCount

func GetAllReportsCount() (int64, error)

func HTTPRunReport

func HTTPRunReport(r ReportRequest)

func InitFirebase

func InitFirebase()

func JwtMiddleware

func JwtMiddleware(next http.Handler) http.Handler

func RunScheduledReports

func RunScheduledReports(reportRunner ReportRunner) int

func StdoutLoggingHandler

func StdoutLoggingHandler(h http.Handler) http.Handler

func TokenFromAuthHeader

func TokenFromAuthHeader(r *http.Request) (string, error)

Types

type App

type App struct {
	Router      *mux.Router
	RedisClient *libredis.Client
}

func NewApp

func NewApp(opts ...AppOption) *App

func (*App) Run

func (a *App) Run(address string)

func (*App) RunScheduledReports

func (a *App) RunScheduledReports(w http.ResponseWriter, r *http.Request)

func (*App) ScheduledReportDelete

func (a *App) ScheduledReportDelete(w http.ResponseWriter, r *http.Request)

func (*App) ScheduledReportGet

func (a *App) ScheduledReportGet(w http.ResponseWriter, r *http.Request)

func (*App) ScheduledReportsGet

func (a *App) ScheduledReportsGet(w http.ResponseWriter, r *http.Request)

func (*App) ScheduledReportsPost

func (a *App) ScheduledReportsPost(w http.ResponseWriter, r *http.Request)

func (*App) SetupRoutes

func (a *App) SetupRoutes()

type AppOption

type AppOption func(c *App)

func WithRedis

func WithRedis(redisURL string) AppOption

type AuditResult

type AuditResult struct {
	ID               string  `json:"id"`
	Title            string  `json:"title"`
	Description      string  `json:"description"`
	Score            float32 `json:"score"`
	ScoreDisplayMode string  `json:"scoreDisplayMode"`
	NumericValue     float64 `json:"numericValue"`
	NumericUnit      string  `json:"numericUnit"`
	DisplayValue     string  `json:"DisplayValue"`
}

type GCPScheduler

type GCPScheduler struct {
	Project  string
	Location string
	Queue    string
}

func (GCPScheduler) RunReport

func (g GCPScheduler) RunReport(sr ScheduledReport)

type GoScheduler

type GoScheduler struct{}

func (GoScheduler) RunReport

func (g GoScheduler) RunReport(sr ScheduledReport)

func (*GoScheduler) Start

func (gs *GoScheduler) Start()

type Location

type Location struct {
	ID          primitive.ObjectID `json:"id" bson:"_id"`
	Name        string             `json:"name" bson:"name" example:"australia-southeast1"`
	DisplayName string             `json:"display_name" bson:"display_name" example:"Sydney, AU"`
	Address     string             `json:"address" bson:"address" example:"8.8.8.8:50051"`
	// Flag to indicate whether TLS should be used
	Secure    bool      `json:"secure" bson:"secure"`
	Order     int32     `json:"order" bson:"order"`
	Premium   bool      `json:"premium" bson:"premium"`
	CreatedAt time.Time `json:"created_at" bson:"created_at"`
}

func GetAllLocations

func GetAllLocations() ([]Location, error)

func GetLocationByName

func GetLocationByName(name string) (Location, error)

func GetLocationByObjectIDHex

func GetLocationByObjectIDHex(hex string) (Location, error)

func NewLocation

func NewLocation() *Location

func NewLocationWithID

func NewLocationWithID(id string) (*Location, error)

func (*Location) Delete

func (location *Location) Delete() error

func (*Location) Insert

func (location *Location) Insert() error

func (*Location) Upsert

func (location *Location) Upsert() error

type Report

type Report struct {
	ID              primitive.ObjectID `json:"id" bson:"_id"`
	ReportRequest   `bson:",inline"`
	LocationDisplay string `json:"location_display" bson:"location_display"`
	// RawJSON contains the lighthouse JSON result
	RawJSON          string                 `json:"raw_json" bson:"raw_json"`
	CreatedAt        time.Time              `json:"created_at" bson:"created_at"`
	PerformanceScore float32                `json:"performance_score" bson:"performance_score"`
	AuditResults     map[string]AuditResult `json:"audit_results" bson:"audit_results"`
}

func GetReportByObjectIDHex

func GetReportByObjectIDHex(hex string) (Report, error)

func GetReports

func GetReports(limit int64, skip int64, query map[string]interface{}) ([]Report, error)

func NewReport

func NewReport() *Report

func NewReportFromRequest

func NewReportFromRequest(rr *ReportRequest) *Report

func (*Report) Delete

func (report *Report) Delete() error

func (*Report) Insert

func (report *Report) Insert() error

func (*Report) SendEmail

func (report *Report) SendEmail() error

type ReportRequest

type ReportRequest struct {
	// Required parameter the URL of the website
	URL string `json:"url" bson:"url" example:"https://www.google.com"`
	// Optional parameter, possible values are desktop or mobile. If unset will default to desktop
	FormFactor string `json:"form_factor" bson:"form_factor" example:"desktop"`
	// Optional parameter, by default will be set to 1000 if omitted
	ThroughputKbps int64 `json:"throughput_kbps" bson:"thoughput_kbps" example:"50000"`
	// Optional parameter, default location will be used if not set
	Location string `json:"location" bson:"location" example:"australia-southeast1"`
	// Optional parameter, email adress to sent the report to
	Email string `json:"email,omitempty" bson:"email"`
	User  string `json:"user,omitempty" bson:"user"`
}

func (ReportRequest) Validate

func (r ReportRequest) Validate() error

type ReportRunner

type ReportRunner interface {
	RunReport(sr ScheduledReport)
}

type ScheduledReport

type ScheduledReport struct {
	ID            primitive.ObjectID `json:"id" bson:"_id"`
	ReportRequest `bson:",inline"`
	Schedule      string    `json:"schedule" bson:"schedule" example:"daily"`
	LastRun       time.Time `json:"last_run" bson:"last_run"`
	CreatedAt     time.Time `json:"created_at" bson:"created_at"`
}

func GetAllScheduledReports

func GetAllScheduledReports() ([]ScheduledReport, error)

func GetScheduleReportsDueToRun

func GetScheduleReportsDueToRun() ([]ScheduledReport, error)

func GetScheduledReportByObjectIDHex

func GetScheduledReportByObjectIDHex(hex string) (ScheduledReport, error)

func NewScheduledReport

func NewScheduledReport() *ScheduledReport

func (*ScheduledReport) Delete

func (sr *ScheduledReport) Delete() error

func (*ScheduledReport) Insert

func (sr *ScheduledReport) Insert() error

func (*ScheduledReport) Update

func (sr *ScheduledReport) Update() error

func (ScheduledReport) Validate

func (s ScheduledReport) Validate() error

Jump to

Keyboard shortcuts

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