Compare commits

...

2 commits

Author SHA1 Message Date
f
6598246076 container
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-03-12 16:10:48 -03:00
f
07eb3108ff registrar llaves públicas 2022-03-12 16:10:16 -03:00
5 changed files with 42 additions and 2 deletions

View file

@ -5,7 +5,7 @@ ARG RUBY_PATCH=5
FROM ${BASE_IMAGE}:${ALPINE_VERSION}-${RUBY_VERSION}.${RUBY_PATCH}
ENV RAILS_ENV production
RUN apk add --no-cache libxslt libxml2 tzdata --no-cache postgresql-libs libstdc++
RUN apk add --no-cache libxslt libxml2 tzdata postgresql-libs libstdc++
VOLUME "/srv"

View file

@ -39,8 +39,11 @@ class ReadingsController < ActionController::API
head :bad_request
end
# Registra una Raspberry junto con su llave pública
def raspberry
@raspberry ||= Raspberry.find_or_create_by! name: params[:controller_id]
@raspberry ||= Raspberry.find_or_create_by!(name: params[:controller_id]).tap do |r|
r.public_keys.find_or_create_by(content: request.headers[:'X-Public-Key'])
end
end
# Procesa la transacción

8
app/models/public_key.rb Normal file
View file

@ -0,0 +1,8 @@
# frozen_string_literal: true
class PublicKey < ApplicationRecord
belongs_to :raspberry
validates_presence_of :content
validates_uniqueness_of :content
end

View file

@ -3,6 +3,7 @@
class Raspberry < ApplicationRecord
has_many :readings
has_many :arduinos
has_many :public_keys
validates_presence_of :name
validates_uniqueness_of :name

View file

@ -0,0 +1,28 @@
# frozen_string_literal: true
# Una Raspberry puede tener muchas llaves públicas
class CreatePublicKeys < ActiveRecord::Migration[6.1]
def up
create_table :public_keys, id: :uuid do |t|
t.timestamps
t.uuid :raspberry_id, index: true
t.string :content, null: false, unique: true
end
Raspberry.find_each do |r|
r.public_keys.create content: r.public_key
end
remove_column :raspberries, :public_key
end
def down
add_column :raspberries, :public_key, :string
Raspberry.find_each do |r|
r.update public_key: r.public_keys.first.public_key
end
drop_table :public_keys
end
end