Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Feature/5705 #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

# input templates
:provider_json_template => 'files/service-definitions/provider.json.erb',
:eip_service_json_template => 'files/service-definitions/#{arg}/eip-service.json.erb',
:eip_service_json_template => 'files/service-definitions/#{arg[0]}/eip-service#{arg[1]}.json.erb',
:soledad_service_json_template => 'files/service-definitions/#{arg}/soledad-service.json.erb',
:smtp_service_json_template => 'files/service-definitions/#{arg}/smtp-service.json.erb',

Expand Down
67 changes: 67 additions & 0 deletions provider_base/files/service-definitions/v1/eip-service-2.json.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<%=
def underscore(words)
words = words.to_s.dup
words.downcase!
words.gsub! /[^a-z]/, '_'
words
end

def add_gateway(node, locations, options={})
return nil if options[:ip] == 'REQUIRED'
gateway = {}
gateway["capabilities"] = node.openvpn.pick(:ports, :protocols, :user_ips, :adblock, :filter_dns)
gateway["capabilities"]["transport"] = ["openvpn"]
gateway["host"] = node.domain.full
gateway["ip_address"] = options[:ip]
gateway["capabilities"]["limited"] = options[:limited]
if node['location']
location_name = underscore(node.location.name)
gateway["location"] = location_name
locations[location_name] ||= node.location
end
gateway
end

def add_obfsproxy(node)
obfsproxy = {}
if node.services.include?("openvpn")
obfsproxy["ip_address"] = node.openvpn.gateway_address
elsif node.services.include?("obfsproxy")
obfsproxy["ip_address"] = node.ip_address
end
if node['obfsproxy']['scramblesuit']
obfsproxy["transport"] = "scramblesuit"
obfsproxy["scramblesuit"] = node.obfsproxy.scramblesuit.pick(:port, :password)
end
obfsproxy
end

hsh = {}
locations = {}
gateways = {}
obfsproxies = []
configuration = nil
nodes_like_me[:services => 'openvpn'].each_node do |node|
if node.openvpn.allow_limited && node.openvpn.allow_unlimited
gateways[node.name + '_unlimited'] = add_gateway(node, locations, :ip => node.openvpn.gateway_address, :limited => false)
gateways[node.name + '_limited'] = add_gateway(node, locations, :ip => node.openvpn.second_gateway_address, :limited => true)
elsif node.openvpn.allow_unlimited
gateways[node.name + '_unlimited'] = add_gateway(node, locations, :ip => node.openvpn.gateway_address, :limited => false)
elsif node.openvpn.allow_limited
gateways[node.name + '_limited'] = add_gateway(node, locations, :ip => node.openvpn.gateway_address, :limited => true)
end
if configuration && node.openvpn.configuration != configuration
log :error, "OpenVPN nodes in the environment `#{node.environment}` have conflicting `openvpn.configuration` values. This will result in bad errors."
end
configuration = node.openvpn.configuration
obfsproxies << add_obfsproxy(node)
end
nodes_like_me[:services => 'obfsproxy'].each_node do |node|
obfsproxies << add_obfsproxy(node)
end
hsh["gateways"] = gateways
hsh["locations"] = locations
hsh["openvpn_configuration"] = configuration
hsh["obfsproxies"] = obfsproxies.compact
JSON.sorted_generate hsh
%>
3 changes: 2 additions & 1 deletion provider_base/services/webapp.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
},
"definition_files": {
"provider": "= file :provider_json_template",
"eip_service": "= file [:eip_service_json_template, 'v'+webapp.api_version.to_s]",
"eip_service": "= file [:eip_service_json_template, 'v'+webapp.api_version.to_s, '']",
"eip_service_2": "= try_file [:eip_service_json_template, 'v'+webapp.api_version.to_s, '-2']",
"soledad_service": "= file [:soledad_service_json_template, 'v'+webapp.api_version.to_s]",
"smtp_service": "= file [:smtp_service_json_template, 'v'+webapp.api_version.to_s]"
},
Expand Down
7 changes: 7 additions & 0 deletions puppet/modules/site_webapp/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
$definition_files = hiera('definition_files')
$provider = $definition_files['provider']
$eip_service = $definition_files['eip_service']
$eip_service_2 = $definition_files['eip_service_2']
$soledad_service = $definition_files['soledad_service']
$smtp_service = $definition_files['smtp_service']
$node_domain = hiera('domain')
Expand Down Expand Up @@ -123,6 +124,12 @@
content => $smtp_service,
require => Vcsrepo['/srv/leap/webapp'],
owner => leap-webapp, group => leap-webapp, mode => '0644';

"/srv/leap/webapp/public/${api_version}/config/eip-service-2.json":
content => $eip_service_2,
require => Vcsrepo['/srv/leap/webapp'],
owner => leap-webapp, group => leap-webapp, mode => '0644';

}

try::file {
Expand Down