server

package
v0.0.0-...-02be50d Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConfig

func NewConfig(clientID, clientSecret, redirectURL string) (*oauth2.Config, error)

NewConfig creates the configuration of oauth2 using given clientID, clientSecret and redirectURL. Scopes and provider are set by default.

func SetUpRouter

func SetUpRouter(service *SharedService) *gin.Engine

SetUpRouter creates new router using SharedService.

func StartProcessingWithNewRequestID

func StartProcessingWithNewRequestID(requests *RequestsMap, email string, handler RequestHandler) string

StartProcessingWithNewRequestID finds unused request ID and calls StartProcessing method of RequestsMap

Types

type AuthorizationService

type AuthorizationService interface {
	// Returns redirect URL to login page used for authentication
	AuthCodeURL(options ...oauth2.AuthCodeOption) string
	// Returns idToken that should be used to authorize
	CreateUser(authCode string) (string, error)
	// Verify checks that token is valid, not expired and issued by our app and returns user email
	Verify(token string) (string, error)
	// Returns GoogleService that should be used to make requests to Google APIs
	GetUser(email string) (User, bool)
}

AuthorizationService creates the user using authentication code and returns idToken. Returns authorized user for this idToken.

func NewAuthorizationService

func NewAuthorizationService(config oauth2.Config) (AuthorizationService, error)

NewAuthorizationService creates new AuthorizationService to access GoogleAPIs

type CheckRequest

type CheckRequest struct {
	Projects []string `json:"projects"`
}

CheckRequest contains the body of POST /requirements

type CheckRequirementsResponse

type CheckRequirementsResponse struct {
	ProjectsRequirements []*automation.ProjectRequirements `json:"projectsRequirements"`
}

CheckRequirementsResponse is response to /requirements method

type CheckStatusResponse

type CheckStatusResponse struct {
	Status       string `json:"status"`
	ErrorMessage string `json:"errorMessage,omitempty"`
}

CheckStatusResponse is the response to recommendations/name/checkStatus method

type ErrorResponse

type ErrorResponse struct {
	ErrorMessage string `json:"errorMessage"`
}

ErrorResponse is response with error containing error message.

type ListRecommendationsResponse

type ListRecommendationsResponse struct {
	Recommendations []*recommender.GoogleCloudRecommenderV1Recommendation `json:"recommendations"`
	FailedProjects  []*automation.ProjectRequirements                     `json:"failedProjects"`
}

ListRecommendationsResponse is response to list/recommendations method

type ListRequest

type ListRequest struct {
	Projects []string `json:"projects"`
}

ListRequest contains the body of POST /recommendations request

type Progress

type Progress struct {
	BatchesProcessed int `json:"batchesProcessed"`
	NumberOfBatches  int `json:"numberOfBatches"`
}

Progress is the structure that stores the fraction of work done for some request

type ProjectsResponse

type ProjectsResponse struct {
	Projects []string `json:"projects"`
}

ProjectsResponse is the response to projects.list method

type RequestHandler

type RequestHandler interface {
	// Start method starts doing the request
	Start()
	// GetResponse returns the current response and whether the request is already done.
	// For example, while request is still in proccess Response will contain some progress info,
	// and after request is done, Response will contain result, second value will be `true`.
	GetResponse() (Response, bool)
}

RequestHandler is the type that can start request processing and get results

func NewApplyRequestHandler

func NewApplyRequestHandler(service automation.GoogleService, name string) RequestHandler

NewApplyRequestHandler creates new applyRequestHandler

func NewCheckRequestHandler

func NewCheckRequestHandler(service automation.GoogleService, projects []string) RequestHandler

NewCheckRequestHandler creates new checkRequestHandler

func NewListRequestHandler

func NewListRequestHandler(service automation.GoogleService, projects []string) RequestHandler

NewListRequestHandler creates new listRequestHandler

type RequestInfo

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

RequestInfo contains information needed to indentify the request

type RequestsMap

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

RequestsMap contains current requests and handles getting response for them, deleting, adding new requests.

func NewRequestsMap

func NewRequestsMap() RequestsMap

NewRequestsMap creates new RequestsMap

func (*RequestsMap) GetResponse

func (m *RequestsMap) GetResponse(info RequestInfo) (Response, bool)

GetResponse returns response if request is in process or finished. If request is finished, deletes it from the map. If there's no such request returns false in second value.

func (*RequestsMap) StartProcessing

func (m *RequestsMap) StartProcessing(info RequestInfo, handler RequestHandler) error

StartProcessing starts the processing of the request. If such request is already in the map, returns error.

type Response

type Response struct {
	Content interface{}
	Error   error
}

Response contains response that should be sent in response to the request. If Error is nil, response should be sent with http.StatusOK. Otherwise, something unexpected happened and error is specified in the Error field.

type SharedService

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

SharedService is the struct that contains authorization service and information about currently processed requests.

func NewSharedService

func NewSharedService(conf oauth2.Config) (*SharedService, error)

NewSharedService creates new sharedService to access GoogleAPIs.

type User

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

User contains fields describing authorized user: Email and GoogleService with required access to Google APIs.

Jump to

Keyboard shortcuts

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