Skip to content

Commit

Permalink
Introduce multi files for authorization definitions
Browse files Browse the repository at this point in the history
Migrate generators too
  • Loading branch information
skelz0r committed Dec 12, 2024
1 parent 69690da commit 0a65309
Show file tree
Hide file tree
Showing 8 changed files with 717 additions and 722 deletions.
4 changes: 2 additions & 2 deletions app/models/authorization_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class AuthorizationDefinition < StaticApplicationRecord
:public

def self.all
Rails.application.config_for(:authorization_definitions).map do |uid, hash|
build(uid, hash)
AuthorizationDefinitionConfigurations.instance.all.map do |uid, hash|
build(uid, hash.deep_symbolize_keys)
end
end

Expand Down
5 changes: 5 additions & 0 deletions app/services/authorization_definition_configurations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AuthorizationDefinitionConfigurations < AbstractYAMLConfiguration
def files
Dir[Rails.root.join('config/authorization_definitions/*.y*ml').to_s]
end
end
632 changes: 0 additions & 632 deletions config/authorization_definitions.yml

This file was deleted.

630 changes: 630 additions & 0 deletions config/authorization_definitions/base.yml

Large diffs are not rendered by default.

28 changes: 2 additions & 26 deletions lib/generators/definition/definition_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def create_model_file
template 'authorization_request.rb.erb', "app/models/authorization_request/#{name.underscore}.rb"
end

def insert_definition_infos
append_to_file 'config/authorization_definitions.yml', definition_data
def create_definition_file
template 'definition.yml.erb', "config/authorization_definitions/#{name.underscore}.yml"
end

def create_forms_file
Expand All @@ -27,30 +27,6 @@ def create_feature_file

private

def definition_data
<<-YAML_DATA
#{name.underscore}:
name: #{humanized_name}
description: "FEEDME"
provider: "dinum"
kind: 'api'
link: "https://#{name.underscore.dasherize}.gouv.fr/feedme-with-valid-url"
cgu_link: "https://#{name.underscore.dasherize}.gouv.fr/cgu"
access_link: "https://#{name.underscore.dasherize}.gouv.fr/tokens/%<external_provider_id>"
public: true
blocks:
- name: "basic_infos"
- name: "personal_data"
- name: "legal"
- name: "scopes"
- name: "contacts"
scopes:
- name: "Scope 1"
value: "value_1"
group: "Groupe"
YAML_DATA
end

def factory_data
<<-FACTORY_DATA
Expand Down
19 changes: 19 additions & 0 deletions lib/generators/definition/templates/definition.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%= name.underscore %>:
name: <%= humanized_name %>
description: "FEEDME"
provider: "dinum"
kind: 'api'
link: "https://<%= name.underscore.dasherize %>.gouv.fr/feedme-with-valid-url"
cgu_link: "https://<%= name.underscore.dasherize %>.gouv.fr/cgu"
access_link: "https://<%= name.underscore.dasherize %>.gouv.fr/tokens/%<external_provider_id>"
public: true
blocks:
- name: "basic_infos"
- name: "personal_data"
- name: "legal"
- name: "scopes"
- name: "contacts"
scopes:
- name: "Scope 1"
value: "value_1"
group: "Groupe"
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def create_models_file
template 'authorization_request_production.rb.erb', "app/models/authorization_request/#{name.underscore}.rb"
end

def insert_definitions_infos
append_to_file 'config/authorization_definitions.yml', definitions_data
def create_definition_file
template 'definition.yml.erb', "config/authorization_definitions/#{name.underscore}.yml"
end

def create_forms_file
Expand Down Expand Up @@ -50,65 +50,6 @@ def provider
options.fetch(:provider, 'dinum').downcase
end

# rubocop:disable Metrics/AbcSize
def definitions_data
<<-YAML_DATA
#{name.underscore}_sandbox:
name: #{humanized_name}
description: "FEEDME"
provider: "#{provider}"
kind: 'api'
link: "https://#{name.underscore.dasherize}.gouv.fr/feedme-with-valid-url"
cgu_link: "https://#{name.underscore.dasherize}.gouv.fr/cgu"
access_link: "https://#{name.underscore.dasherize}.gouv.fr/tokens/%<external_provider_id>"
public: true
stage:
type: sandbox
next:
id: #{name.underscore}
form_id: #{name.underscore.dasherize}
blocks:
- name: basic_infos
- name: personal_data
- name: legal
#{scopes? ? '- name: scopes' : ''}
- name: contacts
#{if scopes?
"scopes: &#{name.underscore}_scopes
- name: 'Scope 1'
value: 'value_1'
group: 'Groupe'"
else
''
end}
#{name.underscore}:
name: #{humanized_name}
description: "FEEDME"
provider: "#{provider}"
kind: 'api'
link: "https://#{name.underscore.dasherize}.gouv.fr/feedme-with-valid-url"
cgu_link: "https://#{name.underscore.dasherize}.gouv.fr/cgu"
access_link: "https://#{name.underscore.dasherize}.gouv.fr/tokens/%<external_provider_id>"
public: true
stage:
type: production
previouses:
- id: #{name.underscore}_sandbox
form_id: #{name.underscore.dasherize}-sandbox
blocks:
- name: basic_infos
- name: personal_data
- name: legal
#{scopes? ? '- name: scopes' : ''}
- name: contacts
- name: operational_acceptance
- name: safety_certification
- name: volumetrie
#{scopes? ? "scopes: *#{name.underscore}_scopes" : ''}
YAML_DATA
end

def factory_data
<<-FACTORY_DATA
Expand Down Expand Up @@ -138,7 +79,6 @@ def factory_data
end
FACTORY_DATA
end
# rubocop:enable Metrics/AbcSize

def end_of_factory_file
/ end\nend/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<%= name.underscore %>_sandbox:
name: <%= humanized_name %>
description: "FEEDME"
provider: "<%= provider %>"
kind: 'api'
link: "https://<%= name.underscore.dasherize %>.gouv.fr/feedme-with-valid-url"
cgu_link: "https://<%= name.underscore.dasherize %>.gouv.fr/cgu"
access_link: "https://<%= name.underscore.dasherize %>.gouv.fr/tokens/%<external_provider_id>"
public: true
stage:
type: sandbox
next:
id: <%= name.underscore %>
form_id: <%= name.underscore.dasherize %>
blocks:
- name: basic_infos
- name: personal_data
- name: legal
<% if scopes? %>
- name: scopes
<% end %>
- name: contacts
<% if scopes? %>
scopes: &<%= name.underscore %>_scopes
- name: 'Scope 1'
value: 'value_1'
group: 'Groupe'
<% end %>

<%= name.underscore %>:
name: <%= humanized_name %>
description: "FEEDME"
provider: "<%= provider %>"
kind: 'api'
link: "https://<%= name.underscore.dasherize %>.gouv.fr/feedme-with-valid-url"
cgu_link: "https://<%= name.underscore.dasherize %>.gouv.fr/cgu"
access_link: "https://<%= name.underscore.dasherize %>.gouv.fr/tokens/%<external_provider_id>"
public: true
stage:
type: production
previouses:
- id: <%= name.underscore %>_sandbox
form_id: <%= name.underscore.dasherize %>-sandbox
blocks:
- name: basic_infos
- name: personal_data
- name: legal
<% if scopes? %>
- name: scopes
<% end %>
- name: contacts
- name: operational_acceptance
- name: safety_certification
- name: volumetrie
<% if scopes? %>
scopes: *<%= name.underscore %>_scopes
<% end %>

0 comments on commit 0a65309

Please sign in to comment.