From 3b0c9384a215cf314470a0d6cc5ae493504511c7 Mon Sep 17 00:00:00 2001 From: fran moore Date: Wed, 3 May 2023 16:08:03 +0100 Subject: [PATCH] Upgrading dp-kafka and go version --- NOMIS/nomis.go | 28 +++++++++++++++++++++------- ci/build.yml | 2 +- ci/unit.yml | 2 +- go.mod | 6 +++--- go.sum | 8 ++++---- instance/instance.go | 5 ++++- models/dataset.go | 17 ++++++++++++++--- 7 files changed, 48 insertions(+), 20 deletions(-) diff --git a/NOMIS/nomis.go b/NOMIS/nomis.go index 10588513..8cf297d4 100644 --- a/NOMIS/nomis.go +++ b/NOMIS/nomis.go @@ -183,12 +183,26 @@ func main() { State: "published", } - censusEditionData.ID = uuid.NewV4().String() + id, err := uuid.NewV4() + if err != nil { + logData := log.Data{"json file": res} + log.Error(ctx, "failed to create UUID for censusEditionData.ID", err, logData) + fmt.Println("error") + return + } + censusEditionData.ID = id.String() censusEditionData.Next = generalModel censusEditionData.Current = generalModel //Model to generate instances documents in mongodb - generateId := uuid.NewV4().String() + genId, err := uuid.NewV4() + if err != nil { + logData := log.Data{"json file": res} + log.Error(ctx, "failed to create UUID for generateId", err, logData) + fmt.Println("error") + return + } + generateId := genId.String() censusInstances = models.Version{ Edition: censusYear, ID: generateId, @@ -283,7 +297,7 @@ func main() { fmt.Println("\ndatasets, instances and editions have been added to datasets db") } -//Inserts a document in the datasets collection +// Inserts a document in the datasets collection func createDatasetsDocument(ctx context.Context, id string, class interface{}, conn *mongodriver.MongoConnection) { var err error logData := log.Data{"data": class} @@ -293,7 +307,7 @@ func createDatasetsDocument(ctx context.Context, id string, class interface{}, c } } -//Inserts a document in the editions collection +// Inserts a document in the editions collection func createEditionsDocument(ctx context.Context, id string, class interface{}, conn *mongodriver.MongoConnection) { var err error logData := log.Data{"data": class} @@ -306,7 +320,7 @@ func createEditionsDocument(ctx context.Context, id string, class interface{}, c } } -//Inserts a document in the instances collection +// Inserts a document in the instances collection func createInstancesDocument(ctx context.Context, id string, class interface{}, conn *mongodriver.MongoConnection) { var err error logData := log.Data{"data": class} @@ -319,7 +333,7 @@ func createInstancesDocument(ctx context.Context, id string, class interface{}, } } -//Updates document in the specific collection +// Updates document in the specific collection func upsertData(ctx context.Context, selector, class interface{}, conn *mongodriver.MongoConnection, document string, logData log.Data) error { var err error if _, err = conn.Collection(document).Upsert(ctx, selector, bson.M{"$set": class}); err != nil { @@ -330,7 +344,7 @@ func upsertData(ctx context.Context, selector, class interface{}, conn *mongodri return err } -//Download a file from nomis website for census 2011 data +// Download a file from nomis website for census 2011 data func downloadFile(ctx context.Context) { fullURLFile = "https://www.nomisweb.co.uk/api/v01/dataset/def.sdmx.json?search=*c2011*" diff --git a/ci/build.yml b/ci/build.yml index 1ba6dcb8..898bced6 100644 --- a/ci/build.yml +++ b/ci/build.yml @@ -6,7 +6,7 @@ image_resource: type: docker-image source: repository: golang - tag: 1.19.2 + tag: 1.20.4 inputs: - name: dp-dataset-api diff --git a/ci/unit.yml b/ci/unit.yml index cb8a4391..6c53d1d4 100644 --- a/ci/unit.yml +++ b/ci/unit.yml @@ -6,7 +6,7 @@ image_resource: type: docker-image source: repository: golang - tag: 1.19.2 + tag: 1.20.4 inputs: - name: dp-dataset-api diff --git a/go.mod b/go.mod index 343a4c68..ef5d8376 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ONSdigital/dp-dataset-api -go 1.19 +go 1.20 // to avoid the following vulnerabilities: // - CVE-2022-29153 # pkg:golang/github.com/hashicorp/consul/api@v1.1.0 @@ -17,7 +17,7 @@ require ( github.com/ONSdigital/dp-component-test v0.9.2 github.com/ONSdigital/dp-graph/v2 v2.16.0 github.com/ONSdigital/dp-healthcheck v1.6.1 - github.com/ONSdigital/dp-kafka/v2 v2.7.5 + github.com/ONSdigital/dp-kafka/v2 v2.8.0 github.com/ONSdigital/dp-mongodb/v3 v3.6.0 github.com/ONSdigital/dp-net/v2 v2.9.1 github.com/ONSdigital/log.go/v2 v2.4.1 @@ -28,7 +28,7 @@ require ( github.com/justinas/alice v1.2.0 github.com/kelseyhightower/envconfig v1.4.0 github.com/pkg/errors v0.9.1 - github.com/satori/go.uuid v1.2.0 + github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b github.com/smartystreets/goconvey v1.8.0 github.com/stretchr/testify v1.8.2 go.mongodb.org/mongo-driver v1.11.4 diff --git a/go.sum b/go.sum index b0e20700..faa2c1ad 100644 --- a/go.sum +++ b/go.sum @@ -70,8 +70,8 @@ github.com/ONSdigital/dp-healthcheck v1.5.1-0.20230419121137-48b17cfe6eab/go.mod github.com/ONSdigital/dp-healthcheck v1.6.0/go.mod h1:3bzw2wxDlY3s0+LqBbgemUVlymyyMjqhf4SDP1ONPGw= github.com/ONSdigital/dp-healthcheck v1.6.1 h1:YDAnxE2fI3G2hhGC42mKI/fRhAhIYmFZGQwQ/8M65M0= github.com/ONSdigital/dp-healthcheck v1.6.1/go.mod h1:FURB2RUJHw3lssamKtsGsrbu31ar9yhMSDYzG9vgSIo= -github.com/ONSdigital/dp-kafka/v2 v2.7.5 h1:M9SJ6W/W7GE2nCrp/EUrXL/GG5ylW607Pa5oO0h5R2k= -github.com/ONSdigital/dp-kafka/v2 v2.7.5/go.mod h1:vu8Lb7GcEmrKIWJo4PjM4Y0ThW5baAgd6nGVqSWRR8w= +github.com/ONSdigital/dp-kafka/v2 v2.8.0 h1:lpIz976VdGr0ZkpN/LeMqYAihI9ojTsxZJkTd/sjKT8= +github.com/ONSdigital/dp-kafka/v2 v2.8.0/go.mod h1:vu8Lb7GcEmrKIWJo4PjM4Y0ThW5baAgd6nGVqSWRR8w= github.com/ONSdigital/dp-mocking v0.0.0-20190905163309-fee2702ad1b9/go.mod h1:BcIRgitUju//qgNePRBmNjATarTtynAgc0yV29VpLEk= github.com/ONSdigital/dp-mocking v0.9.1/go.mod h1:BcIRgitUju//qgNePRBmNjATarTtynAgc0yV29VpLEk= github.com/ONSdigital/dp-mocking v0.9.2-0.20230419122200-aef54dcf2a23/go.mod h1:3O3J2g4gB5i4Oi8dR4qaJCj64g5F/2IWQJhRT8LiKlY= @@ -465,8 +465,8 @@ github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBO github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM= +github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/shurcooL/go v0.0.0-20200502201357-93f07166e636/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk= github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a/go.mod h1:AuYgA5Kyo4c7HfUmvRGs/6rGlMMV/6B1bVnB9JxJEEg= github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29/go.mod h1:AuYgA5Kyo4c7HfUmvRGs/6rGlMMV/6B1bVnB9JxJEEg= diff --git a/instance/instance.go b/instance/instance.go index 7f1c1873..e127b2d9 100644 --- a/instance/instance.go +++ b/instance/instance.go @@ -418,7 +418,10 @@ func unmarshalInstance(ctx context.Context, reader io.Reader, post bool) (*model // One could use a different model, so when unmarshalling request body into an // instance object, it will not include those fields. - id := uuid.NewV4() + id, err := uuid.NewV4() + if err != nil { + return nil, err + } instance.InstanceID = id.String() log.Info(ctx, "post request on an instance", log.Data{"instance_id": instance.InstanceID}) diff --git a/models/dataset.go b/models/dataset.go index b5829c8e..28b9b8b7 100644 --- a/models/dataset.go +++ b/models/dataset.go @@ -366,7 +366,11 @@ func CreateVersion(reader io.Reader, datasetID string) (*Version, error) { log.Info(context.Background(), "DEBUG", log.Data{"body_create_version": string(b)}) var version Version - version.ID = uuid.NewV4().String() + id, err := uuid.NewV4() + if err != nil { + return nil, err + } + version.ID = id.String() version.DatasetID = datasetID err = json.Unmarshal(b, &version) @@ -407,7 +411,11 @@ func CreateContact(reader io.Reader) (*Contact, error) { } // Create unique id - id := uuid.NewV4() + id, err := uuid.NewV4() + if err != nil { + return nil, err + } + contact.ID = id.String() return &contact, nil @@ -415,7 +423,10 @@ func CreateContact(reader io.Reader) (*Contact, error) { // CreateEdition manages the creation of an edition object func CreateEdition(host, datasetID, edition string) (*EditionUpdate, error) { - id := uuid.NewV4() + id, err := uuid.NewV4() + if err != nil { + return nil, err + } return &EditionUpdate{ ID: id.String(),