move requestclient credentials to env
parent
21d8d18ecc
commit
e75988106a
|
@ -10,12 +10,13 @@ import (
|
|||
var Cfg Config
|
||||
|
||||
type Config struct {
|
||||
Debug bool
|
||||
ColorizedOutput bool
|
||||
Host string
|
||||
Port string
|
||||
FolderPaths FolderPaths
|
||||
MariaDB MariaDB
|
||||
Debug bool
|
||||
ColorizedOutput bool
|
||||
Host string
|
||||
Port string
|
||||
FolderPaths FolderPaths
|
||||
MariaDB MariaDB
|
||||
InvexAPI InvexAPI
|
||||
}
|
||||
|
||||
type FolderPaths struct {
|
||||
|
@ -34,6 +35,11 @@ type MariaDB struct {
|
|||
DatabaseName string
|
||||
}
|
||||
|
||||
type InvexAPI struct {
|
||||
Base string
|
||||
Token string
|
||||
}
|
||||
|
||||
func LoadConfig() {
|
||||
// used to determine server was startet in docker or not
|
||||
if os.Getenv("DOCKER") == "" {
|
||||
|
@ -60,6 +66,11 @@ func LoadConfig() {
|
|||
Port: os.Getenv("MARIADB_PORT"),
|
||||
Username: os.Getenv("MARIADB_USERNAME"),
|
||||
Password: os.Getenv("MARIADB_PASSWORD"),
|
||||
DatabaseName: os.Getenv("MARIADB_DATABASE_NAME")},
|
||||
DatabaseName: os.Getenv("MARIADB_DATABASE_NAME"),
|
||||
},
|
||||
InvexAPI: InvexAPI{
|
||||
Base: os.Getenv("INVEX_API_BASE"),
|
||||
Token: os.Getenv("INVEX_API_TOKEN"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ func GetEquipmentDocumentations(stockItemId string, query structs.PageQuery, c *
|
|||
if len(documentations) == 0 {
|
||||
// there are no documentations for this equipment on the our database
|
||||
// so there will be checked on invex if the stock item exists
|
||||
statusCode, _, err = requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/"+stockItemId+"/")
|
||||
statusCode, _, err = requestclient.InvexApiRequestClient(fiber.MethodGet, config.Cfg.InvexAPI.Base+"/api/stock/"+stockItemId+"/")
|
||||
|
||||
if err != nil {
|
||||
log.Error().Msgf("Invex api request error: %s", err)
|
||||
|
@ -264,7 +264,7 @@ func isInList(fileName string, notes []Notes) bool {
|
|||
// fetching the thumbnail from the invex server and sending it back to the client
|
||||
func GetEquipmentInvexThumbnail(c *fiber.Ctx, stockItemId string) error {
|
||||
// first request to /api/stock/:stockItemId/ to get the thumbnail url
|
||||
_, body, err := requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/"+stockItemId+"/")
|
||||
_, body, err := requestclient.InvexApiRequestClient(fiber.MethodGet, config.Cfg.InvexAPI.Base+"/api/stock/"+stockItemId+"/")
|
||||
|
||||
if err != nil {
|
||||
log.Error().Msgf("Invex api request error: %s", err)
|
||||
|
@ -283,7 +283,7 @@ func GetEquipmentInvexThumbnail(c *fiber.Ctx, stockItemId string) error {
|
|||
thumbnail := partDetail["thumbnail"].(string)
|
||||
|
||||
// second request to /media/part_images/:thumbnail to get the thumbnail image
|
||||
_, body, err = requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.Base+"/"+thumbnail)
|
||||
_, body, err = requestclient.InvexApiRequestClient(fiber.MethodGet, config.Cfg.InvexAPI.Base+"/"+thumbnail)
|
||||
|
||||
if err != nil {
|
||||
log.Error().Msgf("Invex api request error: %s", err)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package requestclient
|
||||
|
||||
import (
|
||||
"jannex/admin-dashboard-backend/modules/config"
|
||||
"jannex/admin-dashboard-backend/modules/logger"
|
||||
"strconv"
|
||||
|
||||
|
@ -8,14 +9,13 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
const Base = "https://inv.ex.umbach.dev"
|
||||
const ApiBase = Base + "/api"
|
||||
const ApiToken = "1367f15d21935e4eb540f897946fb5cd98485c3f"
|
||||
//const Base = "https://inv.ex.umbach.dev"
|
||||
//const ApiBase = Base + "/api"
|
||||
|
||||
func InvexApiRequestClient(requestMethod string, url string) (statusCode int, body []byte, err error) {
|
||||
a := fiber.AcquireAgent()
|
||||
|
||||
a.Add("Authorization", "Token "+ApiToken)
|
||||
a.Add("Authorization", "Token "+config.Cfg.InvexAPI.Token)
|
||||
|
||||
req := a.Request()
|
||||
req.Header.SetMethod(requestMethod)
|
||||
|
|
|
@ -52,50 +52,50 @@ var (
|
|||
|
||||
// commands sent to web clients
|
||||
const (
|
||||
SentCmdInitUserSocketConnection = 1
|
||||
SentCmdUpdateConnectedUsers = 2
|
||||
SentCmdNewGroupTaskStarted = 3
|
||||
SentCmdNewGroupTaskStep = 4
|
||||
SentCmdUpdateGroupTaskStep = 5
|
||||
SentCmdUpdateGroupTask = 6
|
||||
SentCmdReloadingGroupTasks = 7
|
||||
SentCmdGroupTasksReloaded = 8
|
||||
SentCmdUpdateUserSessions = 9
|
||||
SentCmdUpdateAllUsersUserAvatar = 10
|
||||
SentCmdNewScanner = 11
|
||||
SentCmdDeleteScanner = 12
|
||||
SentCmdUpdateScannerUsedBy = 13
|
||||
SentCmdScanResult = 14
|
||||
SentCmdUpdateScannerLastUsed = 15
|
||||
SentCmdTaskLocked = 16
|
||||
SentCmdTaskUnlocked = 17
|
||||
SentCmdUserProfileUpdated = 18
|
||||
SentCmdAdminAreaNewRoleCreated = 19
|
||||
SentCmdAdminAreaRoleUpdated = 20
|
||||
SentCmdAdminAreaUpdateRoleSortingOrder = 21
|
||||
SentCmdAdminAreaRoleDeleted = 22
|
||||
SentCmdAllUsersUserRoleUpdated = 23
|
||||
SentCmdRolePermissionsUpdated = 24
|
||||
SentCmdErrorNoPermissions = 25
|
||||
SentCmdAllUsersNewUserCreated = 26
|
||||
SentCmdAllUsersUserDeleted = 27
|
||||
SentCmdAllUsersUserDeactivation = 28
|
||||
SentCmdGroupTasksCategoryGroupChanges = 29
|
||||
SentCmdNewUserApiKeyCreated = 30
|
||||
SentCmdDeletedUserApiKey = 31
|
||||
SentCmdNewApiKeyUsageCount = 32
|
||||
SentCmdInstallingPythonPackages = 33
|
||||
SentCmdInstallingPythonPackagesFailed = 34
|
||||
SentCmdInstallingPythonPackagesFinished = 35
|
||||
SentCmdInstallingGlobalPythonPackages = 36
|
||||
SentCmdInstallingGlobalPythonPackagesFailed = 37
|
||||
SentCmdInstallingGlobalPythonPackagesFinished = 38
|
||||
SentCmdUpdateUsers = 39
|
||||
SentCmdNewNotification = 41
|
||||
SentCmdAllNotificationsDeleted = 42
|
||||
SentCmdOneNotificationDeleted = 43
|
||||
SentCmdAdminAreaManageCheckedForAvailableCategories = 44
|
||||
SentCmdAdminAreaManageLogManagerServerConnectionAdded = 45
|
||||
SentCmdInitUserSocketConnection = 1
|
||||
SentCmdUpdateConnectedUsers = 2
|
||||
SentCmdNewGroupTaskStarted = 3
|
||||
SentCmdNewGroupTaskStep = 4
|
||||
SentCmdUpdateGroupTaskStep = 5
|
||||
SentCmdUpdateGroupTask = 6
|
||||
SentCmdReloadingGroupTasks = 7
|
||||
SentCmdGroupTasksReloaded = 8
|
||||
SentCmdUpdateUserSessions = 9
|
||||
SentCmdUpdateAllUsersUserAvatar = 10
|
||||
SentCmdNewScanner = 11
|
||||
SentCmdDeleteScanner = 12
|
||||
SentCmdUpdateScannerUsedBy = 13
|
||||
SentCmdScanResult = 14
|
||||
SentCmdUpdateScannerLastUsed = 15
|
||||
SentCmdTaskLocked = 16
|
||||
SentCmdTaskUnlocked = 17
|
||||
SentCmdUserProfileUpdated = 18
|
||||
SentCmdAdminAreaNewRoleCreated = 19
|
||||
SentCmdAdminAreaRoleUpdated = 20
|
||||
SentCmdAdminAreaUpdateRoleSortingOrder = 21
|
||||
SentCmdAdminAreaRoleDeleted = 22
|
||||
SentCmdAllUsersUserRoleUpdated = 23
|
||||
SentCmdRolePermissionsUpdated = 24
|
||||
SentCmdErrorNoPermissions = 25
|
||||
SentCmdAllUsersNewUserCreated = 26
|
||||
SentCmdAllUsersUserDeleted = 27
|
||||
SentCmdAllUsersUserDeactivation = 28
|
||||
SentCmdGroupTasksCategoryGroupChanges = 29
|
||||
SentCmdNewUserApiKeyCreated = 30
|
||||
SentCmdDeletedUserApiKey = 31
|
||||
SentCmdNewApiKeyUsageCount = 32
|
||||
SentCmdInstallingPythonPackages = 33
|
||||
SentCmdInstallingPythonPackagesFailed = 34
|
||||
SentCmdInstallingPythonPackagesFinished = 35
|
||||
SentCmdInstallingGlobalPythonPackages = 36
|
||||
SentCmdInstallingGlobalPythonPackagesFailed = 37
|
||||
SentCmdInstallingGlobalPythonPackagesFinished = 38
|
||||
SentCmdUpdateUsers = 39
|
||||
SentCmdNewNotification = 41
|
||||
SentCmdAllNotificationsDeleted = 42
|
||||
SentCmdOneNotificationDeleted = 43
|
||||
SentCmdAdminAreaManageCheckedForAvailableCategories = 44
|
||||
SentCmdAdminAreaManageLogManagerServerConnectionAdded = 45
|
||||
SentCmdAdminAreaManageLogManagerServerConnectionRemoved = 46
|
||||
)
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package machines
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"jannex/admin-dashboard-backend/modules/config"
|
||||
"jannex/admin-dashboard-backend/modules/requestclient"
|
||||
"jannex/admin-dashboard-backend/modules/structs"
|
||||
"jannex/admin-dashboard-backend/modules/utils"
|
||||
|
@ -30,11 +31,7 @@ func GetMachines(c *fiber.Ctx) error {
|
|||
return c.SendStatus(fiber.StatusBadRequest)
|
||||
}
|
||||
|
||||
log.Info().Msgf("body %v", body)
|
||||
|
||||
statusCode, reqBody, err := requestclient.InvexApiRequestClient(fiber.MethodGet, requestclient.ApiBase+"/stock/?search=&offset=0&limit=50&location="+strconv.Itoa(body.Location)+"&part_detail=true&in_stock=0")
|
||||
|
||||
log.Info().Msgf("statuscode %v", statusCode)
|
||||
_, reqBody, err := requestclient.InvexApiRequestClient(fiber.MethodGet, config.Cfg.InvexAPI.Base+"/api/stock/?search=&offset=0&limit=50&location="+strconv.Itoa(body.Location)+"&part_detail=true&in_stock=0")
|
||||
|
||||
if err != nil {
|
||||
log.Error().Msgf("Invex api request error: %s", err)
|
||||
|
|
Loading…
Reference in New Issue