Skip to content

Commit

Permalink
Upgrading dp-kafka and go version
Browse files Browse the repository at this point in the history
  • Loading branch information
franmoore05 committed May 3, 2023
1 parent dfa0bd5 commit 3b0c938
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 20 deletions.
28 changes: 21 additions & 7 deletions NOMIS/nomis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand All @@ -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}
Expand All @@ -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 {
Expand All @@ -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*"

Expand Down
2 changes: 1 addition & 1 deletion ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ci/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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/[email protected]
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
5 changes: 4 additions & 1 deletion instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
17 changes: 14 additions & 3 deletions models/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -407,15 +411,22 @@ 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
}

// 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(),
Expand Down

0 comments on commit 3b0c938

Please sign in to comment.