Skip to content

Commit

Permalink
Merge branch 'develop' into release/1.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-urbani committed Mar 8, 2021
2 parents aa7f7b3 + ae13307 commit b3693be
Show file tree
Hide file tree
Showing 16 changed files with 565 additions and 1,403 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ See [CONTRIBUTING](CONTRIBUTING.md) for details.

Copyright © 2016-2021, Office for National Statistics (https://www.ons.gov.uk)

Released under MIT license, see [LICENSE](LICENSE.md) for details
Released under MIT license, see [LICENSE](LICENSE.md) for details.
79 changes: 32 additions & 47 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,46 +51,44 @@ type AuthHandler interface {

// DatasetAPI manages importing filters against a dataset
type DatasetAPI struct {
Router *mux.Router
dataStore store.DataStore
urlBuilder *url.Builder
host string
downloadServiceToken string
EnablePrePublishView bool
downloadGenerator DownloadsGenerator
enablePrivateEndpoints bool
enableDetachDataset bool
enableObservationEndpoint bool
datasetPermissions AuthHandler
permissions AuthHandler
instancePublishedChecker *instance.PublishCheck
versionPublishedChecker *PublishCheck
defaultLimit int
defaultOffset int
maxLimit int
Router *mux.Router
dataStore store.DataStore
urlBuilder *url.Builder
host string
downloadServiceToken string
EnablePrePublishView bool
downloadGenerator DownloadsGenerator
enablePrivateEndpoints bool
enableDetachDataset bool
datasetPermissions AuthHandler
permissions AuthHandler
instancePublishedChecker *instance.PublishCheck
versionPublishedChecker *PublishCheck
defaultLimit int
defaultOffset int
maxLimit int
}

// Setup creates a new Dataset API instance and register the API routes based on the application configuration.
func Setup(ctx context.Context, cfg *config.Configuration, router *mux.Router, dataStore store.DataStore, urlBuilder *url.Builder, downloadGenerator DownloadsGenerator, datasetPermissions AuthHandler, permissions AuthHandler) *DatasetAPI {

api := &DatasetAPI{
dataStore: dataStore,
host: cfg.DatasetAPIURL,
downloadServiceToken: cfg.DownloadServiceSecretKey,
EnablePrePublishView: cfg.EnablePrivateEndpoints,
Router: router,
urlBuilder: urlBuilder,
downloadGenerator: downloadGenerator,
enablePrivateEndpoints: cfg.EnablePrivateEndpoints,
enableDetachDataset: cfg.EnableDetachDataset,
enableObservationEndpoint: cfg.EnableObservationEndpoint,
datasetPermissions: datasetPermissions,
permissions: permissions,
versionPublishedChecker: nil,
instancePublishedChecker: nil,
defaultLimit: cfg.DefaultLimit,
defaultOffset: cfg.DefaultOffset,
maxLimit: cfg.DefaultMaxLimit,
dataStore: dataStore,
host: cfg.DatasetAPIURL,
downloadServiceToken: cfg.DownloadServiceSecretKey,
EnablePrePublishView: cfg.EnablePrivateEndpoints,
Router: router,
urlBuilder: urlBuilder,
downloadGenerator: downloadGenerator,
enablePrivateEndpoints: cfg.EnablePrivateEndpoints,
enableDetachDataset: cfg.EnableDetachDataset,
datasetPermissions: datasetPermissions,
permissions: permissions,
versionPublishedChecker: nil,
instancePublishedChecker: nil,
defaultLimit: cfg.DefaultLimit,
defaultOffset: cfg.DefaultOffset,
maxLimit: cfg.DefaultMaxLimit,
}

if api.enablePrivateEndpoints {
Expand Down Expand Up @@ -138,10 +136,6 @@ func (api *DatasetAPI) enablePublicEndpoints(ctx context.Context) {
api.get("/datasets/{dataset_id}/editions/{edition}/versions/{version}/dimensions", api.getDimensions)
api.get("/datasets/{dataset_id}/editions/{edition}/versions/{version}/dimensions/{dimension}/options", api.getDimensionOptions)

if api.enableObservationEndpoint {
log.Event(ctx, "enabling observations endpoint", log.INFO)
api.get("/datasets/{dataset_id}/editions/{edition}/versions/{version}/observations", api.getObservations)
}
}

// enablePrivateDatasetEndpoints register the datasets endpoints with the appropriate authentication and authorisation
Expand Down Expand Up @@ -187,15 +181,6 @@ func (api *DatasetAPI) enablePrivateDatasetEndpoints(ctx context.Context) {
api.getMetadata),
)

if api.enableObservationEndpoint {
log.Event(ctx, "enabling observations endpoint", log.INFO)
api.get(
"/datasets/{dataset_id}/editions/{edition}/versions/{version}/observations",
api.isAuthorisedForDatasets(readPermission,
api.getObservations),
)
}

api.get(
"/datasets/{dataset_id}/editions/{edition}/versions/{version}/dimensions",
api.isAuthorisedForDatasets(readPermission,
Expand Down
8 changes: 8 additions & 0 deletions api/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@ func (api *DatasetAPI) putDataset(w http.ResponseWriter, r *http.Request) {
return err
}
} else {
if err := models.CleanDataset(dataset); err != nil {
log.Event(ctx, "could not clean dataset", log.ERROR, log.Error(err))
return nil
}
if err := models.ValidateDataset(dataset); err != nil {
log.Event(ctx, "failed validation check to update dataset", log.ERROR, log.Error(err))
return nil
}
if err := api.dataStore.Backend.UpdateDataset(ctx, datasetID, dataset, currentDataset.Next.State); err != nil {
log.Event(ctx, "putDataset endpoint: failed to update dataset resource", log.ERROR, log.Error(err), data)
return err
Expand Down
Loading

0 comments on commit b3693be

Please sign in to comment.