Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Policy backend branch part of issue #24 #60

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
ee7e3ef
Created db models and configured app
DoRTaL94 Apr 10, 2020
1b7aaf8
adding .gitignore
ahinoamta Apr 11, 2020
345daf4
editing the models User, Token and ResponseUser
ahinoamta Apr 11, 2020
1bf76b8
adding db_hanlder
ahinoamta Apr 11, 2020
92482f1
Updating db handler
DoRTaL94 Apr 11, 2020
5bde4d5
Added required packages to setup.sh and forwarded additional port for…
DoRTaL94 Apr 11, 2020
daf8484
added new line
ahinoamta Apr 12, 2020
82e7381
Merge branch 'master' into user-management
ahinoamta Apr 12, 2020
4a1e0ce
added necessary packages to requirements.txt file
ahinoamta Apr 12, 2020
ba95634
CR fixes
ahinoamta Apr 12, 2020
aeac940
Modified user, db_handler and token files
DoRTaL94 Apr 12, 2020
9580175
added abstract base class BaseStorageHandler that DbHandler derives from
ahinoamta Apr 13, 2020
21dad4f
Fixed token query
DoRTaL94 Apr 14, 2020
e605ac5
Modified generic dbhandler
DoRTaL94 Apr 15, 2020
ced0fc6
Added packages versions in requirements file
DoRTaL94 Apr 15, 2020
24650eb
Changed flask_init name
DoRTaL94 Apr 16, 2020
fa860bb
Moved to standard way of configuring DB connection string
DoRTaL94 Apr 16, 2020
75f3a5c
Removed unnecessary DBHandler.
DoRTaL94 Apr 16, 2020
54500cc
Added config file
DoRTaL94 Apr 16, 2020
f6c312f
Fixed token model repr function
DoRTaL94 Apr 20, 2020
61e4b1c
Updated setup.sh and changed app file name
DoRTaL94 Apr 16, 2020
7deba85
created test that verifies application is running
timshik Apr 18, 2020
9937b84
Restructured project layout
DoRTaL94 Apr 21, 2020
922a891
Merged both flask servers into one
DoRTaL94 Apr 21, 2020
2f2d231
Added use of Flask-Migrate extension
DoRTaL94 Apr 21, 2020
8fb4f37
Changed Vagrantfile
DoRTaL94 Apr 16, 2020
93122d9
Updated gitignore
DoRTaL94 Apr 20, 2020
a0ad329
post new policy
omrico94 May 1, 2020
f8b4999
change file name
omrico94 May 2, 2020
e077ff4
added policy res
omrico94 May 2, 2020
d575a7f
added policy res
omrico94 May 5, 2020
ce12eab
fix code add new policy
omrico94 May 5, 2020
3821a21
change code policy res
omrico94 May 5, 2020
8cbf8c0
add relation between user and policy
omrico94 May 6, 2020
f90e31a
add relation between user and policy
omrico94 May 8, 2020
36c1fd9
add name to msg in mew policy
omrico94 May 8, 2020
b5f44ec
add get all policies
omrico94 May 12, 2020
c94df9c
change message
omrico94 May 12, 2020
b3cd321
merge parser
omrico94 May 13, 2020
846cd89
before changing from policy_name routing to policy_id
omrico94 May 15, 2020
82f1340
delete newPolicy resource and add post function to policy resource
omrico94 May 19, 2020
9fe3731
merge master from origin knowabli/edison
omrico94 May 27, 2020
35c3134
separate from user managments pr's
omrico94 May 27, 2020
a052f71
separate from user managments pr's
omrico94 May 31, 2020
b10308f
Delete .DS_Store
omrico94 May 31, 2020
ea74417
separate from user managments pr's
omrico94 May 31, 2020
9e9f3ae
Merge remote-tracking branch 'origin/policyBackendBranch' into policy…
omrico94 May 31, 2020
b067022
Merge branch 'master' into policyBackendBranch
omrico94 Jun 1, 2020
4b4007c
Merge branch 'master' into policyBackendBranch
omrico94 Jun 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/edisonCI.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Vagrant stuff
acceptance_config.yml
boxes/*
Expand All @@ -13,9 +14,11 @@ test/vagrant-spec/.vagrant/
# IDE
_pycache_/
.idea/*
.DS_Store

# Python
*.pyc
*.orig
*.pyc.*
/.cache

2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

454 changes: 454 additions & 0 deletions .idea/dbnavigator.xml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions .idea/edison.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2020 Roni Rushkin Elharar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2020 Roni Rushkin Elharar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
112 changes: 56 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
# Edison - Automated house managment

### Overview

Edison is an open-source home management system.
In its core, Edison is a regular automatic home management system: it reads data from humidity and light sensors and decides when to turn on the air condition and turn on the lights in different rooms.

Edison allows users to write their own house management plans.
Users can share their management plans through the Edison network and users can also download and review plans from other users.

Edison can also manage different sensors from different rooms with different management plans for each room.

## How to spin and tear down the environment

Edison makes the initial setup easy for you by including a provisioner file that runs automatically on **`vagrant up`**.
You will have a fully ready-to-go work environment with a single command.

### How to get started

- Download the proper [VirtualBox](https://www.virtualbox.org/wiki/Downloads) and [Vagrant](https://www.vagrantup.com/downloads.html) package for your operating system and architecture.
- Download Edison to your machine and then open a console window on *edison* folder.
- Write **`vagrant up`** and press enter.
- That's it! Your virtual machine is up and running.
You can enter your virtual machine with **`vagrant ssh`**.
> **Important!** In case that, after `vagrant ssh`, your virtual machine asks for a password the default password is `vagrant`.

### How to save virtual machine state

In order for your next **`vagrant up`** to execute quicker you should save your virtual machine state into a box file format.

- If you are inside the virtual machine write **`exit`** and press enter. Now you are back on your host command line.
- Write **`vagrant halt`** and press enter.
> **Note:** It will shut down the running machine Vagrant is managing.
- Write **`vagrant package --output box-name.box`** and press enter. You can replace *box-name* with any name you want.
> **Note:** It will output your virtual machine into a box file format with .box extension.
- Write **`vagrant box add box-name box-name.box`** and press enter.
Make sure you replaced *box-name* with the name you have chosen on the previous step.
- Edit *Vagrantfile* inside the *edison* folder.
Change the following line `config.vm.box = "ubuntu/xenial64"` to `config.vm.box = "box-name"` (replace *box-name* with the name of the box you have created).
- Run **`vagrant up --no-provision`** on future spins.

### How to tear down the environment

- If you are inside your virtual machine execute the **`exit`** command so you would get back to your host command line.
- Write **`vagrant destroy -f`** and press enter. It sould terminate your virtual machine.
> **Important!** If you have some unsaved work on your virtual machine your data will be lost! In order to save your data you should follow the steps we provided on **How to save virtual machine state**.

## FAQ

Here are some answers to some frequently asked questions:

**Why does `vagrant up` take so long ?**
If you don't have a box to spin your environment from, **`vagrant up`** will take longer to be done.
As part of this command execution our included file `setup.sh` starts to execute and configure Edison environment inside the virtual machine. It downloads all the dependencies Edison requires to run.

**What is box file format ?**
# Edison - Automated house managment
### Overview
Edison is an open-source home management system.
In its core, Edison is a regular automatic home management system: it reads data from humidity and light sensors and decides when to turn on the air condition and turn on the lights in different rooms.
Edison allows users to write their own house management plans.
Users can share their management plans through the Edison network and users can also download and review plans from other users.
Edison can also manage different sensors from different rooms with different management plans for each room.
## How to spin and tear down the environment
Edison makes the initial setup easy for you by including a provisioner file that runs automatically on **`vagrant up`**.
You will have a fully ready-to-go work environment with a single command.
### How to get started
- Download the proper [VirtualBox](https://www.virtualbox.org/wiki/Downloads) and [Vagrant](https://www.vagrantup.com/downloads.html) package for your operating system and architecture.
- Download Edison to your machine and then open a console window on *edison* folder.
- Write **`vagrant up`** and press enter.
- That's it! Your virtual machine is up and running.
You can enter your virtual machine with **`vagrant ssh`**.
> **Important!** In case that, after `vagrant ssh`, your virtual machine asks for a password the default password is `vagrant`.
### How to save virtual machine state
In order for your next **`vagrant up`** to execute quicker you should save your virtual machine state into a box file format.
- If you are inside the virtual machine write **`exit`** and press enter. Now you are back on your host command line.
- Write **`vagrant halt`** and press enter.
> **Note:** It will shut down the running machine Vagrant is managing.
- Write **`vagrant package --output box-name.box`** and press enter. You can replace *box-name* with any name you want.
> **Note:** It will output your virtual machine into a box file format with .box extension.
- Write **`vagrant box add box-name box-name.box`** and press enter.
Make sure you replaced *box-name* with the name you have chosen on the previous step.
- Edit *Vagrantfile* inside the *edison* folder.
Change the following line `config.vm.box = "ubuntu/xenial64"` to `config.vm.box = "box-name"` (replace *box-name* with the name of the box you have created).
- Run **`vagrant up --no-provision`** on future spins.
### How to tear down the environment
- If you are inside your virtual machine execute the **`exit`** command so you would get back to your host command line.
- Write **`vagrant destroy -f`** and press enter. It sould terminate your virtual machine.
> **Important!** If you have some unsaved work on your virtual machine your data will be lost! In order to save your data you should follow the steps we provided on **How to save virtual machine state**.
## FAQ
Here are some answers to some frequently asked questions:
**Why does `vagrant up` take so long ?**
If you don't have a box to spin your environment from, **`vagrant up`** will take longer to be done.
As part of this command execution our included file `setup.sh` starts to execute and configure Edison environment inside the virtual machine. It downloads all the dependencies Edison requires to run.
**What is box file format ?**
Please read [box file format](https://www.vagrantup.com/docs/boxes/format.html) documentation for more information.
74 changes: 37 additions & 37 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
db_file_exists = "test -f /vagrant/edison/db.sql"
restore_db = "sudo -u postgres psql edison < /vagrant/edison/db.sql"
db_restored_msg = "echo \"Database restored.\""
db_not_exists_msg = "echo \"db.sql not exists.\""
try_restore_db = "bash -c '#{db_file_exists} && #{restore_db} && #{db_restored_msg} || #{db_not_exists_msg}'"
save_db_data = "sudo -u postgres pg_dump edison > /vagrant/edison/db.sql"

Vagrant.configure("2") do |config|
config.trigger.before :destroy do |trigger|
trigger.info = "Saving database data inside synced folder..."
trigger.run_remote = {inline: "#{save_db_data}"}
end

config.trigger.after :up do |trigger|
trigger.info = "Trying to restore database from /vagrant/edison/db.sql..."
trigger.run_remote = {inline: "#{try_restore_db}"}
end

config.vm.box = "ubuntu/bionic64"
config.vm.provision :shell, path: "setup.sh"
config.vm.network "private_network", type: "dhcp"
config.vm.provider "virtualbox" do |v|
v.gui = false
v.name = "Edison_test"
v.memory = 1024
v.cpus = 2
end

end

# Fixes a dhcp configuration conflict of the private network.
# Issue: https://github.com/hashicorp/vagrant/issues/8878
class VagrantPlugins::ProviderVirtualBox::Action::Network
def dhcp_server_matches_config?(dhcp_server, config)
true
end
end
db_file_exists = "test -f /vagrant/edison/db.sql"
restore_db = "sudo -u postgres psql edison < /vagrant/edison/db.sql"
db_restored_msg = "echo \"Database restored.\""
db_not_exists_msg = "echo \"db.sql not exists.\""
try_restore_db = "bash -c '#{db_file_exists} && #{restore_db} && #{db_restored_msg} || #{db_not_exists_msg}'"
save_db_data = "sudo -u postgres pg_dump edison > /vagrant/edison/db.sql"
Vagrant.configure("2") do |config|
config.trigger.before :destroy do |trigger|
trigger.info = "Saving database data inside synced folder..."
trigger.run_remote = {inline: "#{save_db_data}"}
end
config.trigger.after :up do |trigger|
trigger.info = "Trying to restore database from /vagrant/edison/db.sql..."
trigger.run_remote = {inline: "#{try_restore_db}"}
end
config.vm.box = "ubuntu/bionic64"
config.vm.provision :shell, path: "setup.sh"
config.vm.network "private_network", type: "dhcp"
config.vm.provider "virtualbox" do |v|
v.gui = false
v.name = "Edison_test"
v.memory = 1024
v.cpus = 2
end
end
# Fixes a dhcp configuration conflict of the private network.
# Issue: https://github.com/hashicorp/vagrant/issues/3083
class VagrantPlugins::ProviderVirtualBox::Action::Network
def dhcp_server_matches_config?(dhcp_server, config)
true
end
end
24 changes: 12 additions & 12 deletions edison/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from edison.config import get_config_object


# Put app here so the entire app could import it.
app = Flask(__name__)
app.config.from_object(get_config_object(app.config["ENV"]))
basedir = os.path.abspath(os.path.dirname(__file__))
db = SQLAlchemy(app)
import os
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from edison.config import get_config_object
# Put app and db here so the entire app could import them.
app = Flask(__name__)
app.config.from_object(get_config_object(app.config["ENV"]))
basedir = os.path.abspath(os.path.dirname(__file__))
db = SQLAlchemy(app)
Loading