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