From 6064e94858192d1c83742f4d95d799d7539a4c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Mon, 11 Mar 2019 21:47:16 +0100 Subject: [PATCH] moved piwigo authentication --- internal/app/app.go | 7 ++-- .../{authentication => }/authentication.go | 38 ++++++++++++++++--- internal/pkg/piwigo/authentication/types.go | 30 --------------- 3 files changed, 36 insertions(+), 39 deletions(-) rename internal/pkg/piwigo/{authentication => }/authentication.go (66%) delete mode 100644 internal/pkg/piwigo/authentication/types.go diff --git a/internal/app/app.go b/internal/app/app.go index c60e3ba..8f64bf0 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -6,7 +6,6 @@ import ( "fmt" "git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/localFileStructure" "git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo" - "git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo/authentication" "github.com/sirupsen/logrus" "os" ) @@ -50,7 +49,7 @@ func Run() { logErrorAndExit(err, 6) } - _ = authentication.Logout(context.Piwigo) + _ = piwigo.Logout(context.Piwigo) } func configureContext() (*appContext, error) { @@ -81,7 +80,7 @@ func configureContext() (*appContext, error) { func loginToPiwigoAndConfigureContext(context *appContext) error { logrus.Infoln("Logging in to piwigo and getting chunk size configuration for uploads") - err := authentication.Login(context.Piwigo) + err := piwigo.Login(context.Piwigo) if err != nil { return err } @@ -89,7 +88,7 @@ func loginToPiwigoAndConfigureContext(context *appContext) error { } func initializeUploadChunkSize(context *appContext) error { - userStatus, err := authentication.GetStatus(context.Piwigo) + userStatus, err := piwigo.GetStatus(context.Piwigo) if err != nil { return err } diff --git a/internal/pkg/piwigo/authentication/authentication.go b/internal/pkg/piwigo/authentication.go similarity index 66% rename from internal/pkg/piwigo/authentication/authentication.go rename to internal/pkg/piwigo/authentication.go index 9479d7a..9b78544 100644 --- a/internal/pkg/piwigo/authentication/authentication.go +++ b/internal/pkg/piwigo/authentication.go @@ -1,16 +1,44 @@ -package authentication +package piwigo import ( "encoding/json" "errors" "fmt" - "git.haefelfinger.net/piwigo/PiwigoDirectoryUploader/internal/pkg/piwigo" "github.com/sirupsen/logrus" "net/url" "strings" ) -func Login(context *piwigo.PiwigoContext) error { +type LoginResponse struct { + Status string `json:"stat"` + Result bool `json:"result"` + ErrorNumber int `json:"err"` + Message string `json:"message"` +} + +type GetStatusResponse struct { + Status string `json:"stat"` + Result struct { + Username string `json:"username"` + Status string `json:"status"` + Theme string `json:"theme"` + Language string `json:"language"` + PwgToken string `json:"pwg_token"` + Charset string `json:"charset"` + CurrentDatetime string `json:"current_datetime"` + Version string `json:"version"` + AvailableSizes []string `json:"available_sizes"` + UploadFileTypes string `json:"upload_file_types"` + UploadFormChunkSize int `json:"upload_form_chunk_size"` + } `json:"result"` +} + +type LogoutResponse struct { + Status string `json:"stat"` + Result bool `json:"result"` +} + +func Login(context *PiwigoContext) error { logrus.Debugf("Logging in to %s using user %s", context.Url, context.Username) if !strings.HasPrefix(context.Url, "https") { @@ -44,7 +72,7 @@ func Login(context *piwigo.PiwigoContext) error { return nil } -func Logout(context *piwigo.PiwigoContext) error { +func Logout(context *PiwigoContext) error { logrus.Debugf("Logging out from %s", context.Url) formData := url.Values{} @@ -70,7 +98,7 @@ func Logout(context *piwigo.PiwigoContext) error { return nil } -func GetStatus(context *piwigo.PiwigoContext) (*GetStatusResponse, error) { +func GetStatus(context *PiwigoContext) (*GetStatusResponse, error) { logrus.Debugln("Getting current login state...") formData := url.Values{} diff --git a/internal/pkg/piwigo/authentication/types.go b/internal/pkg/piwigo/authentication/types.go deleted file mode 100644 index 2a4be07..0000000 --- a/internal/pkg/piwigo/authentication/types.go +++ /dev/null @@ -1,30 +0,0 @@ -package authentication - -type LoginResponse struct { - Status string `json:"stat"` - Result bool `json:"result"` - ErrorNumber int `json:"err"` - Message string `json:"message"` -} - -type GetStatusResponse struct { - Status string `json:"stat"` - Result struct { - Username string `json:"username"` - Status string `json:"status"` - Theme string `json:"theme"` - Language string `json:"language"` - PwgToken string `json:"pwg_token"` - Charset string `json:"charset"` - CurrentDatetime string `json:"current_datetime"` - Version string `json:"version"` - AvailableSizes []string `json:"available_sizes"` - UploadFileTypes string `json:"upload_file_types"` - UploadFormChunkSize int `json:"upload_form_chunk_size"` - } `json:"result"` -} - -type LogoutResponse struct { - Status string `json:"stat"` - Result bool `json:"result"` -}