Skip to content

Commit

Permalink
[REFAPP-1371] implement re-run
Browse files Browse the repository at this point in the history
  • Loading branch information
diego-m-ob committed Sep 25, 2024
1 parent 4c134ef commit 3cedaf4
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions pkg/server/import_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@
package server

import (
"archive/zip"
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"

"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"

"github.com/OpenBankingUK/conformance-suite/pkg/discovery"
"github.com/OpenBankingUK/conformance-suite/pkg/server/models"
)

Expand Down Expand Up @@ -74,8 +80,49 @@ func (h importHandlers) postImportRerun(c echo.Context) error {

// nolint:unparam
func (h importHandlers) doImport(request models.ImportRequest, logger *logrus.Entry) error {
// logger.WithField("request", request).Info("Importing ...")
logger.WithField("len(request.Report)", len(request.Report)).Info("Importing ...")
// TODO(mbana): Do something with `report.zip`

// Create a reader for the zip file
zipReader, err := zip.NewReader(bytes.NewReader([]byte(request.Report)), int64(len(request.Report)))
if err != nil {
return fmt.Errorf("failed to create zip reader: %w", err)
}

// Search for discovery.json file
var discoveryFile *zip.File
for _, file := range zipReader.File {
if file.Name == "discovery.json" {
discoveryFile = file
break
}
}

if discoveryFile == nil {
return fmt.Errorf("discovery.json not found in the zip file")
}

// Open the discovery.json file
rc, err := discoveryFile.Open()
if err != nil {
return fmt.Errorf("failed to open discovery.json: %w", err)
}
defer rc.Close()

// Read the content of discovery.json
content, err := io.ReadAll(rc)
if err != nil {
return fmt.Errorf("failed to read discovery.json: %w", err)
}

// Parse the JSON content
var discoveryModel discovery.ModelDiscovery
err = json.Unmarshal(content, &discoveryModel)
if err != nil {
return fmt.Errorf("failed to parse discovery.json: %w", err)
}

// Log the parsed data
logger.WithField("discovery", discoveryModel).Info("Discovery data parsed successfully")

return nil
}

0 comments on commit 3cedaf4

Please sign in to comment.