diff --git a/Go/db/db.go b/Go/db/db.go index bc35df0ad6207cb8cbcb94e1495636979c9c210e..8c3954d3872b909e3f1a0ef64550d4c9bce5e3f4 100644 --- a/Go/db/db.go +++ b/Go/db/db.go @@ -78,7 +78,7 @@ func TestDBConnection() string { } // AddApiKey adds a new API key to Firestore, ensuring it does not already exist for the provided user (UUID). -func AddApiKey(docID, UUID string, key string) error { +func AddApiKey(IP, docID, UUID string, key string) error { ref := Client.Collection(Firestore.ApiKeyCollection) // Reference to the APIKey collection in Firestore. // Query for existing API keys with the same UUID. @@ -105,12 +105,12 @@ func AddApiKey(docID, UUID string, key string) error { return err // Return formatted error if setting the document fails. } - log.Printf("API key %s created successfully.", apiKeys.APIKey) // Log success. - return nil // Return nil error on success. + log.Printf("%s: API key %s created successfully.", IP, apiKeys.APIKey) // Log success. + return nil // Return nil error on success. } // DeleteApiKey deletes an API key from Firestore based on UUID and key value. -func DeleteApiKey(UUID, apiKey string) error { +func DeleteApiKey(IP, UUID, apiKey string) error { ref := Client.Collection(Firestore.ApiKeyCollection) // Reference to the APIKey collection in Firestore. // Query for the API key document based on UUID and key. @@ -138,12 +138,12 @@ func DeleteApiKey(UUID, apiKey string) error { return fmt.Errorf("failed to delete API Key: %v", err) // Return formatted error if delete fails. } - log.Printf("API key %s deleted successfully.", apiKey) // Log success. - return nil // Return nil error on success. + log.Printf("%s: API key %s deleted successfully.", IP, apiKey) // Log success. + return nil // Return nil error on success. } // GetAPIKeyUUID retrieves the UUID associated with a specific API key from Firestore. -func GetAPIKeyUUID(apiKey string) string { +func GetAPIKeyUUID(IP, apiKey string) string { ref := Client.Collection(Firestore.ApiKeyCollection) // Reference to the APIKey collection in Firestore. // Query for the API key document based on the key value. @@ -171,13 +171,13 @@ func GetAPIKeyUUID(apiKey string) string { log.Println("Error getting user:", err) return "" // Return an empty string if user authentication fails. } else { - log.Printf("UUID: %s successfully retrieved from API key: %s.", key.UUID, key.APIKey) + log.Printf("%s: UUID: %s successfully retrieved from API key: %s.", IP, key.UUID, key.APIKey) return key.UUID // Return the UUID on success. } } // AddRegistration adds a new registration document to Firestore. -func AddRegistration(docID string, data *structs.CountryInfoInternal) error { +func AddRegistration(IP, docID string, data *structs.CountryInfoInternal) error { ref := Client.Collection(Firestore.RegistrationCollection) // Reference to the Registration collection. // Set the registration document in Firestore with the given ID and data. @@ -193,12 +193,12 @@ func AddRegistration(docID string, data *structs.CountryInfoInternal) error { return err // Return error if the document set operation fails. } - log.Printf("Registration documents %s created successfully.", data.ID) + log.Printf("%s: Registration documents %s created successfully.", IP, data.ID) return nil // Return nil if the addition is successful. } // GetRegistrations retrieves all registration documents for a given user (UUID) from Firestore. -func GetRegistrations(UUID string) ([]*structs.CountryInfoInternal, error) { +func GetRegistrations(IP, UUID string) ([]*structs.CountryInfoInternal, error) { ref := Client.Collection(Firestore.RegistrationCollection) // Reference to the Registration collection. // Query and retrieve all documents where 'UUID' matches, ordered by 'Lastchange' descending. @@ -216,12 +216,12 @@ func GetRegistrations(UUID string) ([]*structs.CountryInfoInternal, error) { } cis = append(cis, ci) // Append the parsed document to the slice. } - log.Printf("Registration documents for user: %s retrieved successfully.", UUID) + log.Printf("%s: Registration documents for user: %s retrieved successfully.", IP, UUID) return cis, nil // Return the slice of documents. } // GetSpecificRegistration retrieves a specific registration document by ID and UUID from Firestore. -func GetSpecificRegistration(ID, UUID string) (*structs.CountryInfoInternal, error) { +func GetSpecificRegistration(IP, ID, UUID string) (*structs.CountryInfoInternal, error) { ref := Client.Collection(Firestore.RegistrationCollection) // Reference to the Registration collection. // Query for the specific document with the given 'ID' and 'UUID'. @@ -241,7 +241,7 @@ func GetSpecificRegistration(ID, UUID string) (*structs.CountryInfoInternal, err if err := doc.DataTo(&ci); err != nil { return nil, err // Return error if parsing the document fails. } - log.Printf("Registration document %s retrieved successfully.", ci.ID) + log.Printf("%s: Registration document %s retrieved successfully.", IP, ci.ID) return ci, nil // Return the parsed document. } @@ -249,7 +249,7 @@ func GetSpecificRegistration(ID, UUID string) (*structs.CountryInfoInternal, err } // UpdateRegistration updates a specific registration document by ID and UUID in Firestore. -func UpdateRegistration(ID, UUID string, data *structs.CountryInfoInternal) error { +func UpdateRegistration(IP, ID, UUID string, data *structs.CountryInfoInternal) error { ref := Client.Collection(Firestore.RegistrationCollection) // Reference to the Registration collection. // Query for the specific document to update. @@ -276,7 +276,7 @@ func UpdateRegistration(ID, UUID string, data *structs.CountryInfoInternal) erro if err != nil { return err // Return error if the document update operation fails. } - log.Printf("Registration document %s patched successfully.", doc.Ref.ID) + log.Printf("%s: Registration document %s patched successfully.", IP, doc.Ref.ID) return nil // Return nil error if the update is successful. } @@ -284,7 +284,7 @@ func UpdateRegistration(ID, UUID string, data *structs.CountryInfoInternal) erro } // DeleteRegistration deletes a specific registration document by ID and UUID from Firestore. -func DeleteRegistration(ID, UUID string) error { +func DeleteRegistration(IP, ID, UUID string) error { ref := Client.Collection(Firestore.RegistrationCollection) // Reference to the Registration collection. // Query for the specific document to delete. @@ -312,12 +312,12 @@ func DeleteRegistration(ID, UUID string) error { return fmt.Errorf("failed to delete document: %v", err) // Return formatted error if delete fails. } - log.Printf("Registration document %s deleted successfully\n", docID) + log.Printf("%s: Registration document %s deleted successfully\n", IP, docID) return nil // Return nil if the deletion is successful. } // AddWebhook creates a new webhook entry in Firestore. -func AddWebhook(docID string, webhook *structs.WebhookInternal) error { +func AddWebhook(IP, docID string, webhook *structs.WebhookInternal) error { ref := Client.Collection(Firestore.WebhookCollection) // Reference to the Webhook collection in Firestore. // Set the webhook document with the provided ID and data. @@ -326,8 +326,8 @@ func AddWebhook(docID string, webhook *structs.WebhookInternal) error { return err // Return error if addition fails. } - log.Printf("Webhook %s created successfully.", webhook.ID) // Log success. - return nil // Return nil error on successful addition. + log.Printf("%s: Webhook %s created successfully.", IP, webhook.ID) // Log success. + return nil // Return nil error on successful addition. } // GetAllWebhooks retrieves all webhook entries from Firestore. @@ -355,7 +355,7 @@ func GetAllWebhooks() ([]structs.WebhookInternal, error) { } // GetWebhooksUser retrieves all webhook entries for a specific user (UUID) from Firestore. -func GetWebhooksUser(UUID string) ([]structs.WebhookResponse, error) { +func GetWebhooksUser(IP, UUID string) ([]structs.WebhookResponse, error) { ref := Client.Collection(Firestore.WebhookCollection) // Reference to the Webhook collection. // Query and retrieve all documents from the webhook collection where 'UUID' matches the provided UUID. @@ -374,12 +374,12 @@ func GetWebhooksUser(UUID string) ([]structs.WebhookResponse, error) { webhooks = append(webhooks, webhook) // Append the parsed document to the slice. } - log.Printf("Webhooks retrieved successfully for user: %s.", UUID) // Log success. - return webhooks, nil // Return the slice of webhook documents for the user. + log.Printf("%s: Webhooks retrieved successfully for user: %s.", IP, UUID) // Log success. + return webhooks, nil // Return the slice of webhook documents for the user. } // GetSpecificWebhook retrieves a specific webhook entry by ID and UUID from Firestore. -func GetSpecificWebhook(ID, UUID string) (*structs.WebhookResponse, error) { +func GetSpecificWebhook(IP, ID, UUID string) (*structs.WebhookResponse, error) { ref := Client.Collection(Firestore.WebhookCollection) // Reference to the Webhook collection. // Query for the specific document with the given 'ID' and 'UUID'. @@ -400,15 +400,15 @@ func GetSpecificWebhook(ID, UUID string) (*structs.WebhookResponse, error) { return nil, err // Return error if parsing the document fails. } - log.Printf("Webhook %s retrieved successfully.", webhook.ID) // Log success. - return webhook, nil // Return the parsed document. + log.Printf("%s: Webhook %s retrieved successfully.", IP, webhook.ID) // Log success. + return webhook, nil // Return the parsed document. } return nil, errors.New("no document with that ID was found") // Return error if no document is found. } // DeleteWebhook deletes a specific webhook entry by ID and UUID from Firestore. -func DeleteWebhook(ID, UUID string) error { +func DeleteWebhook(IP, ID, UUID string) error { ref := Client.Collection(Firestore.WebhookCollection) // Reference to the Webhook collection. // Query for the specific document to delete. @@ -437,6 +437,6 @@ func DeleteWebhook(ID, UUID string) error { return fmt.Errorf("failed to delete document: %v", err) // Return formatted error if delete fails. } - log.Printf("Webhook %s deleted successfully.", docID) // Log success. - return nil // Return nil error on successful operation. + log.Printf("%s: Webhook %s deleted successfully.", IP, docID) // Log success. + return nil // Return nil error on successful operation. } diff --git a/Go/internal/handlers/endpoint/dashboard/dashboards_id_handler.go b/Go/internal/handlers/endpoint/dashboard/dashboards_id_handler.go index 903c63e21b7aefa3666929620a877ad17145a19c..443c5d76c1fb36a10fa2b67222085afd0ed08f77 100644 --- a/Go/internal/handlers/endpoint/dashboard/dashboards_id_handler.go +++ b/Go/internal/handlers/endpoint/dashboard/dashboards_id_handler.go @@ -43,8 +43,8 @@ func handleDashboardGetRequest(w http.ResponseWriter, r *http.Request) { http.Error(w, ProvideAPI, http.StatusUnauthorized) return } - UUID := db.GetAPIKeyUUID(token) // Retrieve UUID associated with API token. - if UUID == "" { // Check if UUID is retrieved. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Retrieve UUID associated with API token. + if UUID == "" { // Check if UUID is retrieved. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.DashboardsID) err := fmt.Sprintf(APINotAccepted) http.Error(w, err, http.StatusNotAcceptable) @@ -56,7 +56,7 @@ func handleDashboardGetRequest(w http.ResponseWriter, r *http.Request) { return } - reg, err := db.GetSpecificRegistration(ID, UUID) // Retrieve registration by ID for user (UUID). + reg, err := db.GetSpecificRegistration(r.RemoteAddr, ID, UUID) // Retrieve registration by ID for user (UUID). if err != nil { log.Printf("%s: Error getting registration: %v", r.RemoteAddr, err) err := fmt.Sprintf("Dashboard doesn't exist: %v", err) diff --git a/Go/internal/handlers/endpoint/dashboard/notifications_handler.go b/Go/internal/handlers/endpoint/dashboard/notifications_handler.go index f5464e14ee32e3fdb4f7273770af7c41567ab2b5..bb84352b2be261787d44cf03ce64b997b6c2d70c 100644 --- a/Go/internal/handlers/endpoint/dashboard/notifications_handler.go +++ b/Go/internal/handlers/endpoint/dashboard/notifications_handler.go @@ -37,8 +37,8 @@ func handleNotifPostRequest(w http.ResponseWriter, r *http.Request) { http.Error(w, ProvideAPI, http.StatusUnauthorized) return } - UUID := db.GetAPIKeyUUID(token) // Retrieve UUID associated with the API token. - if UUID == "" { // Check if UUID is valid. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Retrieve UUID associated with the API token. + if UUID == "" { // Check if UUID is valid. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.Notifications) err := fmt.Sprintf(APINotAccepted) http.Error(w, err, http.StatusNotAcceptable) @@ -65,14 +65,14 @@ func handleNotifPostRequest(w http.ResponseWriter, r *http.Request) { webhook.ID = ID webhook.UUID = UUID - err := db.AddWebhook(UDID, webhook) // Add the webhook to the database. + err := db.AddWebhook(r.RemoteAddr, UDID, webhook) // Add the webhook to the database. if err != nil { log.Println("Error saving data to database" + err.Error()) http.Error(w, "Error storing data in database", http.StatusInternalServerError) return } - hook, err := db.GetSpecificWebhook(ID, UUID) // Retrieve the newly added webhook to confirm its addition. + hook, err := db.GetSpecificWebhook(r.RemoteAddr, ID, UUID) // Retrieve the newly added webhook to confirm its addition. if err != nil { log.Print("Error getting document from database: ", err) http.Error(w, "Error confirming data added to database", http.StatusInternalServerError) @@ -104,14 +104,14 @@ func handleNotifGetAllRequest(w http.ResponseWriter, r *http.Request) { http.Error(w, ProvideAPI, http.StatusUnauthorized) return } - UUID := db.GetAPIKeyUUID(token) // Retrieve UUID associated with the API token. - if UUID == "" { // Check if UUID is valid. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Retrieve UUID associated with the API token. + if UUID == "" { // Check if UUID is valid. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.Notifications) err := fmt.Sprintf(APINotAccepted) http.Error(w, err, http.StatusNotAcceptable) return } - regs, err := db.GetWebhooksUser(UUID) // Retrieve all webhooks associated with the user (UUID). + regs, err := db.GetWebhooksUser(r.RemoteAddr, UUID) // Retrieve all webhooks associated with the user (UUID). if err != nil { log.Printf("%s: Error retrieving webhooks from database: %v", r.RemoteAddr, err) errmsg := fmt.Sprint("Error retrieving webhooks from database: ", err) diff --git a/Go/internal/handlers/endpoint/dashboard/notifications_id_handler.go b/Go/internal/handlers/endpoint/dashboard/notifications_id_handler.go index bff6ee50c1ec1c266a14eae0cf6df62de3350351..bec3c0e25e44c0fc768da1554ff7ad2bbccfa275 100644 --- a/Go/internal/handlers/endpoint/dashboard/notifications_id_handler.go +++ b/Go/internal/handlers/endpoint/dashboard/notifications_id_handler.go @@ -36,8 +36,8 @@ func handleNotifGetRequest(w http.ResponseWriter, r *http.Request) { http.Error(w, ProvideAPI, http.StatusUnauthorized) return } - UUID := db.GetAPIKeyUUID(token) // Retrieve UUID associated with the API token. - if UUID == "" { // Check if UUID is valid. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Retrieve UUID associated with the API token. + if UUID == "" { // Check if UUID is valid. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.NotificationsID) err := fmt.Sprintf(APINotAccepted) http.Error(w, err, http.StatusNotAcceptable) @@ -49,7 +49,7 @@ func handleNotifGetRequest(w http.ResponseWriter, r *http.Request) { return } - hook, err := db.GetSpecificWebhook(ID, UUID) // Retrieve the specific webhook by ID and UUID. + hook, err := db.GetSpecificWebhook(r.RemoteAddr, ID, UUID) // Retrieve the specific webhook by ID and UUID. if err != nil { log.Printf("%s: Error getting webhook from database: %v", r.RemoteAddr, err) err := fmt.Sprintf("Error getting webhook from database: %v", err) @@ -79,8 +79,8 @@ func handleNotifDeleteRequest(w http.ResponseWriter, r *http.Request) { http.Error(w, ProvideAPI, http.StatusUnauthorized) return } - UUID := db.GetAPIKeyUUID(token) // Retrieve UUID associated with the API token. - if UUID == "" { // Check if UUID is valid. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Retrieve UUID associated with the API token. + if UUID == "" { // Check if UUID is valid. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.NotificationsID) err := fmt.Sprintf(APINotAccepted) http.Error(w, err, http.StatusNotAcceptable) @@ -92,7 +92,7 @@ func handleNotifDeleteRequest(w http.ResponseWriter, r *http.Request) { return } - err := db.DeleteWebhook(ID, UUID) // Delete the specific webhook by ID and UUID from the database. + err := db.DeleteWebhook(r.RemoteAddr, ID, UUID) // Delete the specific webhook by ID and UUID from the database. if err != nil { log.Printf(" %s: Error deleting data from database: %v", r.RemoteAddr, err) err := fmt.Sprintf("Error deleting data from database: %v", err) diff --git a/Go/internal/handlers/endpoint/dashboard/registrations_handler.go b/Go/internal/handlers/endpoint/dashboard/registrations_handler.go index e5cab6ae2a41cd204d9d0439d312b5ca6b422fc4..157e9a59fcc59baa49ec7b6c0ab9aba5e909db25 100644 --- a/Go/internal/handlers/endpoint/dashboard/registrations_handler.go +++ b/Go/internal/handlers/endpoint/dashboard/registrations_handler.go @@ -62,8 +62,8 @@ func handleRegPostRequest(w http.ResponseWriter, r *http.Request) { http.Error(w, ProvideAPI, http.StatusUnauthorized) return } - UUID := db.GetAPIKeyUUID(token) // Retrieve the UUID for the API key. - if UUID == "" { // Validate UUID presence. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Retrieve the UUID for the API key. + if UUID == "" { // Validate UUID presence. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.Registrations) err := fmt.Sprintf(APINotAccepted) http.Error(w, err, http.StatusNotAcceptable) @@ -91,14 +91,14 @@ func handleRegPostRequest(w http.ResponseWriter, r *http.Request) { ci.ID = URID ci.UUID = UUID - err = db.AddRegistration(UDID, ci) // Add Registration to the Database. + err = db.AddRegistration(r.RemoteAddr, UDID, ci) // Add Registration to the Database. if err != nil { log.Println("Error saving data to database" + err.Error()) http.Error(w, "Error storing data in database", http.StatusInternalServerError) return } - reg, err := db.GetSpecificRegistration(URID, UUID) // Retrieve specific registration details. + reg, err := db.GetSpecificRegistration(r.RemoteAddr, URID, UUID) // Retrieve specific registration details. if err != nil { log.Print("Error getting document from database: ", err) http.Error(w, "Error confirming data added to database", http.StatusInternalServerError) @@ -140,14 +140,14 @@ func handleRegGetAllRequest(w http.ResponseWriter, r *http.Request) { http.Error(w, ProvideAPI, http.StatusUnauthorized) return } - UUID := db.GetAPIKeyUUID(token) // Extract the UUID parameter from the API token. - if UUID == "" { // Validate UUID presence. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Extract the UUID parameter from the API token. + if UUID == "" { // Validate UUID presence. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.Registrations) err := fmt.Sprintf(APINotAccepted) http.Error(w, err, http.StatusNotAcceptable) return } - regs, err := db.GetRegistrations(UUID) // Retrieve the user's Registrations. + regs, err := db.GetRegistrations(r.RemoteAddr, UUID) // Retrieve the user's Registrations. if err != nil { log.Printf("%s: Error retrieving documents from database: %s", r.RemoteAddr, err) errmsg := fmt.Sprint("Error retrieving documents from database: ", err) diff --git a/Go/internal/handlers/endpoint/dashboard/registrations_id_handler.go b/Go/internal/handlers/endpoint/dashboard/registrations_id_handler.go index 2ae36ac6e33d3c049a79937dd1b0001fef167f9c..ba1a6b033848ca9df2e8d91e4dd72dc356587613 100644 --- a/Go/internal/handlers/endpoint/dashboard/registrations_id_handler.go +++ b/Go/internal/handlers/endpoint/dashboard/registrations_id_handler.go @@ -50,8 +50,8 @@ func handleRegGetRequest(w http.ResponseWriter, r *http.Request) { http.Error(w, ProvideAPI, http.StatusUnauthorized) return } - UUID := db.GetAPIKeyUUID(token) // Retrieve the UUID for the API key. - if UUID == "" { // Validate UUID presence. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Retrieve the UUID for the API key. + if UUID == "" { // Validate UUID presence. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.RegistrationsID) err := fmt.Sprintf(APINotAccepted) http.Error(w, err, http.StatusNotAcceptable) @@ -63,7 +63,7 @@ func handleRegGetRequest(w http.ResponseWriter, r *http.Request) { return } - reg, err := db.GetSpecificRegistration(ID, UUID) // Retrieve registration data from the database. + reg, err := db.GetSpecificRegistration(r.RemoteAddr, ID, UUID) // Retrieve registration data from the database. if err != nil { log.Printf(RegistrationRetrivalError, r.RemoteAddr, err) http.Error(w, "Error retrieving data from database", http.StatusNotFound) @@ -101,8 +101,8 @@ func handleRegPatchRequest(w http.ResponseWriter, r *http.Request) { http.Error(w, ProvideAPI, http.StatusUnauthorized) return } - UUID := db.GetAPIKeyUUID(token) // Retrieve the UUID for the API key. - if UUID == "" { // Validate UUID presence. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Retrieve the UUID for the API key. + if UUID == "" { // Validate UUID presence. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.RegistrationsID) err := fmt.Sprintf(APINotAccepted) http.Error(w, err, http.StatusNotAcceptable) @@ -137,7 +137,7 @@ func handleRegPatchRequest(w http.ResponseWriter, r *http.Request) { return } - err = db.UpdateRegistration(ID, UUID, ci) // Update the registration in the database. + err = db.UpdateRegistration(r.RemoteAddr, ID, UUID, ci) // Update the registration in the database. if err != nil { log.Printf("%s: Error saving patched data to database: %v", r.RemoteAddr, err) err := fmt.Sprintf("Error saving patched data to database: %v", err) @@ -145,7 +145,7 @@ func handleRegPatchRequest(w http.ResponseWriter, r *http.Request) { return } - reg, err := db.GetSpecificRegistration(ID, UUID) // Retrieve the updated registration. + reg, err := db.GetSpecificRegistration(r.RemoteAddr, ID, UUID) // Retrieve the updated registration. if err != nil { log.Printf(RegistrationRetrivalError, r.RemoteAddr, err) err := fmt.Sprint("Error retrieving updated document: ", err) @@ -179,7 +179,7 @@ func handleRegPatchRequest(w http.ResponseWriter, r *http.Request) { // patchCountryInformation updates the country information based on the provided patch data. func patchCountryInformation(r *http.Request, ID, UUID string) (*structs.CountryInfoInternal, error, int) { - reg, err := db.GetSpecificRegistration(ID, UUID) // Retrieve the specific registration. + reg, err := db.GetSpecificRegistration(r.RemoteAddr, ID, UUID) // Retrieve the specific registration. if err != nil { log.Printf(RegistrationRetrivalError, r.RemoteAddr, err) return nil, err, http.StatusNotFound @@ -275,8 +275,8 @@ func handleRegDeleteRequest(w http.ResponseWriter, r *http.Request) { http.Error(w, ProvideAPI, http.StatusUnauthorized) return } - UUID := db.GetAPIKeyUUID(token) // Retrieve the UUID for the API key. - if UUID == "" { // Validate UUID presence. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Retrieve the UUID for the API key. + if UUID == "" { // Validate UUID presence. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.RegistrationsID) err := fmt.Sprintf(APINotAccepted) http.Error(w, err, http.StatusNotAcceptable) @@ -288,7 +288,7 @@ func handleRegDeleteRequest(w http.ResponseWriter, r *http.Request) { return } - reg, err := db.GetSpecificRegistration(ID, UUID) // Retrieve the specific registration to be deleted. + reg, err := db.GetSpecificRegistration(r.RemoteAddr, ID, UUID) // Retrieve the specific registration to be deleted. if err != nil { log.Printf(RegistrationRetrivalError, r.RemoteAddr, err) err := fmt.Sprint("Error getting registration: ", err) @@ -296,7 +296,7 @@ func handleRegDeleteRequest(w http.ResponseWriter, r *http.Request) { return } - err = db.DeleteRegistration(ID, UUID) // Delete the registration from the database. + err = db.DeleteRegistration(r.RemoteAddr, ID, UUID) // Delete the registration from the database. if err != nil { log.Printf("%s: Error deleting registration from database: %v", r.RemoteAddr, err) err := fmt.Sprintf("Error deleting registration from database: %v", err) diff --git a/Go/internal/handlers/endpoint/dashboard/status_handler.go b/Go/internal/handlers/endpoint/dashboard/status_handler.go index e51190b53a292b028f1c6178c448b80bb2789e01..d9c47d1bdaa3b9d24f1f3dc0c605f2fb4db897de 100644 --- a/Go/internal/handlers/endpoint/dashboard/status_handler.go +++ b/Go/internal/handlers/endpoint/dashboard/status_handler.go @@ -63,14 +63,14 @@ func handleStatusGetRequest(w http.ResponseWriter, r *http.Request) { return } - UUID := db.GetAPIKeyUUID(token) // Retrieve the UUID associated with the API token. - if UUID == "" { // Validate UUID presence. + UUID := db.GetAPIKeyUUID(r.RemoteAddr, token) // Retrieve the UUID associated with the API token. + if UUID == "" { // Validate UUID presence. log.Printf(constants.ClientConnectUnauthorized, r.RemoteAddr, r.Method, Endpoints.Status) http.Error(w, "API key not accepted", http.StatusNotAcceptable) return } - webhooksUser, err := db.GetWebhooksUser(UUID) // Retrieve user data associated with webhooks. + webhooksUser, err := db.GetWebhooksUser(r.RemoteAddr, UUID) // Retrieve user data associated with webhooks. if err != nil { log.Printf("%s: Error retrieving user's webhooks: %v", r.RemoteAddr, err) http.Error(w, "Internal Server Error", http.StatusInternalServerError) diff --git a/Go/internal/handlers/endpoint/util/apikey_handler.go b/Go/internal/handlers/endpoint/util/apikey_handler.go index 1b2ee78b6d0aaf824a781552741315c2fd066b0b..0c822daf12d2ee165fa7c565a936b382dbe7d91b 100644 --- a/Go/internal/handlers/endpoint/util/apikey_handler.go +++ b/Go/internal/handlers/endpoint/util/apikey_handler.go @@ -52,7 +52,7 @@ func handleApiKeyDeleteRequest(w http.ResponseWriter, r *http.Request) { return } - err = db.DeleteApiKey(UUID, token) // Attempt to delete the API key. + err = db.DeleteApiKey(r.RemoteAddr, UUID, token) // Attempt to delete the API key. if err != nil { log.Printf("%s: Error deleting API Key: %v", r.RemoteAddr, err) http.Error(w, err.Error(), http.StatusInternalServerError) // Respond with internal server error if deletion fails. @@ -81,7 +81,7 @@ func handleApiKeyGetRequest(w http.ResponseWriter, r *http.Request) { return } - err = db.AddApiKey(UDID, UUID, key) // Attempt to add the new API key to the database. + err = db.AddApiKey(r.RemoteAddr, UDID, UUID, key) // Attempt to add the new API key to the database. if err != nil { log.Printf("%s: Error creating API Key: %v", r.RemoteAddr, err) errorMessage := fmt.Sprintf("Error creating API Key: %v", err) diff --git a/Go/internal/handlers/endpoint/util/user_register_handler.go b/Go/internal/handlers/endpoint/util/user_register_handler.go index 5de96c627ad5dd6834fddd5ef748bb16f1558c89..e7202a1c4da8d453eb3dffcc6b3560e57c99d153 100644 --- a/Go/internal/handlers/endpoint/util/user_register_handler.go +++ b/Go/internal/handlers/endpoint/util/user_register_handler.go @@ -72,7 +72,7 @@ func registerUser(w http.ResponseWriter, r *http.Request) { UDID := _func.GenerateUID(constants.DocIdLength) // Generate a unique document ID. key := _func.GenerateAPIKey(constants.ApiKeyLength) // Generate a new API key. - err = db.AddApiKey(UDID, u.UID, key) // Store the new API key in the database. + err = db.AddApiKey(r.RemoteAddr, UDID, u.UID, key) // Store the new API key in the database. if err != nil { log.Printf("%s Error saving API Key: %v\n", r.RemoteAddr, err) // Log the error. http.Error(w, ISE, http.StatusInternalServerError) // Report API key storage error.