From 7422201d9834d1bbef7264c0792d9429c5634b9e Mon Sep 17 00:00:00 2001 From: arzumify Date: Wed, 8 Jan 2025 18:31:34 +0000 Subject: [PATCH] ISM rewrite Signed-off-by: arzumify --- go.mod | 6 ++++-- go.sum | 30 ++++++++++++------------------ services-src/auth/main.go | 26 +++++++++++++------------- services-src/storage/main.go | 26 +++++++++++++------------- 4 files changed, 42 insertions(+), 46 deletions(-) diff --git a/go.mod b/go.mod index 566cbd6..5bd02c1 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module git.ailur.dev/ailur/fulgens go 1.23.3 require ( - git.ailur.dev/ailur/fg-library/v3 v3.5.0 - git.ailur.dev/ailur/fg-nucleus-library v1.1.0 + git.ailur.dev/ailur/fg-library/v3 v3.6.2 + git.ailur.dev/ailur/fg-nucleus-library v1.1.1 git.ailur.dev/ailur/pow v1.0.3 github.com/CAFxX/httpcompression v0.0.9 github.com/cespare/xxhash/v2 v2.3.0 @@ -19,6 +19,8 @@ require ( ) require ( + git.ailur.dev/ailur/datatracker v1.0.0 // indirect + git.ailur.dev/ailur/fg-library/v2 v2.0.1 // indirect github.com/andybalholm/brotli v1.1.1 // indirect github.com/gabriel-vasile/mimetype v1.4.8 // indirect github.com/go-playground/locales v0.14.1 // indirect diff --git a/go.sum b/go.sum index 9623fda..43b3143 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,19 @@ -git.ailur.dev/ailur/fg-library/v2 v2.1.2 h1:Gk8ztytJfV2GYhsnfTDRWmvTzJ3Cn19V5p2suFCvu4E= -git.ailur.dev/ailur/fg-library/v2 v2.1.2/go.mod h1:gBnZQDV70YON6cnuwB+Jawm2EABbf9dGlV0Qw4obtxs= -git.ailur.dev/ailur/fg-library/v3 v3.2.0 h1:SXVj6iCPQ6sR2ZmCZXhAU51mPgH9ERN7KZbMUB03/p4= -git.ailur.dev/ailur/fg-library/v3 v3.2.0/go.mod h1:ArNsafpqES2JuxQM5aM+bNe0FwHLIsL6pbjpiWvDwGs= -git.ailur.dev/ailur/fg-library/v3 v3.3.0 h1:VRe/shTbIfD00OWaywclb4flduAqRY81lMBXGHmMz5g= -git.ailur.dev/ailur/fg-library/v3 v3.3.0/go.mod h1:ArNsafpqES2JuxQM5aM+bNe0FwHLIsL6pbjpiWvDwGs= -git.ailur.dev/ailur/fg-library/v3 v3.4.0 h1:8Et4J6Psh7GBpQiDsQEd/hqftLzq6IMuB2AcCG+rsQA= -git.ailur.dev/ailur/fg-library/v3 v3.4.0/go.mod h1:ArNsafpqES2JuxQM5aM+bNe0FwHLIsL6pbjpiWvDwGs= +git.ailur.dev/ailur/datatracker v1.0.0 h1:zJ0HppqiGEUkpwPVtKDGdHryUkTjnQvP2y+kFcA1gD0= +git.ailur.dev/ailur/datatracker v1.0.0/go.mod h1:0WE5ozzsgckCbIrKJRav+7iOhikl3B9XGHuJ8LCnRQE= +git.ailur.dev/ailur/fg-library/v2 v2.0.1 h1:ltPYXf/Om0hnMD8gr1K5bkYrfHqKPSbb0hxa0wtTnZ0= +git.ailur.dev/ailur/fg-library/v2 v2.0.1/go.mod h1:1jYbWhabGcIwp7CkhHqvRwC8eP+nHv5BrXPe9NX2HE8= git.ailur.dev/ailur/fg-library/v3 v3.5.0 h1:BGDlS4nQ2PyZWNU4gH3eckVqhZUFIM/zKIj/HXx8RmA= git.ailur.dev/ailur/fg-library/v3 v3.5.0/go.mod h1:ArNsafpqES2JuxQM5aM+bNe0FwHLIsL6pbjpiWvDwGs= -git.ailur.dev/ailur/fg-nucleus-library v1.0.5 h1:0YVSHFOeydGR/pfq5AfiKQ5gWuxSnx8u2K8mHvEDDTI= -git.ailur.dev/ailur/fg-nucleus-library v1.0.5/go.mod h1:nKYjJ+zJD1YcrEGWlyyA5r6CrzW8DWHVAnL9hkn2tNw= +git.ailur.dev/ailur/fg-library/v3 v3.5.1 h1:9QH1myeXhGIlkihzYnH5jdgnD8UUStWC7aVWWq81hUU= +git.ailur.dev/ailur/fg-library/v3 v3.5.1/go.mod h1:ArNsafpqES2JuxQM5aM+bNe0FwHLIsL6pbjpiWvDwGs= +git.ailur.dev/ailur/fg-library/v3 v3.5.2 h1:rGvZSvmWPRMDGcM7ORMEAR2bd6QJx8vUKdki1SjRkoE= +git.ailur.dev/ailur/fg-library/v3 v3.5.2/go.mod h1:ArNsafpqES2JuxQM5aM+bNe0FwHLIsL6pbjpiWvDwGs= +git.ailur.dev/ailur/fg-library/v3 v3.6.2 h1:PNJKxpvbel2iDeB9+/rpYRyMoim6JjRHOXPYFYky7Ng= +git.ailur.dev/ailur/fg-library/v3 v3.6.2/go.mod h1:ArNsafpqES2JuxQM5aM+bNe0FwHLIsL6pbjpiWvDwGs= git.ailur.dev/ailur/fg-nucleus-library v1.1.0 h1:D0eWwdlaw4IiOwz96MiRwHIdU/VIwiHUCeO00HkzzsU= git.ailur.dev/ailur/fg-nucleus-library v1.1.0/go.mod h1:CHuOSByCmookwkcpjJBiinHEF27+IA70BhVtnR2cAhA= +git.ailur.dev/ailur/fg-nucleus-library v1.1.1 h1:IRpAQqgikeT2FyhVbhe16GyIxuTsf1Xq8oLqeUplgHk= +git.ailur.dev/ailur/fg-nucleus-library v1.1.1/go.mod h1:stxiTyMv3Fa7GzpyLbBUh3ahlb7110p0NnCl8ZTjwBs= git.ailur.dev/ailur/pow v1.0.3 h1:LjLSol4ax+M+SoajVjbBoDjfmjH6pKu3fDka7bl2KGY= git.ailur.dev/ailur/pow v1.0.3/go.mod h1:ClAmIdHQ/N9wTq5S4YWhQ5d9CPUBcEjVuOkT07zBdJ4= github.com/CAFxX/httpcompression v0.0.9 h1:0ue2X8dOLEpxTm8tt+OdHcgA+gbDge0OqFQWGKSqgrg= @@ -25,8 +27,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA= -github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU= github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= github.com/go-chi/chi/v5 v5.2.0 h1:Aj1EtB0qR2Rdo2dG4O94RIU35w2lvQSj6BRA4+qwFL0= @@ -83,16 +83,10 @@ github.com/valyala/gozstd v1.20.1 h1:xPnnnvjmaDDitMFfDxmQ4vpx0+3CdTg2o3lALvXTU/g github.com/valyala/gozstd v1.20.1/go.mod h1:y5Ew47GLlP37EkTB+B4s7r6A5rdaeB7ftbl9zoYiIPQ= github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU= github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= -golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= -golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= -golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= -golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= diff --git a/services-src/auth/main.go b/services-src/auth/main.go index 963f1ab..c78c894 100644 --- a/services-src/auth/main.go +++ b/services-src/auth/main.go @@ -70,7 +70,7 @@ func checkScopes(scopes []string) (bool, string, error) { return clientKeyShare, string(scopeString), nil } -func logFunc(message string, messageType library.MessageCode, information library.ServiceInitializationInformation) { +func logFunc(message string, messageType library.MessageCode, information *library.ServiceInitializationInformation) { // Log the message to the logger service information.SendISMessage(loggerService, messageType, message) } @@ -108,7 +108,7 @@ func sha256Base64(s string) string { return encoded } -func renderTemplate(statusCode int, w http.ResponseWriter, data map[string]interface{}, templatePath string, information library.ServiceInitializationInformation) { +func renderTemplate(statusCode int, w http.ResponseWriter, data map[string]interface{}, templatePath string, information *library.ServiceInitializationInformation) { var err error var requestedTemplate *template.Template // Output ls of the resource directory @@ -133,7 +133,7 @@ func renderTemplate(statusCode int, w http.ResponseWriter, data map[string]inter } } -func renderString(statusCode int, w http.ResponseWriter, data string, information library.ServiceInitializationInformation) { +func renderString(statusCode int, w http.ResponseWriter, data string, information *library.ServiceInitializationInformation) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(statusCode) _, err := w.Write([]byte(data)) @@ -142,7 +142,7 @@ func renderString(statusCode int, w http.ResponseWriter, data string, informatio } } -func renderJSON(statusCode int, w http.ResponseWriter, data map[string]interface{}, information library.ServiceInitializationInformation) { +func renderJSON(statusCode int, w http.ResponseWriter, data map[string]interface{}, information *library.ServiceInitializationInformation) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(statusCode) err := json.NewEncoder(w).Encode(data) @@ -188,7 +188,7 @@ func verifyJwt(token string, publicKey ed25519.PublicKey, mem *sql.DB) ([]byte, return userId, claims, true } -func Main(information library.ServiceInitializationInformation) { +func Main(information *library.ServiceInitializationInformation) { var conn library.Database var mem *sql.DB var publicKey ed25519.PublicKey @@ -1599,13 +1599,13 @@ func Main(information library.ServiceInitializationInformation) { case 0: // A service would like to have the hostname // Send it to them - message.Respond(library.Success, hostName) + message.Respond(library.Success, hostName, information) case 1: // A service would like to register a new OAuth entry // Validate the scopes clientKeyShare, scopes, err := checkScopes(message.Message.(authLibrary.OAuthInformation).Scopes) if err != nil { - message.Respond(library.BadRequest, err) + message.Respond(library.BadRequest, err, information) return } @@ -1621,7 +1621,7 @@ func Main(information library.ServiceInitializationInformation) { } if err != nil { - message.Respond(library.InternalError, err) + message.Respond(library.InternalError, err, information) logFunc(err.Error(), 2, information) return } @@ -1629,7 +1629,7 @@ func Main(information library.ServiceInitializationInformation) { message.Respond(library.Success, authLibrary.OAuthResponse{ AppID: appId, SecretKey: secret, - }) + }, information) return } @@ -1638,7 +1638,7 @@ func Main(information library.ServiceInitializationInformation) { // It must be able to be sent via JSON, so we can't have pure-binary data secret, err = randomChars(512) if err != nil { - message.Respond(library.InternalError, err) + message.Respond(library.InternalError, err, information) logFunc(err.Error(), 2, information) return } @@ -1650,7 +1650,7 @@ func Main(information library.ServiceInitializationInformation) { _, err = conn.DB.Exec("INSERT INTO oauth (appId, secret, creator, name, redirectUri, scopes) VALUES ($1, $2, $3, $4, $5, $6)", message.ServiceID.String(), secret, ServiceInformation.ServiceID[:], message.Message.(authLibrary.OAuthInformation).Name, message.Message.(authLibrary.OAuthInformation).RedirectUri, scopes) } if err != nil { - message.Respond(library.InternalError, err) + message.Respond(library.InternalError, err, information) logFunc(err.Error(), 2, information) return } @@ -1659,11 +1659,11 @@ func Main(information library.ServiceInitializationInformation) { message.Respond(library.Success, authLibrary.OAuthResponse{ AppID: appId, SecretKey: secret, - }) + }, information) case 2: // A service would like to have the public key // Send it to them - message.Respond(library.Success, publicKey) + message.Respond(library.Success, publicKey, information) } } }() diff --git a/services-src/storage/main.go b/services-src/storage/main.go index 8c1f2f0..c4247d3 100644 --- a/services-src/storage/main.go +++ b/services-src/storage/main.go @@ -31,12 +31,12 @@ var ( loggerService = uuid.MustParse("00000000-0000-0000-0000-000000000002") ) -func logFunc(message string, messageType library.MessageCode, information library.ServiceInitializationInformation) { +func logFunc(message string, messageType library.MessageCode, information *library.ServiceInitializationInformation) { // Log the message to the logger service information.SendISMessage(loggerService, messageType, message) } -func respondError(message library.InterServiceMessage, err error, information library.ServiceInitializationInformation, myFault bool) { +func respondError(message library.InterServiceMessage, err error, information *library.ServiceInitializationInformation, myFault bool) { // Respond with an error message var errCode = library.BadRequest if myFault { @@ -45,7 +45,7 @@ func respondError(message library.InterServiceMessage, err error, information li errCode = library.InternalError } - message.Respond(errCode, err) + message.Respond(errCode, err, information) } func checkUserExists(userID uuid.UUID) bool { @@ -64,7 +64,7 @@ func checkUserExists(userID uuid.UUID) bool { } // addQuota can be used with a negative quota to remove quota from a user -func addQuota(information library.ServiceInitializationInformation, message library.InterServiceMessage) { +func addQuota(information *library.ServiceInitializationInformation, message library.InterServiceMessage) { // Add more quota to a user userID := message.Message.(nucleusLibrary.Quota).User if checkUserExists(userID) { @@ -80,11 +80,11 @@ func addQuota(information library.ServiceInitializationInformation, message libr } // Success - message.Respond(library.Success, nil) + message.Respond(library.Success, nil, information) } // And so does addReserved -func addReserved(information library.ServiceInitializationInformation, message library.InterServiceMessage) { +func addReserved(information *library.ServiceInitializationInformation, message library.InterServiceMessage) { // Add more reserved space to a user userID := message.Message.(nucleusLibrary.Quota).User if checkUserExists(userID) { @@ -118,7 +118,7 @@ func addReserved(information library.ServiceInitializationInformation, message l } // Success - message.Respond(library.Success, nil) + message.Respond(library.Success, nil, information) } func getQuota(userID uuid.UUID) (int64, error) { @@ -131,7 +131,7 @@ func getQuota(userID uuid.UUID) (int64, error) { return quota, nil } -func getUsed(userID uuid.UUID, information library.ServiceInitializationInformation) (int64, error) { +func getUsed(userID uuid.UUID, information *library.ServiceInitializationInformation) (int64, error) { // Get the used space for a user by first getting the reserved space from file storage _, err := os.Stat(filepath.Join(information.Configuration["path"].(string), userID.String())) if os.IsNotExist(err) { @@ -166,7 +166,7 @@ func getUsed(userID uuid.UUID, information library.ServiceInitializationInformat return used + reserved, nil } -func modifyFile(information library.ServiceInitializationInformation, message library.InterServiceMessage) { +func modifyFile(information *library.ServiceInitializationInformation, message library.InterServiceMessage) { // Check if the file already exists path := filepath.Join(information.Configuration["path"].(string), message.Message.(nucleusLibrary.File).User.String(), message.Message.(nucleusLibrary.File).Name) @@ -225,7 +225,7 @@ func modifyFile(information library.ServiceInitializationInformation, message li } } -func getFile(information library.ServiceInitializationInformation, message library.InterServiceMessage) { +func getFile(information *library.ServiceInitializationInformation, message library.InterServiceMessage) { // Check if the file exists path := filepath.Join(information.Configuration["path"].(string), message.Message.(nucleusLibrary.File).User.String(), message.Message.(nucleusLibrary.File).Name) @@ -252,7 +252,7 @@ func getFile(information library.ServiceInitializationInformation, message libra } } -func deleteFile(information library.ServiceInitializationInformation, message library.InterServiceMessage) { +func deleteFile(information *library.ServiceInitializationInformation, message library.InterServiceMessage) { // Check if the file exists path := filepath.Join(information.Configuration["path"].(string), message.Message.(nucleusLibrary.File).User.String(), message.Message.(nucleusLibrary.File).Name) @@ -279,7 +279,7 @@ func deleteFile(information library.ServiceInitializationInformation, message li } // processInterServiceMessages listens for incoming messages and processes them -func processInterServiceMessages(information library.ServiceInitializationInformation) { +func processInterServiceMessages(information *library.ServiceInitializationInformation) { // Listen for incoming messages for { message := information.AcceptMessage() @@ -305,7 +305,7 @@ func processInterServiceMessages(information library.ServiceInitializationInform } } -func Main(information library.ServiceInitializationInformation) { +func Main(information *library.ServiceInitializationInformation) { // Start up the ISM processor information.StartISProcessor()