-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ETQ tech: je veux publier les fichiers opendata selon les bonnes pratiques de data.gouv #11100
Draft
Benoit-MINT
wants to merge
7
commits into
main
Choose a base branch
from
opendata-new-publication-dataset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−28
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5615d96
refacto process actuel de publication, sur la ressource : nb_comptes_…
Benoit-MINT 662015f
vérification de l'existence du fichier
Benoit-MINT 7176752
si pas de fichier existant, on publie un nouveau
Benoit-MINT dde19af
si fichier existant, récupération des données + détection dernière date
Benoit-MINT 1b3933d
fichier existant, on ajoute les nouvelles données
Benoit-MINT 6107dd7
on construit le nouveau fichier et on upload sur le fichier existant
Benoit-MINT 146d00c
test : account_by_month_job_spec
Benoit-MINT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,28 @@ | |
end | ||
|
||
class << self | ||
def check_existing_resource(dataset, resource) | ||
response = Typhoeus.get( | ||
datagouv_check_url(dataset, resource), | ||
headers: { "X-Api-Key" => datagouv_secret[:api_key] } | ||
) | ||
|
||
response.success? | ||
end | ||
|
||
def get_existing_file_url(dataset, resource) | ||
response = Typhoeus.get( | ||
datagouv_get_resource_url(dataset, resource), | ||
followlocation: true | ||
) | ||
|
||
if response.success? | ||
JSON.parse(response.body)["url"] | ||
else | ||
raise RequestFailed.new(datagouv_get_resource_url(dataset, resource), response) | ||
end | ||
end | ||
|
||
def upload(io, dataset, resource = nil) | ||
response = Typhoeus.post( | ||
datagouv_upload_url(dataset, resource), | ||
|
@@ -32,6 +54,23 @@ | |
|
||
private | ||
|
||
def datagouv_check_url(dataset, resource) | ||
[ | ||
datagouv_secret[:api_url], | ||
"/datasets/", datagouv_secret[dataset], | ||
"/resources/", datagouv_secret[resource], | ||
"/check/" | ||
].join | ||
end | ||
|
||
def datagouv_get_resource_url(dataset, resource) | ||
[ | ||
datagouv_secret[:api_url], | ||
"/datasets/", datagouv_secret[dataset], | ||
"/resources/", datagouv_secret[resource] | ||
].join | ||
end | ||
|
||
def datagouv_upload_url(dataset, resource = nil) | ||
if resource.present? | ||
[ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class GenerateOpenDataCsvService | ||
def self.save_csv_to_tmp(file_name, data) | ||
f = Tempfile.create(["#{file_name}_#{date_last_month}", '.csv'], 'tmp') | ||
f << generate_csv(file_name, data) | ||
f.rewind | ||
yield f if block_given? | ||
f.close | ||
end | ||
|
||
def self.date_last_month | ||
Date.today.prev_month.strftime("%B") | ||
end | ||
|
||
def self.generate_csv(file_name, data) | ||
headers = ["mois", file_name] | ||
data = [[date_last_month, data]] | ||
SpreadsheetArchitect.to_csv(headers: headers, data: data) | ||
def self.save_csv_to_tmp(file_name, headers, data) | ||
Tempfile.create(file_name, 'tmp') do |file| | ||
file << SpreadsheetArchitect.to_csv(headers:, data:) | ||
file.rewind | ||
yield file if block_given? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,6 +173,7 @@ OPENDATA_ENABLED="enabled" # disabled by default if `OPENDATA_ENABLED` not set | |
DATAGOUV_API_KEY="thisisasecret" | ||
DATAGOUV_API_URL="https://www.data.gouv.fr/api/1" | ||
DATAGOUV_STATISTICS_DATASET="dataset-id1" | ||
DATAGOUV_STATICTICS_ACOUNT_RESOURCE="resource-id1-of-dataset-id1" | ||
DATAGOUV_DESCRIPTIF_DEMARCHES_DATASET="dataset-id2" | ||
DATAGOUV_DESCRIPTIF_DEMARCHES_RESOURCE="resource-id-of-dataset-id2" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ defaults: &defaults | |
descriptif_demarches_dataset: <%= ENV['DATAGOUV_DESCRIPTIF_DEMARCHES_DATASET'] %> | ||
descriptif_demarches_resource: <%= ENV['DATAGOUV_DESCRIPTIF_DEMARCHES_RESOURCE'] %> | ||
statistics_dataset: <%= ENV['DATAGOUV_STATISTICS_DATASET'] %> | ||
statistics_account_by_month_resource: <%= ENV['DATAGOUV_STATICTICS_ACOUNT_RESOURCE'] %> | ||
|
||
|
||
development: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,22 @@ | |
let!(:user) { create(:user, created_at: 1.month.ago) } | ||
let(:status) { 200 } | ||
let(:body) { "ok" } | ||
let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) } | ||
# let(:stub) { stub_request(:post, /https:\/\/www.data.gouv.fr\/api\/.*\/upload\//) } | ||
|
||
describe 'perform' do | ||
before do | ||
stub | ||
end | ||
# before do | ||
# stub | ||
# end | ||
|
||
subject { Cron::Datagouv::AccountByMonthJob.perform_now } | ||
|
||
it 'send POST request to datagouv' do | ||
subject | ||
expect(stub).to have_been_requested | ||
allow(APIDatagouv::API).to receive(:upload) do |file| | ||
csv = CSV.read(file, headers: true) | ||
expect(csv[0]['mois']).to eq(Date.today.prev_month.strftime("%B %Y")) | ||
end | ||
# expect(stub).to have_been_requested | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Use of `Kernel.open` or `IO.read` or similar sinks with a non-constant value Critical
Copilot Autofix AI about 10 hours ago
To fix the problem, we should replace the use of
URI.open
with a safer alternative. Specifically, we can useNet::HTTP.get
to fetch the content of the URL, which does not have the same vulnerability asURI.open
.URI.open(file_url).read
withNet::HTTP.get(URI.parse(file_url))
.net/http
library is required at the top of the file if it is not already.