kebab_remote_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +43 -0
  3. data/CHANGELOG.md +89 -0
  4. data/CybeleInstallation.md +51 -0
  5. data/Gemfile +14 -0
  6. data/Gemfile.lock +95 -0
  7. data/MIT-LICENSE +22 -0
  8. data/README.md +41 -0
  9. data/Rakefile +34 -0
  10. data/SECURITY.md +7 -0
  11. data/app/controllers/kebab_remote_api/api/v1/server_info_controller.rb +8 -0
  12. data/app/controllers/kebab_remote_api/api/v1/sessions_controller.rb +52 -0
  13. data/app/controllers/kebab_remote_api/api/v1/users_controller.rb +14 -0
  14. data/app/controllers/kebab_remote_api/application_controller.rb +22 -0
  15. data/bin/rails +8 -0
  16. data/config/initializers/application_controller.rb +4 -0
  17. data/config/initializers/devise.rb +253 -0
  18. data/config/routes.rb +13 -0
  19. data/kebab_remote_api.gemspec +27 -0
  20. data/lib/application_responder.rb +8 -0
  21. data/lib/generators/kebab_remote_api/install/USAGE +8 -0
  22. data/lib/generators/kebab_remote_api/install/install_generator.rb +34 -0
  23. data/lib/generators/kebab_remote_api/install/templates/locales/kebab_remote_api.en.yml +26 -0
  24. data/lib/generators/kebab_remote_api/install/templates/locales/kebab_remote_api.tr.yml +29 -0
  25. data/lib/generators/kebab_remote_api/install/templates/migrations/api_key.rb +9 -0
  26. data/lib/generators/kebab_remote_api/install/templates/migrations/devise_columns.rb +5 -0
  27. data/lib/generators/kebab_remote_api/install/templates/migrations/enumerize.rb +6 -0
  28. data/lib/generators/kebab_remote_api/install/templates/migrations/server_info.rb +8 -0
  29. data/lib/generators/kebab_remote_api/install/templates/models/admin.rb +15 -0
  30. data/lib/generators/kebab_remote_api/install/templates/models/api_key.rb +11 -0
  31. data/lib/generators/kebab_remote_api/install/templates/models/server_info.rb +38 -0
  32. data/lib/generators/kebab_remote_api/install/templates/models/user.rb +19 -0
  33. data/lib/kebab_remote_api.rb +5 -0
  34. data/lib/kebab_remote_api/engine.rb +5 -0
  35. data/lib/kebab_remote_api/version.rb +3 -0
  36. data/lib/tasks/kebab_remote_api_tasks.rake +4 -0
  37. data/lib/user_sanitizer.rb +6 -0
  38. metadata +138 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27202b7d0dc73cacd11aa45a00bddb5a6ea05d28
4
+ data.tar.gz: 51a7d3515409dc30f5c14af4e2d16f088db6834b
5
+ SHA512:
6
+ metadata.gz: f5f52e722492fda58e2a1482113c4ed84006426b74513a4ddc9e50b84c05e4de30503ddf60f1f23f70be7b556397d73296ebeb9417397310a4dd416bed7a1ef6
7
+ data.tar.gz: d5b782cb5c2c32ecadcf961e90bf94c89af9915b7e04e815426f03ce781d5ed16523aac7d790cf776db2050690bf5c458b4d0073d7f250f63734a9eb4422b6a7
data/.gitignore ADDED
@@ -0,0 +1,43 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+ /test/dummy/db/*.sqlite3
14
+
15
+ # Ignore log
16
+ /log/*.log
17
+ /test/dummy/log
18
+
19
+ /tmp
20
+ /test/dummy/tmp
21
+ !.keep
22
+ *.swp
23
+ .env
24
+ bin/stubs
25
+ public/system
26
+ tags
27
+ vendor/bundler_gems
28
+
29
+ # Ignore ide and text editor
30
+ .idea
31
+
32
+ # Ignore pow files
33
+ .powrc
34
+
35
+ # Ignore mac files
36
+ .DS_Store
37
+
38
+ config/settings.local.yml
39
+ config/settings/*.local.yml
40
+ config/environments/*.local.yml
41
+
42
+ # Ignore Linux temp files
43
+ *~
data/CHANGELOG.md ADDED
@@ -0,0 +1,89 @@
1
+
2
+ #### [Current]
3
+ * [18facb0](../../commit/18facb0) - __(Ahmet Sezgin Duran)__ Clean up application controller
4
+ * [8316731](../../commit/8316731) - __(Ahmet Sezgin Duran)__ Remove unnecessary gems
5
+ * [4d7db82](../../commit/4d7db82) - __(Ahmet Sezgin Duran)__ Fix CybeleInstallation tutorial
6
+ * [9d7c1fe](../../commit/9d7c1fe) - __(Ahmet Sezgin Duran)__ Add Cybele installation tutorial
7
+
8
+ #### 0.2.1
9
+ * [a64aad8](../../commit/a64aad8) - __(Ahmet Sezgin Duran)__ [#12](../../issues/12) Fix admin variables in controllers
10
+ * [2b1430b](../../commit/2b1430b) - __(Ahmet Sezgin Duran)__ [#12](../../issues/12) Fix up generator and migration
11
+ * [221c566](../../commit/221c566) - __(Ahmet Sezgin Duran)__ [#12](../../issues/12) Fix model attributes
12
+ * [f0d709c](../../commit/f0d709c) - __(Ahmet Sezgin Duran)__ [#12](../../issues/12) Modify migration for admin's auth token
13
+ * [f869b9a](../../commit/f869b9a) - __(Ahmet Sezgin Duran)__ [#12](../../issues/12) Create admin model and clean up user model
14
+ * [1711214](../../commit/1711214) - __(Ahmet Sezgin Duran)__ [#12](../../issues/12) Modify session controller and bump version
15
+
16
+ #### 0.2.0
17
+ * [0fc4faa](../../commit/0fc4faa) - __(Ahmet Sezgin Duran)__ Bump version 0.2.0
18
+ * [54aa382](../../commit/54aa382) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Remove locales
19
+ * [3b965d0](../../commit/3b965d0) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Remove migrations
20
+ * [833e586](../../commit/833e586) - __(Ahmet Sezgin Duran)__ Bump version
21
+ * [4da1db0](../../commit/4da1db0) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Remove unnecessary files
22
+ * [261f3f5](../../commit/261f3f5) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Remove test files and dummy app
23
+ * [90ddf6c](../../commit/90ddf6c) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Update summary and description fields
24
+ * [cc97ec8](../../commit/cc97ec8) - __(Ahmet Sezgin Duran)__ Update gemspec file
25
+ * [913be44](../../commit/913be44) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Copy namespaced translations
26
+ * [cbd20fb](../../commit/cbd20fb) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Copy migrations with install generator
27
+ * [c2c692e](../../commit/c2c692e) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Create install generator and copy method
28
+ * [8b2bf4a](../../commit/8b2bf4a) - __(Ahmet Sezgin Duran)__ Fix Gemnasium badge
29
+ * [937a9c9](../../commit/937a9c9) - __(Ahmet Sezgin Duran)__ Add Gemnasium badge
30
+ * [d25af54](../../commit/d25af54) - __(Ahmet Sezgin Duran)__ Add Code Climate badge
31
+ * [857a554](../../commit/857a554) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Install Devise
32
+ * [b2712dd](../../commit/b2712dd) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Update gemspec for extra info
33
+ * [4a53628](../../commit/4a53628) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Handle syntax error
34
+ * [7334bb5](../../commit/7334bb5) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Move restrict_access method to application controller
35
+ * [33d500f](../../commit/33d500f) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Remove unused gems
36
+ * [f4aa074](../../commit/f4aa074) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Add namespace to I18n
37
+ * [8cb7765](../../commit/8cb7765) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Migrate translations from application
38
+ * [65d7a3b](../../commit/65d7a3b) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Migrate controllers from application
39
+ * [79cdabf](../../commit/79cdabf) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Add migrations
40
+ * [5f8767d](../../commit/5f8767d) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Add basic gems and ready up Devise
41
+ * [ce89714](../../commit/ce89714) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Update .gitignore to ignore dummy test app files
42
+ * [6ae78aa](../../commit/6ae78aa) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Change engine mount route to remote
43
+ * [5134e04](../../commit/5134e04) - __(Ahmet Sezgin Duran)__ [#7](../../issues/7) Create new mountable engine
44
+ * [4611d31](../../commit/4611d31) - __(Ahmet Sezgin Duran)__ Remove everthing
45
+ * [acb2d3d](../../commit/acb2d3d) - __(Ahmet Sezgin Duran)__ [#9](../../issues/9) Add version warning
46
+
47
+ #### 0.1.0
48
+ * [1c78ce4](../../commit/1c78ce4) - __(Ahmet Sezgin Duran)__ Bump version 0.1.0
49
+ * [206e33c](../../commit/206e33c) - __(Ahmet Sezgin Duran)__ [#9](../../issues/9) Fix wrong app name in Readme.md
50
+ * [2595e08](../../commit/2595e08) - __(Ahmet Sezgin Duran)__ [#9](../../issues/9) Update Readme.md and and license file
51
+ * [cd91c5b](../../commit/cd91c5b) - __(Ahmet Sezgin Duran)__ [#10](../../issues/10) Authenticate every request except session requests
52
+ * [42acf25](../../commit/42acf25) - __(Ahmet Sezgin Duran)__ Add SECURITY.md
53
+ * [65824b8](../../commit/65824b8) - __(Ahmet Sezgin Duran)__ [#2](../../issues/2) Use existing ApiKey object instead of getting from parameters
54
+ * [f2f30bd](../../commit/f2f30bd) - __(Ahmet Sezgin Duran)__ Add accessors and get first ApiKey object
55
+ * [3d8bf7f](../../commit/3d8bf7f) - __(Ahmet Sezgin Duran)__ [#3](../../issues/3) Create API_KEY constant
56
+ * [c957d65](../../commit/c957d65) - __(Ahmet Sezgin Duran)__ Merge success info on sessions controller
57
+ * [124f45e](../../commit/124f45e) - __(Ahmet Sezgin Duran)__ Reduce code mass of as_json method
58
+ * [986e977](../../commit/986e977) - __(Ahmet Sezgin Duran)__ Use unless instead of if-not
59
+ * [a4077cc](../../commit/a4077cc) - __(Ahmet Sezgin Duran)__ Fix comment line fb63e96
60
+ * [95839f3](../../commit/95839f3) - __(Ahmet Sezgin Duran)__ Remove migrations of server info attributes
61
+ * [fb63e96](../../commit/fb63e96) - __(Ahmet Sezgin Duran)__ Avoid saving server info
62
+ * [3f74c09](../../commit/3f74c09) - __(Ahmet Sezgin Duran)__ Delete server_info_helper.rb
63
+ * [1b13f95](../../commit/1b13f95) - __(Ahmet Sezgin Duran)__ Remove unused-empty helpers and TWS
64
+ * [bd20987](../../commit/bd20987) - __(Ahmet Sezgin Duran)__ Delete users_controller.rb
65
+ * [b6f6612](../../commit/b6f6612) - __(Ahmet Sezgin Duran)__ Remove trailing whitespaces
66
+ * [c6dca4e](../../commit/c6dca4e) - __(Ahmet Sezgin Duran)__ [#2](../../issues/2) Use hash mapping to get data dynamically
67
+ * [429377b](../../commit/429377b) - __(Ahmet Sezgin Duran)__ [#2](../../issues/2) Add default values to enumerize definitions
68
+ * [f50a907](../../commit/f50a907) - __(Ahmet Sezgin Duran)__ [#2](../../issues/2) Collect all controllers in Api-V1
69
+ * [40d122b](../../commit/40d122b) - __(Ahmet Sezgin Duran)__ [#3](../../issues/3) Add comment lines for some attributes
70
+ * [f3a7af8](../../commit/f3a7af8) - __(Ahmet Sezgin Duran)__ [#3](../../issues/3) Create migrations for server info attributes
71
+ * [17ca385](../../commit/17ca385) - __(Ahmet Sezgin Duran)__ [#3](../../issues/3) Create and implement server model & controller
72
+ * [336ea99](../../commit/336ea99) - __(Ahmet Sezgin Duran)__ [#1](../../issues/1) Move JSON data to User model
73
+ * [90cc992](../../commit/90cc992) - __(Ahmet Sezgin Duran)__ [#1](../../issues/1) Fix email parameter
74
+ * [7a26ec8](../../commit/7a26ec8) - __(Ahmet Sezgin Duran)__ [#1](../../issues/1) Use translations instead of hardcoded strings
75
+ * [17d5bf9](../../commit/17d5bf9) - __(Ahmet Sezgin Duran)__ [#3](../../issues/3) Get used disk and memory info (drop free info)
76
+ * [8a62167](../../commit/8a62167) - __(Ahmet Sezgin Duran)__ [#3](../../issues/3) Get disk usage info, in megabytes
77
+ * [709a0f4](../../commit/709a0f4) - __(Ahmet Sezgin Duran)__ [#3](../../issues/3) Change system info gem to Vmstat
78
+ * [86fbf8e](../../commit/86fbf8e) - __(Ahmet Sezgin Duran)__ [#3](../../issues/3) Get CPU average load data
79
+ * [8464022](../../commit/8464022) - __(Ahmet Sezgin Duran)__ [#3](../../issues/3) Create empty method get_server_info and link on routes.rb
80
+ * [515cf79](../../commit/515cf79) - __(Ahmet Sezgin Duran)__ [#2](../../issues/2) Render all user data formatted as JSON
81
+ * [1ea885e](../../commit/1ea885e) - __(Ahmet Sezgin Duran)__ [#2](../../issues/2) Add block status field
82
+ * [7b4abe5](../../commit/7b4abe5) - __(Ahmet Sezgin Duran)__ [#2](../../issues/2) Add migration and scoping for enumerized User model
83
+ * [fd6aa82](../../commit/fd6aa82) - __(Ahmet Sezgin Duran)__ [#2](../../issues/2) Add Enumerize gem for role management
84
+ * [d0cbd39](../../commit/d0cbd39) - __(Ahmet Sezgin Duran)__ Fix some notations
85
+ * [9798b74](../../commit/9798b74) - __(Ahmet Sezgin Duran)__ [#1](../../issues/1) Format JSON data as asked
86
+ * [6c0ce27](../../commit/6c0ce27) - __(Ahmet Sezgin Duran)__ [#1](../../issues/1) Create sessions controller and add routes
87
+ * [4d875ff](../../commit/4d875ff) - __(Ahmet Sezgin Duran)__ [#1](../../issues/1) Add authentication token attribute and migration
88
+ * [0b1921a](../../commit/0b1921a) - __(Ahmet Sezgin Duran)__ [#4](../../issues/4) Initialize project
89
+ * [5c9710d](../../commit/5c9710d) - __(Ahmet Sezgin Duran)__ Initial commit
@@ -0,0 +1,51 @@
1
+ # Installing Kebab Remote API on Cybele
2
+
3
+ First let's get to the home directory (on Linux or OSX):
4
+
5
+ ```
6
+ cd ~
7
+ ```
8
+
9
+ Clone the project:
10
+
11
+ ```
12
+ git clone https://github.com/kebab-project/kebab-remote-api
13
+ ```
14
+
15
+ Initialize a Rails application with Cybele:
16
+
17
+ ```
18
+ cybele foobar
19
+ ```
20
+
21
+ Switch to foobar folder and edit foobar's Gemfile:
22
+
23
+ ```
24
+ cd foobar
25
+ nano Gemfile
26
+ ```
27
+
28
+ Add the line:
29
+
30
+ ```
31
+ gem 'kebab_remote_api', path: '~/kebab-remote-api'
32
+ ```
33
+
34
+ Install the bundle:
35
+
36
+ ```
37
+ bundle install
38
+ ```
39
+
40
+ Run the installer:
41
+
42
+ ```
43
+ rails g kebab_remote_api:install
44
+ ```
45
+
46
+ It will show file conflicts, overwrite all of them. And run the migrations:
47
+
48
+ ```
49
+ rake db:migrate
50
+ ```
51
+
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in kebab_remote_api.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use debugger
14
+ # gem 'debugger'
data/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ kebab_remote_api (0.2.1)
5
+ enumerize (~> 0.7.0)
6
+ pg (~> 0.16.0)
7
+ rails (~> 4.0.0)
8
+ vmstat (~> 2.0.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionmailer (4.0.1)
14
+ actionpack (= 4.0.1)
15
+ mail (~> 2.5.4)
16
+ actionpack (4.0.1)
17
+ activesupport (= 4.0.1)
18
+ builder (~> 3.1.0)
19
+ erubis (~> 2.7.0)
20
+ rack (~> 1.5.2)
21
+ rack-test (~> 0.6.2)
22
+ activemodel (4.0.1)
23
+ activesupport (= 4.0.1)
24
+ builder (~> 3.1.0)
25
+ activerecord (4.0.1)
26
+ activemodel (= 4.0.1)
27
+ activerecord-deprecated_finders (~> 1.0.2)
28
+ activesupport (= 4.0.1)
29
+ arel (~> 4.0.0)
30
+ activerecord-deprecated_finders (1.0.3)
31
+ activesupport (4.0.1)
32
+ i18n (~> 0.6, >= 0.6.4)
33
+ minitest (~> 4.2)
34
+ multi_json (~> 1.3)
35
+ thread_safe (~> 0.1)
36
+ tzinfo (~> 0.3.37)
37
+ arel (4.0.1)
38
+ atomic (1.1.14)
39
+ builder (3.1.4)
40
+ enumerize (0.7.0)
41
+ activesupport (>= 3.2)
42
+ erubis (2.7.0)
43
+ hike (1.2.3)
44
+ i18n (0.6.5)
45
+ mail (2.5.4)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.25)
49
+ minitest (4.7.5)
50
+ multi_json (1.8.2)
51
+ pg (0.16.0)
52
+ polyglot (0.3.3)
53
+ rack (1.5.2)
54
+ rack-test (0.6.2)
55
+ rack (>= 1.0)
56
+ rails (4.0.1)
57
+ actionmailer (= 4.0.1)
58
+ actionpack (= 4.0.1)
59
+ activerecord (= 4.0.1)
60
+ activesupport (= 4.0.1)
61
+ bundler (>= 1.3.0, < 2.0)
62
+ railties (= 4.0.1)
63
+ sprockets-rails (~> 2.0.0)
64
+ railties (4.0.1)
65
+ actionpack (= 4.0.1)
66
+ activesupport (= 4.0.1)
67
+ rake (>= 0.8.7)
68
+ thor (>= 0.18.1, < 2.0)
69
+ rake (10.1.0)
70
+ sprockets (2.10.0)
71
+ hike (~> 1.2)
72
+ multi_json (~> 1.0)
73
+ rack (~> 1.0)
74
+ tilt (~> 1.1, != 1.3.0)
75
+ sprockets-rails (2.0.1)
76
+ actionpack (>= 3.0)
77
+ activesupport (>= 3.0)
78
+ sprockets (~> 2.8)
79
+ sqlite3 (1.3.8)
80
+ thor (0.18.1)
81
+ thread_safe (0.1.3)
82
+ atomic
83
+ tilt (1.4.1)
84
+ treetop (1.4.15)
85
+ polyglot
86
+ polyglot (>= 0.3.1)
87
+ tzinfo (0.3.38)
88
+ vmstat (2.0.0)
89
+
90
+ PLATFORMS
91
+ ruby
92
+
93
+ DEPENDENCIES
94
+ kebab_remote_api!
95
+ sqlite3
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 lab2023 - internet technologies
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Kebab Remote API
2
+
3
+ [![Code Climate](https://codeclimate.com/github/kebab-project/kebab-remote-api.png)](https://codeclimate.com/github/kebab-project/kebab-remote-api)
4
+ [![Dependency Status](https://gemnasium.com/kebab-project/kebab-remote-api.png)](https://gemnasium.com/kebab-project/kebab-remote-api)
5
+
6
+ ## Requirements
7
+
8
+ Before mounting Kebab Remote API to your application, you will need:
9
+
10
+ * Ruby ~> 2.0
11
+ * Rails ~> 4.0
12
+ * Cybele ~> 1.0.0
13
+
14
+ ## Usage
15
+
16
+ TODO: REST API documentation here
17
+
18
+ ## Bugs and Feedback
19
+
20
+ If you discover any bugs or want to drop a line, feel free to create an issue on Github
21
+
22
+ http://github.com/kebab-project/kebab-remote-api/issues
23
+
24
+ ## Contributing
25
+
26
+ Once you've made your great commits:
27
+
28
+ 1. Fork Template
29
+ 2. Create a topic branch - `git checkout -b my_branch`
30
+ 3. Push to your branch - `git push origin my_branch`
31
+ 4. Create a Pull Request from your branch
32
+ 5. That's it!
33
+
34
+ ## Credits
35
+
36
+ - Kebab Remote API is maintained and funded by [lab2023 - internet technologies](http://lab2023.com/)
37
+ - The names and logos for lab2023 are trademarks of lab2023, inc.
38
+
39
+ ## License
40
+
41
+ Copyright 2012 lab2023 – internet technologies
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'KebabRemoteApi'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
data/SECURITY.md ADDED
@@ -0,0 +1,7 @@
1
+ # Reporting Security Issues
2
+
3
+ If you discover a security issue in Kebab Remote API, please report it by sending an email to info@lab2023.com
4
+
5
+ This will allow us to assess the risk, and make a fix available before we add a bug report to the Github repo.
6
+
7
+ Thanks for helping make Kebab Remote API safe for everyone.
@@ -0,0 +1,8 @@
1
+ module KebabRemoteApi
2
+ class Api::V1::ServerInfoController < KebabRemoteApi::ApplicationController
3
+ def get_server_info
4
+ @info = ServerInfo.new
5
+ render status: 200, json: @info.as_json
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,52 @@
1
+ module KebabRemoteApi
2
+
3
+ class Api::V1::SessionsController < KebabRemoteApi::ApplicationController
4
+ skip_before_filter :verify_authenticity_token, :authenticate_request, :restrict_access
5
+ respond_to :json
6
+
7
+ def create
8
+ email = params[:email]
9
+ password = params[:password]
10
+
11
+ # Checking whether format is json or not
12
+ if request.format != :json
13
+ render status: 406, json: { message: I18n.t('kebab_remote_api.not_json') }
14
+ return
15
+ end
16
+
17
+ # Checking for empty email or password
18
+ if email.nil? or password.nil?
19
+ render status: 400, json: { message: I18n.t('kebab_remote_api.empty_input') }
20
+ return
21
+ end
22
+
23
+ @admin = Admin.where(email: email.downcase).first
24
+
25
+ # Checking whether user exists
26
+ if @admin.nil?
27
+ render status: 401, json: { message: I18n.t('kebab_remote_api.invalid_field') }
28
+ return
29
+ end
30
+
31
+ @admin.ensure_authentication_token!
32
+
33
+ # Finally, checking for password
34
+ unless @admin.valid_password?(password)
35
+ render status: 401, json: { message: I18n.t('kebab_remote_api.invalid_field') }
36
+ else
37
+ render status: 200, json: @admin.as_json.merge(success: true)
38
+ end
39
+ end
40
+
41
+ def destroy
42
+ @admin = Admin.find_by_authentication_token(params[:id])
43
+
44
+ if @admin.nil?
45
+ render status: 404, json: { message: I18n.t('kebab_remote_api.invalid_token') }
46
+ else
47
+ @admin.reset_authentication_token!
48
+ render status: 200, json: { token: params[:id] }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,14 @@
1
+ module KebabRemoteApi
2
+ class Api::V1::UsersController < KebabRemoteApi::ApplicationController
3
+ respond_to :json
4
+
5
+ def index
6
+ render status: 200, json: {
7
+ 'active_user' => User.with_block_status(:active).count,
8
+ 'total_user' => User.all.count,
9
+ 'total_user_by_role' => User.role.values.map { |role| { "role_name" => role.to_s,
10
+ "count" => User.with_role(role).count } }
11
+ }.to_json
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ module KebabRemoteApi
2
+ class ApplicationController < ActionController::Base
3
+ before_filter :authenticate_request, :restrict_access
4
+
5
+ respond_to :json
6
+
7
+ # Prevent CSRF attacks by raising an exception.
8
+ # For APIs, you may want to use :null_session instead.
9
+ protect_from_forgery with: :exception
10
+
11
+ protected
12
+ def authenticate_request
13
+ admin = Admin.find_by_authentication_token(params[:secret_token])
14
+ head :unauthorized unless admin
15
+ end
16
+
17
+ def restrict_access
18
+ api_key = ApiKey.first
19
+ head :unauthorized unless api_key
20
+ end
21
+ end
22
+ end
data/bin/rails ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/kebab_remote_api/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
@@ -0,0 +1,4 @@
1
+ if not defined?(ApplicationController)
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,253 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth.
2
+ # Many of these configuration options can be set straight in your model.
3
+ Devise.setup do |config|
4
+ # ==> Mailer Configuration
5
+ # Configure the e-mail address which will be shown in Devise::Mailer,
6
+ # note that it will be overwritten if you use your own mailer class with default "from" parameter.
7
+ config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
8
+
9
+ config.router_name = :kebab_remote_api
10
+ # Configure the class responsible to send e-mails.
11
+ # config.mailer = "Devise::Mailer"
12
+
13
+ # ==> ORM configuration
14
+ # Load and configure the ORM. Supports :active_record (default) and
15
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
16
+ # available as additional gems.
17
+ require 'devise/orm/active_record'
18
+
19
+ # ==> Configuration for any authentication mechanism
20
+ # Configure which keys are used when authenticating a user. The default is
21
+ # just :email. You can configure it to use [:username, :subdomain], so for
22
+ # authenticating a user, both parameters are required. Remember that those
23
+ # parameters are used only when authenticating and not when retrieving from
24
+ # session. If you need permissions, you should implement that in a before filter.
25
+ # You can also supply a hash where the value is a boolean determining whether
26
+ # or not authentication should be aborted when the value is not present.
27
+ # config.authentication_keys = [ :email ]
28
+
29
+ # Configure parameters from the request object used for authentication. Each entry
30
+ # given should be a request method and it will automatically be passed to the
31
+ # find_for_authentication method and considered in your model lookup. For instance,
32
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
33
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
34
+ # config.request_keys = []
35
+
36
+ # Configure which authentication keys should be case-insensitive.
37
+ # These keys will be downcased upon creating or modifying a user and when used
38
+ # to authenticate or find a user. Default is :email.
39
+ config.case_insensitive_keys = [ :email ]
40
+
41
+ # Configure which authentication keys should have whitespace stripped.
42
+ # These keys will have whitespace before and after removed upon creating or
43
+ # modifying a user and when used to authenticate or find a user. Default is :email.
44
+ config.strip_whitespace_keys = [ :email ]
45
+
46
+ # Tell if authentication through request.params is enabled. True by default.
47
+ # It can be set to an array that will enable params authentication only for the
48
+ # given strategies, for example, `config.params_authenticatable = [:database]` will
49
+ # enable it only for database (email + password) authentication.
50
+ # config.params_authenticatable = true
51
+
52
+ # Tell if authentication through HTTP Auth is enabled. False by default.
53
+ # It can be set to an array that will enable http authentication only for the
54
+ # given strategies, for example, `config.http_authenticatable = [:token]` will
55
+ # enable it only for token authentication. The supported strategies are:
56
+ # :database = Support basic authentication with authentication key + password
57
+ # :token = Support basic authentication with token authentication key
58
+ # :token_options = Support token authentication with options as defined in
59
+ # http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Token.html
60
+ # config.http_authenticatable = false
61
+
62
+ # If http headers should be returned for AJAX requests. True by default.
63
+ # config.http_authenticatable_on_xhr = true
64
+
65
+ # The realm used in Http Basic Authentication. "Application" by default.
66
+ # config.http_authentication_realm = "Application"
67
+
68
+ # It will change confirmation, password recovery and other workflows
69
+ # to behave the same regardless if the e-mail provided was right or wrong.
70
+ # Does not affect registerable.
71
+ # config.paranoid = true
72
+
73
+ # By default Devise will store the user in session. You can skip storage for
74
+ # :http_auth and :token_auth by adding those symbols to the array below.
75
+ # Notice that if you are skipping storage for all authentication paths, you
76
+ # may want to disable generating routes to Devise's sessions controller by
77
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
78
+ config.skip_session_storage = [:http_auth]
79
+
80
+ # By default, Devise cleans up the CSRF token on authentication to
81
+ # avoid CSRF token fixation attacks. This means that, when using AJAX
82
+ # requests for sign in and sign up, you need to get a new CSRF token
83
+ # from the server. You can disable this option at your own risk.
84
+ # config.clean_up_csrf_token_on_authentication = true
85
+
86
+ # ==> Configuration for :database_authenticatable
87
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
88
+ # using other encryptors, it sets how many times you want the password re-encrypted.
89
+ #
90
+ # Limiting the stretches to just one in testing will increase the performance of
91
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
92
+ # a value less than 10 in other environments.
93
+ config.stretches = Rails.env.test? ? 1 : 10
94
+
95
+ # Setup a pepper to generate the encrypted password.
96
+ # config.pepper = "bde1d04daa140c7da83dbec26f6e9f78d3df7e53041c11a374727516f517a7802d122555fb77b17efde1a998de7419e14454ea3bddaddeda4aa7fe463f7d582d"
97
+
98
+ # ==> Configuration for :confirmable
99
+ # A period that the user is allowed to access the website even without
100
+ # confirming his account. For instance, if set to 2.days, the user will be
101
+ # able to access the website for two days without confirming his account,
102
+ # access will be blocked just in the third day. Default is 0.days, meaning
103
+ # the user cannot access the website without confirming his account.
104
+ # config.allow_unconfirmed_access_for = 2.days
105
+
106
+ # A period that the user is allowed to confirm their account before their
107
+ # token becomes invalid. For example, if set to 3.days, the user can confirm
108
+ # their account within 3 days after the mail was sent, but on the fourth day
109
+ # their account can't be confirmed with the token any more.
110
+ # Default is nil, meaning there is no restriction on how long a user can take
111
+ # before confirming their account.
112
+ # config.confirm_within = 3.days
113
+
114
+ # If true, requires any email changes to be confirmed (exactly the same way as
115
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
116
+ # db field (see migrations). Until confirmed new email is stored in
117
+ # unconfirmed email column, and copied to email column on successful confirmation.
118
+ config.reconfirmable = true
119
+
120
+ # Defines which key will be used when confirming an account
121
+ # config.confirmation_keys = [ :email ]
122
+
123
+ # ==> Configuration for :rememberable
124
+ # The time the user will be remembered without asking for credentials again.
125
+ # config.remember_for = 2.weeks
126
+
127
+ # If true, extends the user's remember period when remembered via cookie.
128
+ # config.extend_remember_period = false
129
+
130
+ # Options to be passed to the created cookie. For instance, you can set
131
+ # :secure => true in order to force SSL only cookies.
132
+ # config.rememberable_options = {}
133
+
134
+ # ==> Configuration for :validatable
135
+ # Range for password length. Default is 8..128.
136
+ config.password_length = 8..128
137
+
138
+ # Email regex used to validate email formats. It simply asserts that
139
+ # one (and only one) @ exists in the given string. This is mainly
140
+ # to give user feedback and not to assert the e-mail validity.
141
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
142
+
143
+ # ==> Configuration for :timeoutable
144
+ # The time you want to timeout the user session without activity. After this
145
+ # time the user will be asked for credentials again. Default is 30 minutes.
146
+ # config.timeout_in = 30.minutes
147
+
148
+ # If true, expires auth token on session timeout.
149
+ # config.expire_auth_token_on_timeout = false
150
+
151
+ # ==> Configuration for :lockable
152
+ # Defines which strategy will be used to lock an account.
153
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
154
+ # :none = No lock strategy. You should handle locking by yourself.
155
+ # config.lock_strategy = :failed_attempts
156
+
157
+ # Defines which key will be used when locking and unlocking an account
158
+ # config.unlock_keys = [ :email ]
159
+
160
+ # Defines which strategy will be used to unlock an account.
161
+ # :email = Sends an unlock link to the user email
162
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
163
+ # :both = Enables both strategies
164
+ # :none = No unlock strategy. You should handle unlocking by yourself.
165
+ # config.unlock_strategy = :both
166
+
167
+ # Number of authentication tries before locking an account if lock_strategy
168
+ # is failed attempts.
169
+ # config.maximum_attempts = 20
170
+
171
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
172
+ # config.unlock_in = 1.hour
173
+
174
+ # ==> Configuration for :recoverable
175
+ #
176
+ # Defines which key will be used when recovering the password for an account
177
+ # config.reset_password_keys = [ :email ]
178
+
179
+ # Time interval you can reset your password with a reset password key.
180
+ # Don't put a too small interval or your users won't have the time to
181
+ # change their passwords.
182
+ config.reset_password_within = 6.hours
183
+
184
+ # ==> Configuration for :encryptable
185
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
186
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
187
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
188
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
189
+ # REST_AUTH_SITE_KEY to pepper).
190
+ #
191
+ # Require the `devise-encryptable` gem when using anything other than bcrypt
192
+ # config.encryptor = :sha512
193
+
194
+ # ==> Configuration for :token_authenticatable
195
+ # Defines name of the authentication token params key
196
+ # config.token_authentication_key = :auth_token
197
+
198
+ # ==> Scopes configuration
199
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
200
+ # "users/sessions/new". It's turned off by default because it's slower if you
201
+ # are using only default views.
202
+ # config.scoped_views = false
203
+
204
+ # Configure the default scope given to Warden. By default it's the first
205
+ # devise role declared in your routes (usually :user).
206
+ # config.default_scope = :user
207
+
208
+ # Set this configuration to false if you want /users/sign_out to sign out
209
+ # only the current scope. By default, Devise signs out all scopes.
210
+ # config.sign_out_all_scopes = true
211
+
212
+ # ==> Navigation configuration
213
+ # Lists the formats that should be treated as navigational. Formats like
214
+ # :html, should redirect to the sign in page when the user does not have
215
+ # access, but formats like :xml or :json, should return 401.
216
+ #
217
+ # If you have any extra navigational formats, like :iphone or :mobile, you
218
+ # should add them to the navigational formats lists.
219
+ #
220
+ # The "*/*" below is required to match Internet Explorer requests.
221
+ # config.navigational_formats = ["*/*", :html]
222
+
223
+ # The default HTTP method used to sign out a resource. Default is :delete.
224
+ config.sign_out_via = :delete
225
+
226
+ # ==> OmniAuth
227
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
228
+ # up on your models and hooks.
229
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
230
+
231
+ # ==> Warden configuration
232
+ # If you want to use other strategies, that are not supported by Devise, or
233
+ # change the failure app, you can configure them inside the config.warden block.
234
+ #
235
+ # config.warden do |manager|
236
+ # manager.intercept_401 = false
237
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
238
+ # end
239
+
240
+ # ==> Mountable engine configurations
241
+ # When using Devise inside an engine, let's call it `MyEngine`, and this engine
242
+ # is mountable, there are some extra configurations to be taken into account.
243
+ # The following options are available, assuming the engine is mounted as:
244
+ #
245
+ # mount MyEngine, at: "/my_engine"
246
+ #
247
+ # The router that invoked `devise_for`, in the example above, would be:
248
+ # config.router_name = :my_engine
249
+ #
250
+ # When using omniauth, Devise cannot automatically set Omniauth path,
251
+ # so you need to do it manually. For the users scope, it would be:
252
+ # config.omniauth_path_prefix = "/my_engine/users/auth"
253
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,13 @@
1
+ KebabRemoteApi::Engine.routes.draw do
2
+
3
+ namespace :api do
4
+
5
+ namespace :v1 do
6
+ resources :users, only: [:index], defaults: { format: 'json' }
7
+ resources :sessions, only: [:create, :destroy], defaults: { format: 'json' }
8
+ match "server_info", to: "server_info#get_server_info", via: [:get], defaults: { format: 'json' }
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,27 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "kebab_remote_api/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "kebab_remote_api"
9
+ s.version = KebabRemoteApi::VERSION
10
+ s.authors = %w[lab2023]
11
+ s.email = %w[info@lab2023.com]
12
+ s.homepage = "https://github.com/kebab-project/kebab-remote-api"
13
+ s.summary = %q{This is a JSON data sender gem for a Cybele initialized Rails project.}
14
+ s.description = %q{Kebab Remote API is a gem that sends spesific server data through JSON.}
15
+ s.license = 'MIT'
16
+ s.extra_rdoc_files = %w[README.md SECURITY.md]
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
+ s.require_paths = %w[lib]
21
+
22
+ s.add_dependency "rails", "~> 4.0.0"
23
+ s.add_dependency 'enumerize', '~> 0.7.0'
24
+ s.add_dependency 'vmstat', '~> 2.0.0'
25
+
26
+ s.add_development_dependency "sqlite3"
27
+ end
@@ -0,0 +1,8 @@
1
+ class ApplicationResponder < ActionController::Responder
2
+ include Responders::FlashResponder
3
+ include Responders::HttpCacheResponder
4
+
5
+ # Uncomment this responder if you want your resources to redirect to the collection
6
+ # path (index action) instead of the resource path for POST/PUT/DELETE requests.
7
+ # include Responders::CollectionResponder
8
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate install Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,34 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/base'
3
+ require 'rails/generators/migration'
4
+ require 'rails/generators/active_record'
5
+
6
+ module KebabRemoteApi
7
+ module Generators
8
+ class InstallGenerator < Rails::Generators::Base
9
+ include Rails::Generators::Migration
10
+
11
+ desc "Copies KebabRemoteApi models, migrations and locales"
12
+ source_root File.expand_path('../templates', __FILE__)
13
+
14
+ def copy_models
15
+ directory 'models', 'app/models'
16
+ end
17
+
18
+ def self.next_migration_number(dirname)
19
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
20
+ end
21
+
22
+ def create_migration_file
23
+ migration_template 'migrations/api_key.rb', 'db/migrate/create_api_keys.rb' rescue nil
24
+ migration_template 'migrations/devise_columns.rb', 'db/migrate/add_devise_columns_to_admins.rb' rescue nil
25
+ migration_template 'migrations/enumerize.rb', 'db/migrate/add_enumerize_columns_to_user.rb' rescue nil
26
+ migration_template 'migrations/server_info.rb', 'db/migrate/create_server_infos.rb' rescue nil
27
+ end
28
+
29
+ def copy_locales
30
+ directory 'locales', 'config/locales'
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ kebab_remote_api:
24
+ not_json: 'Type of the request must be JSON'
25
+ empty_input: "The request must contain the user's email and password"
26
+ invalid_field: 'Invalid email or password'
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Files in the config/locales directory are used for internationalization
4
+ # and are automatically loaded by Rails. If you want to use locales other
5
+ # than English, add the necessary files in this directory.
6
+ #
7
+ # To use the locales, use `I18n.t`:
8
+ #
9
+ # I18n.t 'hello'
10
+ #
11
+ # In views, this is aliased to just `t`:
12
+ #
13
+ # <%= t('hello') %>
14
+ #
15
+ # To use a different locale, set it with `I18n.locale`:
16
+ #
17
+ # I18n.locale = :es
18
+ #
19
+ # This would use the information in config/locales/es.yml.
20
+ #
21
+ # To learn more, please read the Rails Internationalization guide
22
+ # available at http://guides.rubyonrails.org/i18n.html.
23
+
24
+ tr:
25
+ kebab_remote_api:
26
+ not_json: 'İstek JSON tipinde olmalıdır.'
27
+ empty_input: 'İstek kullanıcının e-postasını ve parolasını içermelidir.'
28
+ invalid_field: 'Yanlış e-posta veya parola'
29
+
@@ -0,0 +1,9 @@
1
+ class CreateApiKeys < ActiveRecord::Migration
2
+ def change
3
+ create_table :api_keys do |t|
4
+ t.string :access_token
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class AddDeviseColumnsToAdmins < ActiveRecord::Migration
2
+ def change
3
+ add_column :admins, :authentication_token, :string
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddEnumerizeColumnsToUser < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :role, :integer
4
+ add_column :users, :block_status, :integer
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ class CreateServerInfos < ActiveRecord::Migration
2
+ def change
3
+ create_table :server_infos do |t|
4
+
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ class Admin < ActiveRecord::Base
2
+ # Include default devise modules. Others available are:
3
+ # :token_authenticatable, :confirmable,
4
+ # :lockable, :timeoutable and :omniauthable
5
+ devise :database_authenticatable,
6
+ :recoverable, :rememberable, :trackable, :validatable,
7
+ :token_authenticatable
8
+
9
+ def as_json
10
+ { id: id,
11
+ auth_token: authentication_token,
12
+ email: email
13
+ }
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ class ApiKey < ActiveRecord::Base
2
+ before_create :generate_access_token
3
+
4
+ private
5
+
6
+ def generate_access_token
7
+ begin
8
+ self.access_token = SecureRandom.hex
9
+ end while self.class.exists?(access_token: access_token)
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ require 'vmstat'
2
+
3
+ class ServerInfo < ActiveRecord::Base
4
+ after_initialize :init
5
+ attr_accessor :cpu_load, :mem_total, :mem_used, :disk_total, :disk_used, :uptime
6
+
7
+ def init
8
+ mem = Vmstat.memory
9
+ total_mem = mem.active_bytes + mem.inactive_bytes + mem.free_bytes + mem.wired_bytes
10
+ # Getting disk info for main partition is, temprorarily, for only
11
+ # UN*X-like systems, such as GNU/Linux, BSD, Mac OS X etc.
12
+ # Windows implementation will be added in future
13
+ disk = Vmstat.disk('/')
14
+ # CPU load data => Float typed
15
+ self.cpu_load = Vmstat.load_average.five_minutes
16
+ # All size data => Megabytes (MB)
17
+ self.mem_total = (mem.active_bytes + mem.inactive_bytes + mem.free_bytes + mem.wired_bytes) / 1024**2
18
+ self.mem_used = self.mem_total - (mem.free_bytes / 1024**2)
19
+ self.disk_total = disk.total_bytes / 1024**2
20
+ self.disk_used = (disk.total_bytes - disk.free_bytes) / 1024**2
21
+ # Uptime data => Minutes
22
+ self.uptime = (Time.now - Vmstat.boot_time).to_i / 60
23
+ end
24
+
25
+ def as_json
26
+ { "CPU" => self.cpu_load,
27
+ "Memory" => {
28
+ "Total" => self.mem_total,
29
+ "Used" => self.mem_used,
30
+ },
31
+ "Disk" => {
32
+ "Total" => self.disk_total,
33
+ "Used" => self.disk_used
34
+ },
35
+ "Uptime" => self.uptime
36
+ }.to_json
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ class User < ActiveRecord::Base
2
+ extend Enumerize
3
+ # Include default devise modules. Others available are:
4
+ # :token_authenticatable, :confirmable,
5
+ # :lockable, :timeoutable and :omniauthable
6
+ devise :database_authenticatable, :registerable,
7
+ :recoverable, :rememberable, :trackable, :validatable
8
+
9
+ enumerize :role, in: { admin: 1, user: 2, editor: 3 }, scope: true, default: :user
10
+ enumerize :block_status, in: { active: 1, blocked: 2 }, scope: true, default: :active
11
+ # Example creation of User with role
12
+ # new_user = User.create(email: 'blabla@bla.com', password: '12345678', role: :user)
13
+ #
14
+ # Checking role:
15
+ # new_user.role.editor? (returns true or false)
16
+ #
17
+ # Selecting all users with given role (A.K.A. scoping):
18
+ # User.with_role(:editor)
19
+ end
@@ -0,0 +1,5 @@
1
+ require "kebab_remote_api/engine"
2
+ require 'enumerize'
3
+
4
+ module KebabRemoteApi
5
+ end
@@ -0,0 +1,5 @@
1
+ module KebabRemoteApi
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace KebabRemoteApi
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module KebabRemoteApi
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :kebab_remote_api do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,6 @@
1
+ class User::ParameterSanitizer < Devise::ParameterSanitizer
2
+ private
3
+ def sign_up
4
+ default_params.permit(:name, :email, :password, :password_confirmation) # TODO add other params here
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kebab_remote_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - lab2023
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: enumerize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: vmstat
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Kebab Remote API is a gem that sends spesific server data through JSON.
70
+ email:
71
+ - info@lab2023.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - README.md
76
+ - SECURITY.md
77
+ files:
78
+ - .gitignore
79
+ - CHANGELOG.md
80
+ - CybeleInstallation.md
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - MIT-LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - SECURITY.md
87
+ - app/controllers/kebab_remote_api/api/v1/server_info_controller.rb
88
+ - app/controllers/kebab_remote_api/api/v1/sessions_controller.rb
89
+ - app/controllers/kebab_remote_api/api/v1/users_controller.rb
90
+ - app/controllers/kebab_remote_api/application_controller.rb
91
+ - bin/rails
92
+ - config/initializers/application_controller.rb
93
+ - config/initializers/devise.rb
94
+ - config/routes.rb
95
+ - kebab_remote_api.gemspec
96
+ - lib/application_responder.rb
97
+ - lib/generators/kebab_remote_api/install/USAGE
98
+ - lib/generators/kebab_remote_api/install/install_generator.rb
99
+ - lib/generators/kebab_remote_api/install/templates/locales/kebab_remote_api.en.yml
100
+ - lib/generators/kebab_remote_api/install/templates/locales/kebab_remote_api.tr.yml
101
+ - lib/generators/kebab_remote_api/install/templates/migrations/api_key.rb
102
+ - lib/generators/kebab_remote_api/install/templates/migrations/devise_columns.rb
103
+ - lib/generators/kebab_remote_api/install/templates/migrations/enumerize.rb
104
+ - lib/generators/kebab_remote_api/install/templates/migrations/server_info.rb
105
+ - lib/generators/kebab_remote_api/install/templates/models/admin.rb
106
+ - lib/generators/kebab_remote_api/install/templates/models/api_key.rb
107
+ - lib/generators/kebab_remote_api/install/templates/models/server_info.rb
108
+ - lib/generators/kebab_remote_api/install/templates/models/user.rb
109
+ - lib/kebab_remote_api.rb
110
+ - lib/kebab_remote_api/engine.rb
111
+ - lib/kebab_remote_api/version.rb
112
+ - lib/tasks/kebab_remote_api_tasks.rake
113
+ - lib/user_sanitizer.rb
114
+ homepage: https://github.com/kebab-project/kebab-remote-api
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.1.10
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: This is a JSON data sender gem for a Cybele initialized Rails project.
138
+ test_files: []