Add basically API support

This commit is contained in:
uu59 2014-05-26 13:35:28 +09:00
parent 86a3e684b1
commit 9861f55ac9
10 changed files with 51 additions and 3 deletions

View File

@ -2,6 +2,7 @@ PATH
remote: .
specs:
fluentd-ui (0.0.1.pre)
addressable
bcrypt (~> 3.1.5)
bundler (~> 1.5)
coffee-rails (~> 4.0.0)

View File

@ -42,6 +42,6 @@ class FluentdController < ApplicationController
end
def fluentd_params
params.require(:fluentd).permit(:log_file, :pid_file, :config_file, :variant)
params.require(:fluentd).permit(:log_file, :pid_file, :config_file, :variant, :api_endpoint)
end
end

View File

@ -27,6 +27,10 @@ class Fluentd < ActiveRecord::Base
})
end
def api
@api ||= Api::Http.new(api_endpoint)
end
def label
"#{variant} ##{id}"
end

View File

@ -0,0 +1,6 @@
require "fluentd/api/http"
class Fluentd
class Api
end
end

View File

@ -0,0 +1,26 @@
require "httpclient"
require "addressable/uri"
class Fluentd
class Api
class Http
def initialize(endpoint)
@endpoint = Addressable::URI.parse(endpoint)
end
def config
request("/api/config.json")
end
private
def request(path)
uri = @endpoint.dup
uri.path = path
res = HTTPClient.get(uri)
JSON.parse res.body
end
end
end
end

View File

@ -15,4 +15,7 @@
%div.form-group
= f.label :config_file
= f.text_field :config_file, class: "form-control"
%div.form-group
= f.label :api_endpoint
= f.text_field :api_endpoint, class: "form-control"
= f.submit btn, class: "btn btn-primary"

View File

@ -126,3 +126,4 @@ ja:
pid_file: PIDファイル
config_file: 設定ファイル
variant: タイプ
api_endpoint: APIエンドポイント

View File

@ -0,0 +1,5 @@
class AddFluentdApiEndpoint < ActiveRecord::Migration
def change
add_column :fluentds, :api_endpoint, :string, default: "http://localhost:24220/"
end
end

View File

@ -11,15 +11,16 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140522055753) do
ActiveRecord::Schema.define(version: 20140526042609) do
create_table "fluentds", force: true do |t|
t.string "variant", null: false
t.string "variant", null: false
t.string "pid_file"
t.string "log_file"
t.string "config_file"
t.datetime "created_at"
t.datetime "updated_at"
t.string "api_endpoint", default: "http://localhost:24220/"
end
create_table "login_tokens", force: true do |t|

View File

@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'i18n_generators', '1.2.1'
spec.add_dependency 'bcrypt', '~> 3.1.5'
spec.add_dependency 'sqlite3'
spec.add_dependency 'addressable'
spec.add_dependency "font-awesome-rails"
spec.add_dependency 'sass-rails', '~> 4.0.3'
spec.add_dependency 'uglifier', '>= 1.3.0'