2023-03-27 18:54:56 +00:00
|
|
|
package ocssapi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
|
|
|
|
"git.coopgo.io/coopgo-platform/carpool-service/handler"
|
|
|
|
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type OCSSApiService struct {
|
2023-04-03 18:35:12 +00:00
|
|
|
OperatorId string
|
|
|
|
Handler *handler.CarpoolServiceHandler
|
2023-03-27 18:54:56 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 18:35:12 +00:00
|
|
|
func NewOCSSApiService(cfg *viper.Viper, handler *handler.CarpoolServiceHandler) (*OCSSApiService, error) {
|
2023-03-27 18:54:56 +00:00
|
|
|
return &OCSSApiService{
|
2023-04-03 18:35:12 +00:00
|
|
|
OperatorId: cfg.GetString("standards.ocss.operator_id"),
|
|
|
|
Handler: handler,
|
2023-03-27 18:54:56 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status
|
|
|
|
func (s *OCSSApiService) Status() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Run(done chan error, cfg *viper.Viper, handler *handler.CarpoolServiceHandler) {
|
|
|
|
var (
|
|
|
|
address = ":" + cfg.GetString("services.ocss_api.port")
|
|
|
|
)
|
|
|
|
|
2023-04-03 18:35:12 +00:00
|
|
|
service, err := NewOCSSApiService(cfg, handler)
|
2023-03-27 18:54:56 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("could not initialize OCSS api service")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-29 10:50:25 +00:00
|
|
|
server := ocss.NewServer(service)
|
|
|
|
server.AddOperator("mobilaude_preprod", "wxvSwUpTTZ5wiAxrHpPfDsijz88w6tMW")
|
|
|
|
server.AuthorizedOperators = append(server.AuthorizedOperators, ocss.AuthorizedOperator{
|
|
|
|
Operator: "mobilaude",
|
|
|
|
ApiKey: "$2y$10$TJuDZDu.mqy5dDKGMSfxSO5f6pz/36XVrAyQ1CXJd63ccjRlX7gpC",
|
|
|
|
})
|
2023-03-27 18:54:56 +00:00
|
|
|
|
|
|
|
srv := &http.Server{
|
2023-03-29 10:50:25 +00:00
|
|
|
Handler: server,
|
2023-03-27 18:54:56 +00:00
|
|
|
Addr: address,
|
|
|
|
WriteTimeout: 15 * time.Second,
|
|
|
|
ReadTimeout: 15 * time.Second,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = srv.ListenAndServe()
|
|
|
|
|
|
|
|
log.Error().Err(err).Msg("OCSS api error")
|
|
|
|
done <- err
|
|
|
|
}
|