Compare commits
2 commits
833307d9e6
...
6598246076
Author | SHA1 | Date | |
---|---|---|---|
|
6598246076 | ||
|
07eb3108ff |
5 changed files with 42 additions and 2 deletions
|
@ -5,7 +5,7 @@ ARG RUBY_PATCH=5
|
||||||
FROM ${BASE_IMAGE}:${ALPINE_VERSION}-${RUBY_VERSION}.${RUBY_PATCH}
|
FROM ${BASE_IMAGE}:${ALPINE_VERSION}-${RUBY_VERSION}.${RUBY_PATCH}
|
||||||
ENV RAILS_ENV production
|
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"
|
VOLUME "/srv"
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,11 @@ class ReadingsController < ActionController::API
|
||||||
head :bad_request
|
head :bad_request
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Registra una Raspberry junto con su llave pública
|
||||||
def raspberry
|
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
|
end
|
||||||
|
|
||||||
# Procesa la transacción
|
# Procesa la transacción
|
||||||
|
|
8
app/models/public_key.rb
Normal file
8
app/models/public_key.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class PublicKey < ApplicationRecord
|
||||||
|
belongs_to :raspberry
|
||||||
|
|
||||||
|
validates_presence_of :content
|
||||||
|
validates_uniqueness_of :content
|
||||||
|
end
|
|
@ -3,6 +3,7 @@
|
||||||
class Raspberry < ApplicationRecord
|
class Raspberry < ApplicationRecord
|
||||||
has_many :readings
|
has_many :readings
|
||||||
has_many :arduinos
|
has_many :arduinos
|
||||||
|
has_many :public_keys
|
||||||
|
|
||||||
validates_presence_of :name
|
validates_presence_of :name
|
||||||
validates_uniqueness_of :name
|
validates_uniqueness_of :name
|
||||||
|
|
28
db/migrate/20220312183608_create_public_keys.rb
Normal file
28
db/migrate/20220312183608_create_public_keys.rb
Normal 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
|
Loading…
Reference in a new issue