Skip to content
Snippets Groups Projects
Commit 0eb26ded authored by Malte Bauch's avatar Malte Bauch
Browse files

Move prototypical etsi14 emulator in its own dir

See merge request !59
parent 8f7d78cd
Branches
Tags
1 merge request!59Move prototypical etsi14 emulator in its own dir
Pipeline #186338 passed
...@@ -44,12 +44,18 @@ build-ekms: pre ...@@ -44,12 +44,18 @@ build-ekms: pre
build-quantumlayer: pre build-quantumlayer: pre
$(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/quantumlayer ./quantumlayer/example/main.go $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/quantumlayer ./quantumlayer/example/main.go
build-etsi14module: pre
$(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/etsi14module ./etsi14module/main.go
build-akms-simulator: pre build-akms-simulator: pre
$(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/akms-simulator ./akms-simulator/akms-simulator.go $(GOBUILD) -o $(BUILD_ARTIFACTS_PATH)/akms-simulator ./akms-simulator/akms-simulator.go
quantumlayer-container: quantumlayer-container:
docker buildx build --rm -t quantumlayer --load -f ./quantumlayer/Dockerfile --build-arg GITLAB_LOGIN=${GITLAB_LOGIN} --build-arg GITLAB_TOKEN=${GITLAB_TOKEN} --build-arg GOLANG_VERSION=${GOLANG_VERSION} . docker buildx build --rm -t quantumlayer --load -f ./quantumlayer/Dockerfile --build-arg GITLAB_LOGIN=${GITLAB_LOGIN} --build-arg GITLAB_TOKEN=${GITLAB_TOKEN} --build-arg GOLANG_VERSION=${GOLANG_VERSION} .
etsi14module-container:
docker buildx build --rm -t etsi14module --load -f ./etsi14module/Dockerfile --build-arg GOLANG_VERSION=${GOLANG_VERSION} .
ekms-build-debug: pre ekms-build-debug: pre
$(GOBUILD) -gcflags="all=-N -l" -o $(BUILD_ARTIFACTS_PATH)/ekms ./ekms/main.go $(GOBUILD) -gcflags="all=-N -l" -o $(BUILD_ARTIFACTS_PATH)/ekms ./ekms/main.go
......
...@@ -40,7 +40,6 @@ import ( ...@@ -40,7 +40,6 @@ import (
"code.fbi.h-da.de/danet/quant/ekms/handlers/danet" "code.fbi.h-da.de/danet/quant/ekms/handlers/danet"
"code.fbi.h-da.de/danet/quant/ekms/handlers/system" "code.fbi.h-da.de/danet/quant/ekms/handlers/system"
gnmitargetygot "code.fbi.h-da.de/danet/quant/ekms/model" gnmitargetygot "code.fbi.h-da.de/danet/quant/ekms/model"
"code.fbi.h-da.de/danet/quant/ekms/restserver"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
...@@ -74,9 +73,6 @@ var startCmd = &cobra.Command{ ...@@ -74,9 +73,6 @@ var startCmd = &cobra.Command{
fmt.Println("Startup of GNMI Target...") fmt.Println("Startup of GNMI Target...")
lvl := viper.GetString("logLevel") lvl := viper.GetString("logLevel")
etsi14RESTService := restserver.NewETSI14RESTService(":1414")
restserver.SetupETSI14RestServer(etsi14RESTService)
// parse string, this is built-in feature of logrus // parse string, this is built-in feature of logrus
ll, err := logrus.ParseLevel(lvl) ll, err := logrus.ParseLevel(lvl)
if err != nil { if err != nil {
......
artifacts
ARG GOLANG_VERSION=1.22
ARG BUILDARGS
FROM ${GITLAB_PROXY}golang:$GOLANG_VERSION-bookworm as builder
WORKDIR /app/
COPY . .
RUN --mount=type=cache,target=/root/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
make build-etsi14module
FROM ${GITLAB_PROXY}debian:bookworm-slim
WORKDIR /app/
COPY --from=builder /app/artifacts/etsi14module ./etsi14module
ENTRYPOINT ["./etsi14module"]
package restserver package main
import ( import (
"context" "context"
"crypto/rand"
"encoding/base64"
"net/http" "net/http"
"os"
"os/signal"
"sync"
"syscall"
restserver "code.fbi.h-da.de/danet/quant/ekms/api/go/rest/etsi/server/go" restserver "code.fbi.h-da.de/danet/quant/ekms/api/go/rest/etsi/server/go"
"github.com/google/uuid"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
...@@ -12,6 +19,9 @@ type ETSI14RESTService struct { ...@@ -12,6 +19,9 @@ type ETSI14RESTService struct {
serviceAddress string serviceAddress string
} }
var keyStoreMutex sync.RWMutex
var keyStore = make(map[string]string, 0)
func NewETSI14RESTService(serviceAdress string) *ETSI14RESTService { func NewETSI14RESTService(serviceAdress string) *ETSI14RESTService {
return &ETSI14RESTService{ return &ETSI14RESTService{
serviceAddress: serviceAdress, serviceAddress: serviceAdress,
...@@ -45,14 +55,26 @@ func (s *ETSI14RESTService) GetKey(ctx context.Context, slaveSAEID interface{}, ...@@ -45,14 +55,26 @@ func (s *ETSI14RESTService) GetKey(ctx context.Context, slaveSAEID interface{},
// return Response(503, nil),nil // return Response(503, nil),nil
keyContainer := &restserver.KeyContainer{} keyContainer := &restserver.KeyContainer{}
keyContainer.Keys = append(keyContainer.Keys, restserver.KeyContainerKeysInner{
KeyID: "1234", for range number {
Key: "asdf", keyId := uuid.New().String()
})
keyContainer.Keys = append(keyContainer.Keys, restserver.KeyContainerKeysInner{ b := make([]byte, 32)
KeyID: "5787538778534", _, err := rand.Read(b)
Key: "cddelffsfkllfsdmflmdl", if err != nil {
}) //TODO: todo
}
keyAsBase64String := base64.StdEncoding.EncodeToString(b)
keyContainer.Keys = append(keyContainer.Keys, restserver.KeyContainerKeysInner{
KeyID: keyId,
Key: keyAsBase64String,
})
keyStoreMutex.Lock()
keyStore[keyId] = keyAsBase64String
keyStoreMutex.Unlock()
}
return restserver.Response(http.StatusOK, keyContainer), nil return restserver.Response(http.StatusOK, keyContainer), nil
} }
...@@ -100,10 +122,17 @@ func (s *ETSI14RESTService) GetKeyWithIds(ctx context.Context, masterSAEID inter ...@@ -100,10 +122,17 @@ func (s *ETSI14RESTService) GetKeyWithIds(ctx context.Context, masterSAEID inter
// TODO: Uncomment the next line to return response Response(503, {}) or use other options such as http.Ok ... // TODO: Uncomment the next line to return response Response(503, {}) or use other options such as http.Ok ...
// return Response(503, nil),nil // return Response(503, nil),nil
keyStoreMutex.RLock()
key, ok := keyStore[keyID]
if !ok {
//TODO: todo
}
keyStoreMutex.RUnlock()
keyContainer := &restserver.KeyContainer{} keyContainer := &restserver.KeyContainer{}
keyContainer.Keys = append(keyContainer.Keys, restserver.KeyContainerKeysInner{ keyContainer.Keys = append(keyContainer.Keys, restserver.KeyContainerKeysInner{
KeyID: "1234", KeyID: keyID,
Key: "asdf", Key: key,
}) })
return restserver.Response(http.StatusOK, keyContainer), nil return restserver.Response(http.StatusOK, keyContainer), nil
...@@ -170,3 +199,13 @@ func (s *ETSI14RESTService) GetStatus(ctx context.Context, slaveSAEID interface{ ...@@ -170,3 +199,13 @@ func (s *ETSI14RESTService) GetStatus(ctx context.Context, slaveSAEID interface{
return resp, nil return resp, nil
} }
func main() {
etsi14RESTService := NewETSI14RESTService(":1414")
SetupETSI14RestServer(etsi14RESTService)
stopChan := make(chan os.Signal, 1)
signal.Notify(stopChan, os.Interrupt, syscall.SIGTERM)
<-stopChan
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment