safedb 0.7.1001 → 0.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +50 -3
- data/Dockerfile +46 -0
- data/Jenkinsfile +45 -0
- data/README.md +16 -0
- data/Rakefile +2 -2
- data/cucumber-test.sh +55 -0
- data/lib/cli.rb +20 -7
- data/lib/controller/abstract/controller.rb +2 -3
- data/lib/controller/access/init.rb +11 -7
- data/lib/controller/access/login.rb +0 -2
- data/lib/controller/book/commit.rb +1 -0
- data/lib/controller/db/obliterate.feature +45 -0
- data/lib/controller/db/obliterate.rb +58 -0
- data/lib/controller/db/pull.rb +10 -26
- data/lib/controller/db/push.rb +29 -321
- data/lib/controller/db/{remote.rb → remote-github-keypair.rb} +11 -6
- data/lib/controller/db/remote-github-token.rb +69 -0
- data/lib/controller/db/state.rb +63 -0
- data/lib/controller/query/publish.rb +27 -0
- data/lib/controller/requirer.rb +0 -1
- data/lib/manual/git-interaction.md +176 -0
- data/lib/manual/remote.md +0 -1
- data/lib/model/book.rb +13 -1
- data/lib/model/checkin.feature +15 -27
- data/lib/model/content.rb +25 -27
- data/lib/model/indices.rb +35 -8
- data/lib/model/state_evolve.rb +21 -0
- data/lib/model/text_chunk.rb +1 -1
- data/lib/utils/extend/string.rb +28 -0
- data/lib/utils/git/gitflow.rb +565 -0
- data/lib/utils/git/github.rb +69 -0
- data/lib/utils/identity/machine.id.rb +2 -2
- data/lib/utils/keys/keypair.rb +93 -0
- data/lib/utils/logs/logger.rb +3 -4
- data/lib/utils/time/timestamp.rb +2 -0
- data/lib/version.rb +1 -1
- data/pod-image-builder.yaml +27 -0
- data/pod-image-safetty.yaml +18 -0
- data/safedb.gemspec +1 -6
- metadata +17 -64
- data/genius-decision.txt +0 -25
- data/lib/controller/db/model_git_service.rb +0 -399
- data/lib/plugin/github.rb +0 -53
- data/lib/utils/store/github.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5221d9e392de0ee7e1d506642281edbed9531f7b1cc8846f948c8186edeb1e3
|
4
|
+
data.tar.gz: 83805b1ef1d48f03171863ffb7ce6da789c4fadbda0946f5750ecf13a3de1417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5601e437f9bcd5c05cf956b48ec453fbbccb144799e5cbfd2d89228aa0589cd16ac7ed345f8002f9887c37e05103e97e2e1d4d92675a4a5ced378612bcb254e5
|
7
|
+
data.tar.gz: ba1c693c125a8d625e9c0a7020583a7616fe8394e6ed72400af3b661d391f806a8db8695f4c69b2654cd2a74981fe8e57ea4702d09a047aaf374000f6dfa373c
|
data/CONTRIBUTING.md
CHANGED
@@ -3,8 +3,38 @@
|
|
3
3
|
|
4
4
|
You can contriubute software, documentation, issues and even good ideas. Most contributions will either be integrations with other tools and technologies, or new use cases (plugins).
|
5
5
|
|
6
|
+
**Ignore these instructions if you just want to use the software.** To **use the software** **[visit the readme](README.md)**.
|
6
7
|
|
7
|
-
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
|
12
|
+
## Use Docker to Build and Run the Tests
|
13
|
+
|
14
|
+
Using **`docker`** is the **simplest quickest** way to **build, package** and run the **cucumber/aruba** test suite.
|
15
|
+
|
16
|
+
```
|
17
|
+
# Get the safe software
|
18
|
+
git clone https://github.com/devops4me/safedb.net.git
|
19
|
+
cd safedb.net
|
20
|
+
|
21
|
+
# Prepare the safe build docker image
|
22
|
+
docker build --tag img.safeci .
|
23
|
+
|
24
|
+
# Now run the safe build docker image
|
25
|
+
docker run \
|
26
|
+
--interactive \
|
27
|
+
--tty \
|
28
|
+
--rm \
|
29
|
+
--name vm.safeci \
|
30
|
+
img.safeci
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
---
|
35
|
+
|
36
|
+
|
37
|
+
## Building a Development Environment
|
8
38
|
|
9
39
|
To contribute software you'll need to setup a development environment.
|
10
40
|
|
@@ -13,7 +43,7 @@ sudo apt install --assume-yes ruby-full libicu-dev git
|
|
13
43
|
sudo chown -R $USER:$USER /var/lib/gems
|
14
44
|
sudo chown -R $USER:$USER /usr/local/bin
|
15
45
|
sudo chown -R $USER:$USER /usr/local/lib
|
16
|
-
gem install
|
46
|
+
gem install bundler gem-release cucumber aruba
|
17
47
|
git clone https://github.com/devops4me/safedb.net.git mirror.safedb.ro
|
18
48
|
cd mirror.safedb
|
19
49
|
rake install
|
@@ -24,6 +54,23 @@ cucumber
|
|
24
54
|
You change the software as you see fit and **send a pull request** when you are ready.
|
25
55
|
|
26
56
|
|
57
|
+
## Cucumber and Aruba | Installi the right version
|
58
|
+
|
59
|
+
Aruba and Cucumber are **finickity** about both each others versions and the ruby version. If you see this output in the gem install command you need to act.
|
60
|
+
|
61
|
+
```
|
62
|
+
Fetching: aruba-0.14.12.gem (100%)
|
63
|
+
Use on ruby 1.8.7
|
64
|
+
* Make sure you add something like that to your `Gemfile`. Otherwise you will
|
65
|
+
get cucumber > 2 and this will fail on ruby 1.8.7
|
66
|
+
|
67
|
+
gem 'cucumber', '~> 1.3.20'
|
68
|
+
|
69
|
+
With aruba >= 1.0 there will be breaking changes. Make sure to read https://github.com/cucumber/aruba/blob/master/History.md for 1.0.0
|
70
|
+
Successfully installed aruba-0.14.12
|
71
|
+
```
|
72
|
+
|
73
|
+
|
27
74
|
## Running Cucumber/Aruba Tests
|
28
75
|
|
29
76
|
Use the simple **`cucumber`** command in the project directory to run the tests.
|
@@ -44,7 +91,7 @@ reek lib
|
|
44
91
|
|
45
92
|
## Automated Software Release
|
46
93
|
|
47
|
-
safedb is automatically released by Jenkins using a GitOps style pipeline defined in the Jenkinsfile and Dockerfile
|
94
|
+
safedb is automatically released by Jenkins using a GitOps style pipeline defined in the **[Jenkinsfile]** and **[Dockerfile]**. The release to rubygems.org depends on
|
48
95
|
|
49
96
|
- a pull request to the [safe github master branch](https://github.com/devops4me/safedb.net.git)
|
50
97
|
- an error-free gem build
|
data/Dockerfile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
FROM ruby:latest
|
2
|
+
|
3
|
+
# --->
|
4
|
+
# ---> install the gems necessary to build test package and
|
5
|
+
# ---> release this ruby project.
|
6
|
+
# --->
|
7
|
+
|
8
|
+
RUN gem install gem-release cucumber aruba yard reek
|
9
|
+
|
10
|
+
|
11
|
+
# --->
|
12
|
+
# ---> Create a non-root user from which cucumber and aruba
|
13
|
+
# ---> orchestrate and validate command line behaviour.
|
14
|
+
# --->
|
15
|
+
|
16
|
+
RUN adduser --home /home/safeci --shell /bin/bash --gecos 'Safe TTY Test User' safeci && \
|
17
|
+
install -d -m 755 -o safeci -g safeci /home/safeci
|
18
|
+
|
19
|
+
|
20
|
+
# --->
|
21
|
+
# ---> Copy the project assets into the docker image.
|
22
|
+
# --->
|
23
|
+
|
24
|
+
COPY . /home/safeci/code/
|
25
|
+
|
26
|
+
|
27
|
+
# --->
|
28
|
+
# ---> Use rake to Copy the project assets into the docker image.
|
29
|
+
# --->
|
30
|
+
|
31
|
+
RUN chown -R safeci:safeci /home/safeci && \
|
32
|
+
chmod u+x /home/safeci/code/cucumber-test.sh && \
|
33
|
+
cd /home/safeci/code && \
|
34
|
+
rake install
|
35
|
+
|
36
|
+
|
37
|
+
# --->
|
38
|
+
# --->
|
39
|
+
# ---> As the safeci user employ cucumber and aruba to recursively
|
40
|
+
# ---> find and execute all cucumber (*.feature) files under lib.
|
41
|
+
# --->
|
42
|
+
|
43
|
+
USER safeci
|
44
|
+
WORKDIR /home/safeci/code
|
45
|
+
|
46
|
+
####### ENTRYPOINT [ "/home/safeci/code/cucumber-test.sh" ]
|
data/Jenkinsfile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
pipeline
|
2
|
+
{
|
3
|
+
agent none
|
4
|
+
stages
|
5
|
+
{
|
6
|
+
stage('Build Safe Docker Image')
|
7
|
+
{
|
8
|
+
agent
|
9
|
+
{
|
10
|
+
kubernetes
|
11
|
+
{
|
12
|
+
defaultContainer 'kaniko'
|
13
|
+
yamlFile 'pod-image-builder.yaml'
|
14
|
+
}
|
15
|
+
}
|
16
|
+
steps
|
17
|
+
{
|
18
|
+
/*
|
19
|
+
* We checkout the git repository again because we
|
20
|
+
* are running in a different pod setup specifically
|
21
|
+
* to build and test the software.
|
22
|
+
*/
|
23
|
+
checkout scm
|
24
|
+
sh '/kaniko/executor -f `pwd`/Dockerfile -c `pwd` --destination devops4me/safetty:latest --cleanup'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
stage('Run the Cucumber Tests')
|
28
|
+
{
|
29
|
+
agent
|
30
|
+
{
|
31
|
+
kubernetes
|
32
|
+
{
|
33
|
+
yamlFile 'pod-image-safetty.yaml'
|
34
|
+
}
|
35
|
+
}
|
36
|
+
steps
|
37
|
+
{
|
38
|
+
container('safettytests')
|
39
|
+
{
|
40
|
+
sh '/home/safeci/code/cucumber-test.sh'
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
data/README.md
CHANGED
@@ -2,6 +2,22 @@ safe [](http://trav
|
|
2
2
|
==========
|
3
3
|
|
4
4
|
|
5
|
+
## safe drag `<<xxxx>>`
|
6
|
+
|
7
|
+
if xxxx
|
8
|
+
- ends with a colon @--> book name
|
9
|
+
- begins with a colon and no slashes @--> chapter name
|
10
|
+
- has just one fwd slash @===> verse (could also have colon to specify different book or different chapter)
|
11
|
+
- has 2 fwd slashes ==> it is a line => may also have colon to specify different book or different chapter
|
12
|
+
- has no colon or fwd slashes its a line name
|
13
|
+
|
14
|
+
With this notation the open chapter/verse does not change.
|
15
|
+
Used in commands like safe delete | safe drag | safe drop | safe rename <<from>> <<to>>
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
5
21
|
## safe push | safe pull
|
6
22
|
|
7
23
|
Working with <tt>remote (off-site) storage</tt> and <tt>sync-ing safe books</tt> between **different computers** is done using <tt>safe push</tt> and <tt>safe pull</tt>. Even with a single laptop you need a backup and restore process and this push pull is in-built and ready to go.
|
data/Rakefile
CHANGED
@@ -18,6 +18,6 @@ require 'yard'
|
|
18
18
|
# This configuration allows us to run "rake yard"
|
19
19
|
# to build documentation.
|
20
20
|
YARD::Rake::YardocTask.new do |t|
|
21
|
-
|
22
|
-
|
21
|
+
t.files = ['lib/**/*.rb'] # optional
|
22
|
+
t.stats_options = ['--list-undoc']
|
23
23
|
end
|
data/cucumber-test.sh
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
## ####################################### ##
|
4
|
+
## Exit this script when any command fails ##
|
5
|
+
## ####################################### ##
|
6
|
+
set -e
|
7
|
+
|
8
|
+
# ++ +++ ++++++ # +++++ +++++++ # +++ +++++++++ # +++++++ # ++++ +++++ ++ #
|
9
|
+
# ++ --- ------ # ----- ------- # --- --------- # ------- # ---- ----- ++ #
|
10
|
+
# ++ ++ #
|
11
|
+
# ++ Prepare for the cucumber orchestrated tests that are part of the ++ #
|
12
|
+
# ++ build for the safedb personal database. This script exports the ++ #
|
13
|
+
# ++ protective safe token and then executes cucumber feature files. ++ #
|
14
|
+
# ++ ++ #
|
15
|
+
# ++ --- ------ # ----- ------- # --- --------- # ------- # ---- ----- ++ #
|
16
|
+
# ++ +++ ++++++ # +++++ +++++++ # +++ +++++++++ # +++++++ # ++++ +++++ ++ #
|
17
|
+
|
18
|
+
echo "" ; echo "" ;
|
19
|
+
echo "### ######################################## ###"
|
20
|
+
echo "### Static Code Quality Analyzer Suggestions ###"
|
21
|
+
echo "### ######################################## ###"
|
22
|
+
echo ""
|
23
|
+
|
24
|
+
reek lib
|
25
|
+
echo ""
|
26
|
+
|
27
|
+
echo "" ; echo "" ;
|
28
|
+
echo "### ################################## ###"
|
29
|
+
echo "### Ruby Execution Environment Details ###"
|
30
|
+
echo "### ################################## ###"
|
31
|
+
echo ""
|
32
|
+
|
33
|
+
echo "Current directory is $(pwd)"
|
34
|
+
echo "Current username is $(whoami)"
|
35
|
+
echo "" ; ls -lh
|
36
|
+
safe version
|
37
|
+
|
38
|
+
echo ""
|
39
|
+
echo "### ################################ ###"
|
40
|
+
echo "### Exporting safe shell (tty) token ###"
|
41
|
+
echo "### ################################ ###"
|
42
|
+
echo ""
|
43
|
+
|
44
|
+
export SAFE_TTY_TOKEN=$(safe token)
|
45
|
+
|
46
|
+
echo "" ; echo "" ;
|
47
|
+
echo "### ###################################### ###"
|
48
|
+
echo "### Now executing the cucumber/aruba tests ###"
|
49
|
+
echo "### ###################################### ###"
|
50
|
+
echo ""
|
51
|
+
|
52
|
+
cucumber lib
|
53
|
+
echo ""
|
54
|
+
|
55
|
+
exit 0
|
data/lib/cli.rb
CHANGED
@@ -360,7 +360,7 @@ class CLI < Thor
|
|
360
360
|
# Creates remote storage for the safe database crypt files.
|
361
361
|
def remote
|
362
362
|
log.info(x) { "performing a remote storage use case. The provision flag is set to #{options[ :provision ]}." }
|
363
|
-
remote_uc = SafeDb::
|
363
|
+
remote_uc = SafeDb::RemoteGithubToken.new()
|
364
364
|
remote_uc.provision = true if options[ :provision ]
|
365
365
|
remote_uc.provision = false unless options[ :provision ]
|
366
366
|
remote_uc.flow()
|
@@ -410,19 +410,32 @@ class CLI < Thor
|
|
410
410
|
|
411
411
|
|
412
412
|
# Description of the safe database push command.
|
413
|
-
desc "push", "push crypts to
|
413
|
+
desc "push", "push commited safe crypts to the remote backend repository."
|
414
414
|
|
415
|
-
#
|
416
|
-
#
|
417
|
-
#
|
418
|
-
# remote for safe keeping.
|
415
|
+
# This simple command does not require the user to be logged into a specific
|
416
|
+
# book. The only pre-condition is that safe remote --provision has been successfully
|
417
|
+
# run thus placing the required remote origin urls.
|
419
418
|
def push
|
420
|
-
log.info(x) { "push
|
419
|
+
log.info(x) { "request to push safe crypts to the remote backend." }
|
421
420
|
SafeDb::Push.new().flow()
|
422
421
|
end
|
423
422
|
|
424
423
|
|
425
424
|
|
425
|
+
|
426
|
+
# Description of the safe database obliterate command.
|
427
|
+
desc "obliterate", "creates a backup then removes the entire safe master database"
|
428
|
+
|
429
|
+
# The obliterate command does not need to be secured behind authentication because
|
430
|
+
# all it does is delete a directory. Not withstanding taking a backup - this command
|
431
|
+
# is exactly like the bash rm -fr command.
|
432
|
+
def obliterate
|
433
|
+
log.info(x) { "request to obliterate the safedb master database." }
|
434
|
+
SafeDb::Obliterate.new().flow()
|
435
|
+
end
|
436
|
+
|
437
|
+
|
438
|
+
|
426
439
|
# Description of the set configuration directives command.
|
427
440
|
desc "set <directive_name> <directive_value>", "set book-scoped configuration directive"
|
428
441
|
|
@@ -35,12 +35,11 @@ module SafeDb
|
|
35
35
|
def initialize
|
36
36
|
|
37
37
|
class_name = self.class.name.split(":").last.downcase
|
38
|
-
is_no_token_uc = [ "token", "init", "id" ].include? class_name
|
38
|
+
is_no_token_uc = [ "token", "init", "id", "obliterate" ].include? class_name
|
39
39
|
return if is_no_token_uc
|
40
40
|
exit(100) unless ops_key_exists?
|
41
41
|
|
42
|
-
|
43
|
-
return if is_login_uc
|
42
|
+
return if [ "login", "push", "pull" ].include? class_name
|
44
43
|
|
45
44
|
not_logged_in = StateInspect.not_logged_in?()
|
46
45
|
puts TextChunk.not_logged_in_message() if not_logged_in
|
@@ -33,9 +33,6 @@ module SafeDb
|
|
33
33
|
|
34
34
|
def execute
|
35
35
|
|
36
|
-
# @todo => in parent class Authenticate validate the book name
|
37
|
-
|
38
|
-
|
39
36
|
@book_id = Identifier.derive_ergonomic_identifier( @book_name, Indices::SAFE_BOOK_ID_LENGTH )
|
40
37
|
|
41
38
|
if is_book_initialized?()
|
@@ -45,8 +42,6 @@ module SafeDb
|
|
45
42
|
|
46
43
|
EvolveState.create_book( @book_id )
|
47
44
|
|
48
|
-
# @todo => search for password in environment variable
|
49
|
-
|
50
45
|
book_secret = KeyPass.password_from_shell( true ) if @password.nil?
|
51
46
|
book_secret = @password unless @password.nil?
|
52
47
|
|
@@ -60,6 +55,15 @@ module SafeDb
|
|
60
55
|
virginal_book()
|
61
56
|
)
|
62
57
|
|
58
|
+
commit_msg = "safe init artifacts for newly created (#{@book_name}) book on #{TimeStamp.readable()}."
|
59
|
+
|
60
|
+
GitFlow.init( Indices::MASTER_CRYPTS_FOLDER_PATH )
|
61
|
+
GitFlow.config( Indices::MASTER_CRYPTS_FOLDER_PATH, "#{ENV[ "USER" ]}@#{Socket.gethostname()}", "SafeDb User" )
|
62
|
+
GitFlow.stage( Indices::MASTER_CRYPTS_FOLDER_PATH )
|
63
|
+
GitFlow.list( Indices::MASTER_CRYPTS_FOLDER_PATH )
|
64
|
+
GitFlow.list( Indices::MASTER_CRYPTS_FOLDER_PATH, true )
|
65
|
+
GitFlow.commit( Indices::MASTER_CRYPTS_FOLDER_PATH, commit_msg )
|
66
|
+
|
63
67
|
print_success_initializing
|
64
68
|
|
65
69
|
end
|
@@ -73,7 +77,7 @@ module SafeDb
|
|
73
77
|
initial_db = DataStore.new()
|
74
78
|
initial_db.store( Indices::SAFE_BOOK_INITIALIZE_TIME, TimeStamp.readable() )
|
75
79
|
initial_db.store( Indices::SAFE_BOOK_NAME, @book_name )
|
76
|
-
initial_db.store( Indices::SAFE_BOOK_INIT_VERSION, Indices::
|
80
|
+
initial_db.store( Indices::SAFE_BOOK_INIT_VERSION, "#{Indices::SAFE_PRE_VERSION_STRING}#{SafeDb::VERSION}" )
|
77
81
|
initial_db.store( Indices::SAFE_BOOK_CHAPTER_KEYS, {} )
|
78
82
|
|
79
83
|
return initial_db.to_json
|
@@ -85,7 +89,7 @@ module SafeDb
|
|
85
89
|
|
86
90
|
puts ""
|
87
91
|
puts "You can go ahead and login."
|
88
|
-
puts "Your
|
92
|
+
puts "Your book [#{@book_name}] already exists."
|
89
93
|
puts "You should already know the password."
|
90
94
|
puts ""
|
91
95
|
puts " #{COMMANDMENT} login #{@book_name}"
|
@@ -25,8 +25,6 @@ module SafeDb
|
|
25
25
|
# - the shell's secure password reader
|
26
26
|
class Login < Authenticate
|
27
27
|
|
28
|
-
# DELETE ME ####################### attr_writer :clip, :login_book_id, :suppress_output
|
29
|
-
|
30
28
|
# If the clip switch is present it signifies that the password should
|
31
29
|
# be read in from the clipboard. Any text selection puts text into the
|
32
30
|
# the clipboard - no need specifically to use Ctrl-c (copy).
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
Feature: test safedb's obliterate command
|
3
|
+
|
4
|
+
This test will run the `safe obliterate` command
|
5
|
+
|
6
|
+
Scenario: checking the safe shell token exists
|
7
|
+
When I run `printenv`
|
8
|
+
Then the output should contain "SAFE_TTY_TOKEN"
|
9
|
+
|
10
|
+
Scenario: there is nothing to obliterate
|
11
|
+
When I run `safe obliterate`
|
12
|
+
Then the output should contain "There is nothing to obliterate"
|
13
|
+
And a directory named "~/.config/safedb/safedb-master-crypts" should not exist
|
14
|
+
And a directory named "~/.config/safedb/safedb-branch-crypts" should not exist
|
15
|
+
And a directory named "~/.config/safedb/safedb-branch-keys" should not exist
|
16
|
+
|
17
|
+
Scenario: initializing the safe to obliterate
|
18
|
+
When I run `safe init book1 --password=abc123XYZ`
|
19
|
+
Then the output should contain "Your book book1 with id r6h43w-c69155 is up"
|
20
|
+
And the output should contain "Success"
|
21
|
+
And a directory named "~/.config/safedb/safedb-master-crypts" should exist
|
22
|
+
And a file named "~/.config/safedb/safedb-master-crypts/safedb-master-keys.ini" should exist
|
23
|
+
And a directory named "~/.config/safedb/safedb-master-crypts/.git" should exist
|
24
|
+
And a directory named "~/.config/safedb/safedb-branch-crypts" should not exist
|
25
|
+
And a directory named "~/.config/safedb/safedb-branch-keys" should not exist
|
26
|
+
|
27
|
+
Scenario: logging into the (just initialized) safe
|
28
|
+
When I run `safe init book1 --password=abc123XYZ`
|
29
|
+
And I run `printenv`
|
30
|
+
And I run `safe login book1 --password=abc123XYZ`
|
31
|
+
Then the output should contain "SAFE_TTY_TOKEN"
|
32
|
+
And the output should contain "There are 0 chapters and 0 verses"
|
33
|
+
And a directory named "~/.config/safedb/safedb-master-crypts" should exist
|
34
|
+
And a file named "~/.config/safedb/safedb-master-crypts/safedb-master-keys.ini" should exist
|
35
|
+
And a directory named "~/.config/safedb/safedb-branch-crypts" should exist
|
36
|
+
And a directory named "~/.config/safedb/safedb-branch-keys" should exist
|
37
|
+
|
38
|
+
Scenario: now obliterating the safe we just created
|
39
|
+
When I run `safe init book1 --password=abc123XYZ`
|
40
|
+
And I run `safe login book1 --password=abc123XYZ`
|
41
|
+
And I run `safe obliterate`
|
42
|
+
Then the output should contain "The safe has been successfully obliterated"
|
43
|
+
And a directory named "~/.config/safedb/safedb-master-crypts" should not exist
|
44
|
+
And a directory named "~/.config/safedb/safedb-branch-crypts" should not exist
|
45
|
+
And a directory named "~/.config/safedb/safedb-branch-keys" should not exist
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
module SafeDb
|
4
|
+
|
5
|
+
# Obliterate the entire safe database by removing a number of folders. This is a
|
6
|
+
# drastic action especially as it will terminate all safe sessions on the machine
|
7
|
+
# no matter which shell is being used.
|
8
|
+
#
|
9
|
+
# This action is recoverable in two ways. The first is a "safe pull" if using a
|
10
|
+
# remote repository like git. The second is manual restoration of the obliterated
|
11
|
+
# folder which is saved in the safedb-backup-crypts folder.
|
12
|
+
class Obliterate < Controller
|
13
|
+
|
14
|
+
# Print message and return if the master crypts directory does not exist. Otherwise
|
15
|
+
# make a backup of the folder then obliterate
|
16
|
+
# - the master crypts folder
|
17
|
+
# - the branch crypts folder
|
18
|
+
# - the branch keys folder
|
19
|
+
def execute()
|
20
|
+
|
21
|
+
unless ( File.exist?( Indices::MASTER_CRYPTS_FOLDER_PATH ) && File.directory?( Indices::MASTER_CRYPTS_FOLDER_PATH ) )
|
22
|
+
|
23
|
+
puts ""
|
24
|
+
puts " Could not find directory"
|
25
|
+
puts " #{Indices::MASTER_CRYPTS_FOLDER_PATH}"
|
26
|
+
puts " #{Indices::NOTHING_TO_OBLITERATE}"
|
27
|
+
puts ""
|
28
|
+
return
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
backup_folder_name = TimeStamp.yyjjj_hhmm_sst() + "-" + Indices::MASTER_CRYPTS_FOLDER_NAME
|
33
|
+
backup_folder_path = File.join( Indices::BACKUP_CRYPTS_FOLDER_PATH, backup_folder_name )
|
34
|
+
FileUtils.mkdir_p( backup_folder_path )
|
35
|
+
FileUtils.cp_r( "#{Indices::MASTER_CRYPTS_FOLDER_PATH}/.", backup_folder_path )
|
36
|
+
|
37
|
+
FileUtils.remove_dir( Indices::MASTER_CRYPTS_FOLDER_PATH ) if ( File.exist?( Indices::MASTER_CRYPTS_FOLDER_PATH ) && File.directory?( Indices::MASTER_CRYPTS_FOLDER_PATH ) )
|
38
|
+
FileUtils.remove_dir( Indices::BRANCH_CRYPTS_FOLDER_PATH ) if ( File.exist?( Indices::BRANCH_CRYPTS_FOLDER_PATH ) && File.directory?( Indices::BRANCH_CRYPTS_FOLDER_PATH ) )
|
39
|
+
FileUtils.remove_dir( Indices::BRANCH_INDICES_FOLDER_PATH ) if ( File.exist?( Indices::BRANCH_INDICES_FOLDER_PATH ) && File.directory?( Indices::BRANCH_INDICES_FOLDER_PATH ) )
|
40
|
+
|
41
|
+
puts ""
|
42
|
+
puts " The safe has been successfully obliterated."
|
43
|
+
puts " The obliterated safe database is backed up in this folder."
|
44
|
+
puts " #{backup_folder_path}"
|
45
|
+
puts " safe init # this will create a new safe"
|
46
|
+
puts " safe pull # downloads a remote safe db"
|
47
|
+
puts ""
|
48
|
+
|
49
|
+
return
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
data/lib/controller/db/pull.rb
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
module SafeDb
|
4
4
|
|
5
|
-
# If the removable drive path is configured and exists and contains the master
|
6
|
-
# index file, the pull use case backs up both file and master crypts (if necessary)
|
7
|
-
# and then refreshes them with the state that exists in the remote mirrored git
|
8
|
-
# directory and the indices on the removable drive path.
|
9
|
-
class Pull < Controller
|
10
|
-
|
11
5
|
# If the removable drive path is configured and exists and contains the master
|
12
6
|
# index file, the pull use case backs up both file and master crypts (if necessary)
|
13
7
|
# and then refreshes them with the state that exists in the remote mirrored git
|
14
8
|
# directory and the indices on the removable drive path.
|
15
|
-
|
9
|
+
class Pull < Controller
|
10
|
+
|
11
|
+
# If the removable drive path is configured and exists and contains the master
|
12
|
+
# index file, the pull use case backs up both file and master crypts (if necessary)
|
13
|
+
# and then refreshes them with the state that exists in the remote mirrored git
|
14
|
+
# directory and the indices on the removable drive path.
|
15
|
+
def execute()
|
16
16
|
|
17
|
-
|
17
|
+
puts ""
|
18
18
|
|
19
19
|
removable_drive_path = xxx # ~~~~ read this from the --to variable
|
20
20
|
removable_drive_file = File.join( removable_drive_path, Indices::MASTER_INDICES_FILE_NAME )
|
@@ -41,29 +41,13 @@ module SafeDb
|
|
41
41
|
|
42
42
|
is_git = File.exist?( Indices::MASTER_CRYPTS_GIT_PATH ) && File.directory?( Indices::MASTER_CRYPTS_GIT_PATH )
|
43
43
|
|
44
|
+
return
|
44
45
|
|
45
46
|
|
46
|
-
|
47
|
-
require "octokit"
|
48
|
-
############client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!')
|
49
|
-
|
50
|
-
client = Octokit::Client.new(:access_token => '')
|
51
|
-
user = client.user
|
52
|
-
puts "Company Name => #{user[:company]}"
|
53
|
-
puts "User Name => #{user[:name]}"
|
54
|
-
puts "User ID => #{user[:id]}"
|
55
|
-
puts "Email => #{user[:email]}"
|
56
|
-
puts "Login => #{user[:login]}"
|
57
|
-
puts "Biography => #{user[:bio]}"
|
58
|
-
=end
|
59
|
-
|
60
|
-
return
|
47
|
+
end
|
61
48
|
|
62
49
|
|
63
50
|
end
|
64
51
|
|
65
52
|
|
66
|
-
end
|
67
|
-
|
68
|
-
|
69
53
|
end
|