move requestclient credentials to env
parent
21d8d18ecc
commit
e75988106a
|
@ -16,6 +16,7 @@ type Config struct {
|
||||||
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)
|
||||||
|
|
|
@ -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"
|
||||||
|
@ -30,11 +31,7 @@ func GetMachines(c *fiber.Ctx) error {
|
||||||
return c.SendStatus(fiber.StatusBadRequest)
|
return c.SendStatus(fiber.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Msgf("body %v", body)
|
_, 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")
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Msgf("Invex api request error: %s", err)
|
log.Error().Msgf("Invex api request error: %s", err)
|
||||||
|
|
Loading…
Reference in New Issue