server

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrBindingFromGin         = "(debugging message) error binding json"
	ErrRetrievingOauthCode    = "error retrieving oauth login credentials; try again"
	ErrCreatingPortwardenUser = "error creating a portwarden user"
	ErrGettingPortwardenUser  = "error getting a portwarden user"
	ErrMergingPortwardenUser  = "error merging a portwarden user"
	ErrLoginWithBitwarden     = "error logging in with Bitwarden"
	ErrSettingupBackup        = "error setting up backup"
	ErrBackupNotCancelled     = "error cancelling back up"

	MsgSuccessfullyCancelledBackingUp = "successfully cancelled backup process"

	FrontEndBaseAddressTest = "http://localhost:8000/"
	FrontEndBaseAddressProd = ""
)
View Source
const (
	ErrWillNotSetupBackupByUser = "err the user stopped backing up"
)
View Source
const (
	GoogleOauth2TokenContextVariableName = "GoogleOauth2TokenContextVariableName"
)

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware() gin.HandlerFunc

func CancelEncryptBackupHandler

func CancelEncryptBackupHandler(c *gin.Context)

func DecryptBackupHandler

func DecryptBackupHandler(c *gin.Context)

func EncryptBackupHandler

func EncryptBackupHandler(c *gin.Context)

func GetClient

func GetClient(ctx context.Context, config *oauth2.Config) *http.Client

GetClient uses a Context and Config to retrieve a Token then generate a Client. It returns the generated Client.

func GetOrCreateFolder

func GetOrCreateFolder(srv *drive.Service, folderName string) (string, error)

func GetTokenFromWeb

func GetTokenFromWeb(config *oauth2.Config) *oauth2.Token

GetTokenFromWeb uses Config to request a Token. It returns the retrieved Token.

func SaveToken

func SaveToken(file string, token *oauth2.Token)

saveToken uses a file path to create a file and store the token in it.

func TokenAuthMiddleware

func TokenAuthMiddleware() gin.HandlerFunc

func UploadFile

func UploadFile(fileBytes []byte, token *oauth2.Token) (*oauth2.Token, error)

UploadFile upload the fileBytes to Google Drive's portwarden folder https://gist.github.com/tzmartin/f5732091783752660b671c20479f519a

func VerifyGoogleAccessToekn

func VerifyGoogleAccessToekn(access_token string) (bool, error)

Types

type BackupSetting

type BackupSetting struct {
	Passphrase             string `json:"passphrase"`
	BackupFrequencySeconds int    `json:"backup_frequency_seconds"`
	WillSetupBackup        bool   `json:"will_setup_backup"`
}

type DecryptBackupInfo

type DecryptBackupInfo struct {
	File       *multipart.FileHeader `form:"file"`
	Passphrase string                `form:"passphrase"`
}

type GoogleDriveCredentials

type GoogleDriveCredentials struct {
	State string `form:"state"`
	Code  string `form:"code"`
	Scope string `form:"scope"`
}

type GoogleTokenVerifyResponse

type GoogleTokenVerifyResponse struct {
	IssuedTo      string `json:"issued_to"`
	Audience      string `json:"audience"`
	UserID        string `json:"user_id"`
	Scope         string `json:"scope"`
	ExpiresIn     int64  `json:"expires_in"`
	Email         string `json:"email"`
	VerifiedEmail bool   `json:"verified_email"`
	AccessType    string `json:"access_type"`
}

type GoogleUserInfo

type GoogleUserInfo struct {
	ID         string `json:"id"`
	Email      string `json:"email"`
	Name       string `json:"name"`
	GivenName  string `json:"given_name"`
	FamilyName string `json:"family_name"`
	Link       string `json:"link"`
	Picture    string `json:"picture"`
	Locale     string `json:"locale"`
}

func RetrieveUserEmail

func RetrieveUserEmail(token *oauth2.Token) (GoogleUserInfo, error)

type PortwardenServer

type PortwardenServer struct {
	Port                      int
	Router                    *gin.Engine
	GoogleDriveContext        context.Context
	GoogleDriveAppCredentials []byte
	GoogleDriveAppConfig      *oauth2.Config
}

func (*PortwardenServer) GetGoogleDriveLoginHandler

func (ps *PortwardenServer) GetGoogleDriveLoginHandler(c *gin.Context)

func (*PortwardenServer) GetGoogleDriveLoginURLHandler

func (ps *PortwardenServer) GetGoogleDriveLoginURLHandler(c *gin.Context)

TODO: GoogleDriveHandler() will return Json with the google login url Not sure if it's supposed to call UploadFile() directly

func (*PortwardenServer) Run

func (ps *PortwardenServer) Run()

type PortwardenUser

type PortwardenUser struct {
	Email                     string                       `json:"email"`
	BitwardenDataJSON         []byte                       `json:"bitwarden_data_json"`
	BitwardenSessionKey       string                       `json:"bitwarden_session_key"`
	BackupSetting             BackupSetting                `json:"backup_setting"`
	BitwardenLoginCredentials *portwarden.LoginCredentials `json:"bitwarden_login_credentials"` // Not stored in Redis
	GoogleUserInfo            GoogleUserInfo
	GoogleToken               *oauth2.Token
}

func (*PortwardenUser) CreateWithGoogle

func (pu *PortwardenUser) CreateWithGoogle() error

func (*PortwardenUser) Get

func (pu *PortwardenUser) Get() error

func (*PortwardenUser) LoginWithBitwarden

func (pu *PortwardenUser) LoginWithBitwarden() error

func (*PortwardenUser) Set

func (pu *PortwardenUser) Set() error

func (*PortwardenUser) SetupAutomaticBackup

func (pu *PortwardenUser) SetupAutomaticBackup(eta *time.Time) error

Jump to

Keyboard shortcuts

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