Skip to content

Commit

Permalink
Merge pull request #122 from internetee/add-repp-connection
Browse files Browse the repository at this point in the history
Add repp connection
  • Loading branch information
OlegPhenomenon authored Oct 13, 2021
2 parents 85a5e51 + 8c5a1a4 commit fa25ed4
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_deploy_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
cp config/database.yml.sample config/database.yml
cp config/application.yml.sample config/application.yml
sed -i -e 's/BASE_URL: "http:\/\/registry:3000"/BASE_URL: "https:\/\/reg-api-accreditation-'$PR_REF'.pilv.tld.ee"/' config/application.yml
sed -i -e 's/BASE_REPP_URL: "http:\/\/registry:3000"/BASE_REPP_URL: "https:\/\/repp-accreditation-'$PR_REF'.pilv.tld.ee"/' config/application.yml
ls -l config/
- name: Build rails image
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Ignore bundler config.
/.bundle

.idea
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-*
Expand Down
8 changes: 4 additions & 4 deletions app/services/api_connector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def initialize(username:, password:)

private

def request(url:, method:, headers:, params: nil)
request = faraday_request(url: url, headers: headers, params: params)
def request(url:, method:, headers:, params: nil, ssl: nil)
request = faraday_request(url: url, headers: headers, params: params, ssl: ssl)
response = request.send(method)
JSON.parse(response.body)
end
Expand All @@ -19,12 +19,12 @@ def generate_token(username:, password:)
Base64.urlsafe_encode64("#{username}:#{password}")
end

def faraday_request(url:, headers:, params: {})
def faraday_request(url:, headers:, params: {}, ssl:)
Faraday.new(
url: url,
headers: headers,
params: params,
ssl: { verify: false}
ssl: ssl
)
end
end
17 changes: 15 additions & 2 deletions app/services/create_domain.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
require 'openssl'
require 'net/http'
require 'json'

class CreateDomain < ApiConnector
if Rails.env.test?
SSL_OPTIONS = nil.freeze
else
SSL_OPTIONS = {
client_cert: OpenSSL::X509::Certificate.new(File.read(ENV['CLIENT_CERTS_PATH'])),
client_key: OpenSSL::PKey::RSA.new(File.read(ENV['CLIENT_KEY_PATH']), ENV['CLIENT_PASSWORD'])
}.freeze
end

def initialize(username:, password:)
super

end

def domain_endpoint
base_url = ENV['BASE_URL']
base_url = ENV['BASE_REPP_URL']
endpoint = ENV['CREATE_DOMAIN']

base_url + endpoint
Expand All @@ -17,7 +30,7 @@ def headers
end

def create_domain
request(url: domain_endpoint, headers: headers, method: :post, params: payload)
request(url: domain_endpoint, headers: headers, method: :post, params: payload, ssl: SSL_OPTIONS)
end

private
Expand Down
7 changes: 5 additions & 2 deletions config/application.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# Temporary secret key for registry
TEMPORARY_SECRET_KEY: "temporary-secret-key"
BASE_URL: "http://registry:3000"
REPP_STAGING_BASE_URL: "https://st-repp.infra.tld.ee"
API_STAGING_BASE_URL: "https://st-api.infra.tld.ee"
BASE_REPP_URL: "http://registry:3000"

GET_INFO: "/api/v1/accreditation_center/auth"

Expand All @@ -22,3 +21,7 @@ ACCR_USERNAME: "accr_bot"
ACCR_PASSWORD: "123456"
ACCR_CONTACT_CODE: "1234566:8A125009"
ACCR_REGISTRAR_NAME: "ACCREDITATION EIS"

CLIENT_CERTS_PATH: '/opt/ca/certs/accr_bot.crt.pem'
CLIENT_KEY_PATH: '/opt/ca/private/client.key'
CLIENT_PASSWORD: '123456'
2 changes: 1 addition & 1 deletion spec/services/api_connector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
allow(body).to receive(:body).and_return(response)

api_connector = ApiConnector.new(username: "mock", password: "username")
allow(api_connector).to receive(:faraday_request).with(url: "https://something", headers: {}, params: {}).and_return(Faraday)
allow(api_connector).to receive(:faraday_request).with(url: "https://something", headers: {}, params: {}, ssl: nil).and_return(Faraday)

allow(Faraday).to receive(:send).with(:get).and_return(body)

Expand Down
5 changes: 3 additions & 2 deletions spec/services/create_domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
allow(@api_connector).to receive(:request).with(url: @api_connector.domain_endpoint,
headers: @api_connector.headers,
method: :post,
params: payload).and_return(@response_successful)
params: payload,
ssl: nil).and_return(@response_successful)

response = @api_connector.create_domain
expect(response["code"]).to eq("1000")
Expand All @@ -55,7 +56,7 @@
end

it "should return endpoint" do
ENV['BASE_URL'] = 'https://api.website'
ENV['BASE_REPP_URL'] = 'https://api.website'
ENV['CREATE_DOMAIN'] = '/repp/domains/'

api_connector = CreateDomain.new(username: user.username, password: user.password)
Expand Down

0 comments on commit fa25ed4

Please sign in to comment.