safedb 0.5.1005 → 0.7.1001
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +1 -1
- data/genius-decision.txt +25 -0
- data/lib/cli.rb +155 -8
- data/lib/controller/{admin/auth.rb → abstract/authenticate.rb} +1 -2
- data/lib/controller/{controller.rb → abstract/controller.rb} +45 -24
- data/lib/controller/{edit/editverse.rb → abstract/edit_verse.rb} +0 -0
- data/lib/controller/{query/queryverse.rb → abstract/query_verse.rb} +0 -0
- data/lib/controller/{admin → access}/README.md +0 -0
- data/lib/controller/access/banner.txt +6 -0
- data/lib/controller/{admin → access}/init.rb +4 -4
- data/lib/controller/{admin → access}/login.rb +28 -23
- data/lib/controller/{admin → access}/logout.rb +0 -0
- data/lib/controller/{admin → access}/token.rb +0 -0
- data/lib/controller/{admin → access}/use.rb +0 -0
- data/lib/controller/api/docker/docker.rb +4 -22
- data/lib/controller/api/git/git.rb +104 -0
- data/lib/controller/api/terraform/README.md +23 -2
- data/lib/controller/api/terraform/terraform.rb +38 -7
- data/lib/controller/{admin → book}/commit.rb +2 -3
- data/lib/controller/{admin → book}/diff.rb +0 -0
- data/lib/controller/{admin → book}/export.rb +0 -0
- data/lib/controller/{admin → book}/import.rb +0 -0
- data/lib/controller/{admin → book}/refresh.rb +2 -2
- data/lib/controller/{admin → book}/view.rb +0 -0
- data/lib/{modules/storage/git.store.rb → controller/db/model_git_service.rb} +0 -0
- data/lib/controller/db/pull.rb +69 -0
- data/lib/controller/db/push.rb +352 -0
- data/lib/controller/db/remote.rb +108 -0
- data/lib/controller/edit/generate.rb +1 -1
- data/lib/controller/edit/keys.rb +72 -0
- data/lib/controller/edit/paste.rb +36 -0
- data/lib/controller/files/write.rb +11 -3
- data/lib/controller/misc/wipe.rb +23 -0
- data/lib/controller/navigate/at.rb +42 -0
- data/lib/controller/{admin → navigate}/goto.rb +0 -0
- data/lib/controller/{admin → navigate}/open.rb +0 -0
- data/lib/controller/query/copy.rb +32 -95
- data/lib/controller/query/tell.rb +36 -0
- data/lib/controller/requirer.rb +4 -4
- data/lib/controller/visit/README.md +34 -0
- data/lib/controller/visit/visit.rb +33 -0
- data/lib/manual/copy-paste.md +19 -2
- data/lib/{modules/README.md → manual/crypto-math.md} +0 -0
- data/lib/manual/push-pull.md +46 -0
- data/lib/manual/remote.md +62 -0
- data/lib/model/coordinates.rb +59 -0
- data/lib/model/{safe_tree.rb → file_tree.rb} +11 -6
- data/lib/model/indices.rb +113 -8
- data/lib/model/master.rb +40 -0
- data/lib/model/{state.migrate.rb → state_evolve.rb} +13 -5
- data/lib/model/{state.inspect.rb → state_query.rb} +5 -1
- data/lib/plugin/github.rb +53 -0
- data/lib/{modules/cryptology → utils/ciphers}/aes-256.rb +0 -0
- data/lib/{modules/cryptology → utils/ciphers}/blowfish.rb +0 -0
- data/lib/{modules/cryptology → utils/ciphers}/cipher.rb +0 -0
- data/lib/{modules/cryptology → utils/ciphers}/crypt.io.rb +0 -0
- data/lib/utils/keys/key.rb +44 -0
- data/lib/utils/keys/keypair.rb +52 -0
- data/lib/utils/logs/logger.rb +1 -1
- data/lib/utils/store/datastore.rb +1 -1
- data/lib/utils/store/github.rb +27 -0
- data/lib/utils/time/timestamp.rb +91 -0
- data/lib/version.rb +1 -1
- data/safedb.gemspec +2 -0
- metadata +75 -32
- data/lib/controller/verse.rb +0 -20
- data/lib/modules/storage/coldstore.rb +0 -186
- data/lib/utils/store/test-commands.sh +0 -24
@@ -3,8 +3,29 @@
|
|
3
3
|
|
4
4
|
### safe terraform | introduction
|
5
5
|
|
6
|
-
This terraform use case exports the AWS IAM user access key, secret key and region key into (very safe) environment variables and then runs the specified terraform be it **
|
6
|
+
This terraform use case exports the AWS IAM user access key, secret key and region key into (very safe) environment variables and then runs the specified terraform be it **plan**, **apply** or **destroy**.
|
7
7
|
|
8
|
+
The plan is to extend this command to directly cache terraform output variables.
|
9
|
+
|
10
|
+
### Passing Input Variables
|
11
|
+
|
12
|
+
The most powerful feature of **`safe terraform`** is the ability to pass safely stored input variables to terraform via environment variables. The safe exports data when the key
|
13
|
+
|
14
|
+
- **either** begins with **`tfvar.`**
|
15
|
+
- **or** begins with **`@tfvar.`** (for sensitive values)
|
16
|
+
|
17
|
+
### safe input variables examples
|
18
|
+
|
19
|
+
| **safe key** | **safe value** | type | exported env variable | usage |
|
20
|
+
|:----------------------------- |:---------------------- |:--------- |:--------------------- |: ----------------------- |
|
21
|
+
**tfvar.in_vpc_id** | vpc-1234567890 | string | TF_VAR_in_vpc_id | var.in_vpc_id
|
22
|
+
**tfvar.in_role_arn** | arn:aws:iam::98764 ... | string | TF_VAR_in_role_arn | var.in_role_arn
|
23
|
+
**@tfvar.in_db_password** | secret-543+210=753 | string | TF_VAR_in_db_password | var.in_db_password
|
24
|
+
**tfvar.in_ingress** | '[ "ssh", "http" ]' | list | TF_VAR_in_ingress | var.in_ingress
|
25
|
+
|
26
|
+
Mostly you pass string, number or boolean input variables to terraform. These examples also show how you can pass list and map variables to terraform.
|
27
|
+
|
28
|
+
---
|
8
29
|
|
9
30
|
## safe terraform | credential creation
|
10
31
|
|
@@ -21,7 +42,7 @@ The first use case is importing the IAM user credentials into safe.
|
|
21
42
|
$ safe put @secret.key 5678uvwx4321abcd9876 # Put IAM secret key in safe
|
22
43
|
$ safe put region.key eu-west-1 # infrastructure in Dublin
|
23
44
|
|
24
|
-
safe logout
|
45
|
+
$ safe logout
|
25
46
|
|
26
47
|
Take care to specify these 3 key names **@access.key**, **@secret.key**, **region.key** and note that safe's convention is to sensitively treat the value's of keys beginning with an **@** sign. **safe show** and other readers **mask out (redact)** these sensitive values.
|
27
48
|
|
@@ -14,9 +14,9 @@ module SafeDb
|
|
14
14
|
# ubiquitous safe open command.
|
15
15
|
#
|
16
16
|
# safe open <<chapter>> <<verse>>
|
17
|
-
class Terraform <
|
17
|
+
class Terraform < EditVerse
|
18
18
|
|
19
|
-
attr_writer :command
|
19
|
+
attr_writer :command, :debug
|
20
20
|
|
21
21
|
# This prefix is tagged onto environment variables which Terraform will read
|
22
22
|
# and convert for consumption into module input variables.
|
@@ -26,15 +26,19 @@ module SafeDb
|
|
26
26
|
# <tt>terraform apply</tt> command, it examines the lines at the opened
|
27
27
|
# chapter and verse and any that start with this prefix will be substringed
|
28
28
|
# to create an environment variable with the substringed name and key value.
|
29
|
-
ENV_VAR_PREFIX_A = "
|
29
|
+
ENV_VAR_PREFIX_A = "tfvar."
|
30
30
|
|
31
31
|
# Secure var prefix for environment variable key (line). Before safe runs the
|
32
32
|
# <tt>terraform apply</tt> command, it examines the lines at the opened
|
33
33
|
# chapter and verse and any that start with this prefix will be substringed
|
34
34
|
# to create an environment variable with the substringed name and key value.
|
35
|
-
ENV_VAR_PREFIX_B = "
|
35
|
+
ENV_VAR_PREFIX_B = "@#{ENV_VAR_PREFIX_A}"
|
36
36
|
|
37
|
-
|
37
|
+
TIMESTAMP_LINE_KEY = "tfvar.in_timestamp"
|
38
|
+
DESCRIBES_LINE_KEY = "tfvar.in_description"
|
39
|
+
|
40
|
+
|
41
|
+
def edit_verse()
|
38
42
|
|
39
43
|
# ############## | ############################################################
|
40
44
|
# @todo refactor | ############################################################
|
@@ -67,10 +71,25 @@ module SafeDb
|
|
67
71
|
puts "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
|
68
72
|
puts ""
|
69
73
|
|
74
|
+
command_name = @command ? @command : "apply"
|
75
|
+
is_apply = command_name.eql?( "apply" )
|
76
|
+
is_blast = command_name.eql?( "destroy" )
|
77
|
+
|
78
|
+
has_timestamp = @verse.has_key?( TIMESTAMP_LINE_KEY )
|
79
|
+
is_create_stamps = is_apply && !has_timestamp
|
80
|
+
is_remove_stamps = is_blast && has_timestamp
|
81
|
+
|
82
|
+
the_description = "was created on #{TimeStamp.readable()}."
|
83
|
+
|
84
|
+
@verse.store( TIMESTAMP_LINE_KEY, TimeStamp.yjjjhhmmsst() ) if is_create_stamps
|
85
|
+
@verse.store( DESCRIBES_LINE_KEY, the_description ) if is_create_stamps
|
86
|
+
|
70
87
|
ENV[ "AWS_ACCESS_KEY_ID" ] = @verse[ "@access.key" ]
|
71
88
|
ENV[ "AWS_SECRET_ACCESS_KEY" ] = @verse[ "@secret.key" ]
|
72
89
|
ENV[ "AWS_DEFAULT_REGION" ] = @verse[ "region.key" ]
|
73
90
|
|
91
|
+
ENV[ "TF_LOG" ] = "DEBUG" if @debug == true
|
92
|
+
|
74
93
|
@verse.each do | key_str, value_object |
|
75
94
|
|
76
95
|
is_env_var = key_str.start_with?( ENV_VAR_PREFIX_A ) || key_str.start_with?( ENV_VAR_PREFIX_B )
|
@@ -90,13 +109,25 @@ module SafeDb
|
|
90
109
|
puts ""
|
91
110
|
|
92
111
|
auto_approve = @command && @command.eql?( "plan" ) ? "" : "-auto-approve"
|
93
|
-
|
94
|
-
system "terraform #{command_name} #{auto_approve}"
|
112
|
+
exit_success = system "terraform #{command_name} #{auto_approve}"
|
95
113
|
|
96
114
|
puts ""
|
97
115
|
puts "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
|
98
116
|
puts ""
|
99
117
|
|
118
|
+
return if ( exit_success.nil?() || !exit_success )
|
119
|
+
|
120
|
+
@verse.delete( TIMESTAMP_LINE_KEY ) if is_remove_stamps
|
121
|
+
@verse.delete( DESCRIBES_LINE_KEY ) if is_remove_stamps
|
122
|
+
|
123
|
+
return unless is_apply
|
124
|
+
|
125
|
+
puts "Successful terraform apply."
|
126
|
+
graph_filename = "network-#{@book.get_open_verse_name()}-#{TimeStamp.yyjjj_hhmm_sst()}.png"
|
127
|
+
system "terraform graph | dot -Tpng > #{graph_filename}"
|
128
|
+
puts "Resource graph #{graph_filename} created."
|
129
|
+
puts ""
|
130
|
+
|
100
131
|
end
|
101
132
|
|
102
133
|
|
@@ -37,10 +37,9 @@ module SafeDb
|
|
37
37
|
|
38
38
|
end
|
39
39
|
|
40
|
-
|
40
|
+
EvolveState.commit( @book )
|
41
41
|
|
42
|
-
puts "
|
43
|
-
puts "Commit from branch to master was successful.\n"
|
42
|
+
puts "Commit at #{TimeStamp.readable()} successful."
|
44
43
|
puts ""
|
45
44
|
|
46
45
|
|
File without changes
|
File without changes
|
File without changes
|
@@ -39,8 +39,8 @@ module SafeDb
|
|
39
39
|
puts " == Book Mark := #{@book.get_open_chapter_name()}/#{@book.get_open_verse_name()}\n" if @book.is_opened?()
|
40
40
|
puts ""
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
EvolveState.refresh( @book )
|
43
|
+
EvolveState.copy_commit_id_to_branch( @book )
|
44
44
|
|
45
45
|
puts "Refresh from master to branch was successful.\n"
|
46
46
|
puts ""
|
File without changes
|
File without changes
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
module SafeDb
|
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
|
+
# 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
|
+
|
17
|
+
puts ""
|
18
|
+
|
19
|
+
removable_drive_path = xxx # ~~~~ read this from the --to variable
|
20
|
+
removable_drive_file = File.join( removable_drive_path, Indices::MASTER_INDICES_FILE_NAME )
|
21
|
+
removable_drive_file_exists = File.exist?( removable_drive_file ) && File.file?( removable_drive_file )
|
22
|
+
|
23
|
+
puts "Removable Drive Location => #{removable_drive_path}"
|
24
|
+
puts "Removable Drive Filepath => #{removable_drive_file}"
|
25
|
+
|
26
|
+
if removable_drive_file_exists
|
27
|
+
drive_filename = TimeStamp.yyjjj_hhmm_sst() + "-" + Indices::MASTER_INDICES_FILE_NAME
|
28
|
+
drive_backup_filepath = File.join( removable_drive_path, drive_filename )
|
29
|
+
File.write( drive_backup_filepath, File.read( removable_drive_file ) )
|
30
|
+
puts "Backup of Clobbered File => #{drive_backup_filepath}"
|
31
|
+
end
|
32
|
+
|
33
|
+
clobbered_crypts_name = TimeStamp.yyjjj_hhmm_sst() + "-" + Indices::MASTER_CRYPTS_FOLDER_NAME
|
34
|
+
clobbered_crypts_path = File.join( Indices::SAFE_DATABASE_FOLDER, clobbered_crypts_name )
|
35
|
+
|
36
|
+
FileUtils.mkdir_p( clobbered_crypts_path )
|
37
|
+
FileUtils.copy_entry( Indices::MASTER_CRYPTS_FOLDER_PATH, clobbered_crypts_path )
|
38
|
+
|
39
|
+
|
40
|
+
puts "Backup of Clobbered Crypts => #{clobbered_crypts_path}"
|
41
|
+
|
42
|
+
is_git = File.exist?( Indices::MASTER_CRYPTS_GIT_PATH ) && File.directory?( Indices::MASTER_CRYPTS_GIT_PATH )
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
=begin
|
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
|
61
|
+
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,352 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
module SafeDb
|
4
|
+
|
5
|
+
# After backing up local assets the <b>push use case</b> creates a remoe github
|
6
|
+
# repository if necessary and initializes the master crypts as a git repository
|
7
|
+
# if necessary and then adds, commits and pushes the crypts up to the github
|
8
|
+
# remote for safe keeping.
|
9
|
+
#
|
10
|
+
# We also remember the commit reference and we add this to the master indices
|
11
|
+
# file before finally backing up, and then updating the master indices file on
|
12
|
+
# the locally accessible removable drive.
|
13
|
+
#
|
14
|
+
# == The First Push
|
15
|
+
#
|
16
|
+
# The first push on a machine
|
17
|
+
#
|
18
|
+
# - writes and secures the private key
|
19
|
+
# - creates an entry within ~/.ssh/config
|
20
|
+
# - does a git init and sets the git remote
|
21
|
+
#
|
22
|
+
# Subsequent pushes will always
|
23
|
+
#
|
24
|
+
# - add and commit to the local repository
|
25
|
+
# - push crypts to the remote repository
|
26
|
+
# - record the commit reference in the safe database tracker file
|
27
|
+
# - copy the database tracker file to the removable drive
|
28
|
+
#
|
29
|
+
class Push < Controller
|
30
|
+
|
31
|
+
# After backing up local assets the <b>push use case</b> creates a remoe github
|
32
|
+
# repository if necessary and initializes the master crypts as a git repository
|
33
|
+
# if necessary and then adds, commits and pushes the crypts up to the github
|
34
|
+
# remote for safe keeping.
|
35
|
+
def execute()
|
36
|
+
|
37
|
+
open_remote_backend_location()
|
38
|
+
|
39
|
+
###########
|
40
|
+
########### =========================================
|
41
|
+
########### Instead of Private Keys Use Tokens =====
|
42
|
+
########### =========================================
|
43
|
+
###########
|
44
|
+
########### git remote add origin https://<<GITHUB_TOKEN>>@github.com/<<REPO_USERNAME>>/<<REPO_NAME>>.git
|
45
|
+
########### git remote set-url origin https://<<GITHUB_TOKEN>>@github.com/<<REPO_USERNAME>>/<<REPO_NAME>>.git
|
46
|
+
########### git push origin master
|
47
|
+
###########
|
48
|
+
########### Note ==== Query repository with git remote -v to see if an origin has been set
|
49
|
+
########### ==== If no origin set use the set-url variant otherwise use the add variant
|
50
|
+
###########
|
51
|
+
########### ==========================================
|
52
|
+
########### For Pulling (Cloning the Repository =====
|
53
|
+
########### ==========================================
|
54
|
+
###########
|
55
|
+
########### git clone https://github.com/<<REPO_USERNAME>>/<<REPO_NAME>>.git [[safedb-master-crypts]]
|
56
|
+
###########
|
57
|
+
###########
|
58
|
+
###########
|
59
|
+
|
60
|
+
# @todo ------------------------------------------------------------ >>
|
61
|
+
# @todo REFACTOR the below into lib/utils/keys/keypair.rb
|
62
|
+
# @todo REFACTOR And create a utiliy class for bulk of file Writer functionality
|
63
|
+
# @todo Methods in keypair should NOT know about the Indices constants
|
64
|
+
# @todo Refactor name from [Indices] to [Constants]
|
65
|
+
# @todo ------------------------------------------------------------ >>
|
66
|
+
# @todo Method Names
|
67
|
+
# @todo ------------------------------------------------------------ >>
|
68
|
+
# @todo (1) - Constants.write_private_key()
|
69
|
+
# @todo ------------------------------------------------------------ >>
|
70
|
+
|
71
|
+
private_key_path = File.join( Indices::SSH_DIRECTORY_PATH, @verse[ Indices::REMOTE_PRIVATE_KEY_KEYNAME ] )
|
72
|
+
private_key_exists = File.file?( private_key_path )
|
73
|
+
puts "private key found at #{private_key_path}" if private_key_exists
|
74
|
+
|
75
|
+
unless private_key_exists
|
76
|
+
|
77
|
+
puts "private key will be created at #{private_key_path}"
|
78
|
+
file_writer = Write.new()
|
79
|
+
file_writer.file_key = Indices::PRIVATE_KEY_DEFAULT_KEY_NAME
|
80
|
+
file_writer.to_dir = Indices::SSH_DIRECTORY_PATH
|
81
|
+
file_writer.flow()
|
82
|
+
|
83
|
+
FileUtils.chmod( 0600, private_key_path, :verbose => true )
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
git_username = @verse[ Indices::GIT_REPOSITORY_USER_KEYNAME ]
|
88
|
+
git_reponame = @verse[ Indices::GIT_REPOSITORY_NAME_KEYNAME ]
|
89
|
+
|
90
|
+
ssh_host_name = @verse[ Indices::REMOTE_MIRROR_SSH_HOST_KEYNAME ]
|
91
|
+
ssh_config_exists = File.file?( Indices::SSH_CONFIG_FILE_PATH )
|
92
|
+
config_file_contents = File.read( Indices::SSH_CONFIG_FILE_PATH ) if ssh_config_exists
|
93
|
+
ssh_config_written = ssh_config_exists && config_file_contents.include?( ssh_host_name )
|
94
|
+
puts "ssh config for host #{ssh_host_name} has already been written" if ssh_config_written
|
95
|
+
|
96
|
+
unless ssh_config_written
|
97
|
+
|
98
|
+
puts "ssh config for host #{ssh_host_name} will be written"
|
99
|
+
config_backup_path = File.join( Indices::SSH_DIRECTORY_PATH, "safe.clobbered.ssh.config-#{TimeStamp.yyjjj_hhmm_sst()}" )
|
100
|
+
File.write( config_backup_path, config_file_contents ) if ssh_config_exists
|
101
|
+
puts "original ssh config at #{config_backup_path}" if ssh_config_exists
|
102
|
+
|
103
|
+
File.open( Indices::SSH_CONFIG_FILE_PATH, "a" ) do |line|
|
104
|
+
line.puts( "\n" )
|
105
|
+
line.puts( "Host #{ ssh_host_name }" )
|
106
|
+
line.puts( "HostName github.com" )
|
107
|
+
line.puts( "User #{ git_username }" )
|
108
|
+
line.puts( "IdentityFile #{ private_key_path }" )
|
109
|
+
line.puts( "StrictHostKeyChecking no" )
|
110
|
+
end
|
111
|
+
|
112
|
+
puts "ssh config has been successfully written"
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
puts ""
|
117
|
+
|
118
|
+
ssh_test_cmd_string = "ssh -i #{private_key_path} -vT git@github.com"
|
119
|
+
system( ssh_test_cmd_string )
|
120
|
+
ssh_cmd_exit_status = $?.exitstatus
|
121
|
+
|
122
|
+
unless ssh_cmd_exit_status == 1
|
123
|
+
|
124
|
+
puts ""
|
125
|
+
puts "The command exit status is #{ssh_test_exitstatus}"
|
126
|
+
puts ""
|
127
|
+
puts "### ##### : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
128
|
+
puts "### Error : SSH test result did not contain expected string."
|
129
|
+
puts "### Query : #{ ssh_test_cmd_string }"
|
130
|
+
puts "### ##### : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
131
|
+
puts ""
|
132
|
+
|
133
|
+
return
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
puts ""
|
138
|
+
puts "### ####### : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
139
|
+
puts "### Success : The SSH connection test was a roaring success."
|
140
|
+
puts "### Command : #{ ssh_test_cmd_string }"
|
141
|
+
puts "### ####### : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
|
142
|
+
puts ""
|
143
|
+
|
144
|
+
## ==========>>> git rev-parse HEAD
|
145
|
+
|
146
|
+
# git init
|
147
|
+
# git clone `URLTORepository`
|
148
|
+
# cd `into your cloned folder`
|
149
|
+
# git checkout commithash
|
150
|
+
|
151
|
+
puts ""
|
152
|
+
return
|
153
|
+
|
154
|
+
=begin
|
155
|
+
ssh -i ~/.ssh/safedb.code.private.key.pem -vT git@safedb.code
|
156
|
+
git clone https://github.com/devops4me/safedb.net safedb.net
|
157
|
+
git remote set-url --push origin git@safedb.code:devops4me/safedb.net.git
|
158
|
+
=end
|
159
|
+
|
160
|
+
unless ssh_config_file contains git_reponame
|
161
|
+
|
162
|
+
#write out the SSH private key
|
163
|
+
# @todo change the write method to change the file permissions
|
164
|
+
|
165
|
+
# SAFE_PRIVATE_KEY_KEYNAME
|
166
|
+
|
167
|
+
# @todo - Write the chunk of text into .ssh/config file (name is git_reponame)
|
168
|
+
# @todo - the User is git_username
|
169
|
+
# @todo - the IdentityFile is Dir.home() joined to .ssh and User is git_username
|
170
|
+
|
171
|
+
user_host_name = "#{Etc.getlogin()}@#{Socket.gethostname()}"
|
172
|
+
@verse.store( Indices::REMOTE_LAST_PUSH_ON, TimeStamp.readable() )
|
173
|
+
@verse.store( Indices::REMOTE_LAST_PUSH_BY, user_host_name )
|
174
|
+
|
175
|
+
end # end the unless block
|
176
|
+
|
177
|
+
|
178
|
+
# -- SAFE_REMOTE_SSH_HOST = "safe.remote"
|
179
|
+
# -- SAFE_REMOTE_HOST_NAME = "github.com"
|
180
|
+
|
181
|
+
# @todo - link this to the Keys class to use the same string constant
|
182
|
+
# -- SAFE_PRIVATE_KEY_KEYNAME = "private.key"
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
# Do a git init if no .git folder found
|
188
|
+
# do git local config (for name and email) if necessary
|
189
|
+
# do git set remote url add
|
190
|
+
# do git add
|
191
|
+
# do git commit
|
192
|
+
# do git push origin master
|
193
|
+
|
194
|
+
# @verse.store( Indices::REMOTE_LAST_PUSH_ID, )
|
195
|
+
# @todo set git remote url (for push) in the @verse
|
196
|
+
# @todo set git clone url in the @verse
|
197
|
+
# @todo set git commit id in the @verse
|
198
|
+
|
199
|
+
# @todo now set the git clone url and commit ID in the master index file
|
200
|
+
|
201
|
+
# Make sure git pull --from=/path/to/dir LOGS in and writes the /path/to/dir with KEY as the User@hostname
|
202
|
+
|
203
|
+
## Now the git push --to=/path/to/this/dir => IF no path read from @verse
|
204
|
+
## If no verse with user@host path the WRITE to present working directory
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
=begin
|
209
|
+
|
210
|
+
Setting up passwordless git interactions (cloning, pulling, pushing) is the same as setting up passwordless ssh login.
|
211
|
+
|
212
|
+
To interact with Git without passwords you need to
|
213
|
+
|
214
|
+
- setup a public private SSH keypair
|
215
|
+
- install and lock down the private key
|
216
|
+
- create a SSH IdentityFile called config in `$HOME/.ssh/config`
|
217
|
+
- install the public key into BitBucket, GitLab, GitHub or a SSH accessible repo
|
218
|
+
|
219
|
+
### Setup Passwordless SSH
|
220
|
+
|
221
|
+
Passwordless SSH is a prerequisite to passwordless git interaction.
|
222
|
+
|
223
|
+
### The SSH Identity File
|
224
|
+
|
225
|
+
The Identity File is telling the SSH subsystem that when you see this particular hostname (IP Address) - you submit this private key because that host will for sure have the corresponding public key in its authorized keys cache.
|
226
|
+
|
227
|
+
When using Github, Gitlab or BitBucket - you go to a screen and enter in the public key portion.
|
228
|
+
|
229
|
+
```
|
230
|
+
Host bitbucket.server
|
231
|
+
StrictHostKeyChecking no
|
232
|
+
HostName bitbucket.org
|
233
|
+
User joebloggs276
|
234
|
+
IdentityFile /home/joebloggs/.ssh/bitbucket-repo-private-key.pem
|
235
|
+
```
|
236
|
+
|
237
|
+
### The Passwordless SSH Setup Commands
|
238
|
+
|
239
|
+
Our local user `joebloggs` has an account with `bitbucket.org` with username `joebloggs276` and has submitted the public key to it. He has created a private key at `/home/joebloggs/.ssh/bitbucket-repo-private-key.pem` (locked with a 400) and an identity file at `/home/joebloggs/.ssh/config`.
|
240
|
+
|
241
|
+
``` bash
|
242
|
+
ssh-keygen -t rsa # enter /home/joebloggs/.ssh/bitbucket-repo-private-key.pem
|
243
|
+
chmod 400 /home/joebloggs/.ssh/bitbucket-repo-private-key.pem # restrict to user read-only permissions
|
244
|
+
GIT_HOST_IP=bitbucket.org # set the hostname as bitbucket.org
|
245
|
+
ssh-keyscan $GIT_HOST_IP >> /home/joebloggs/.ssh/known_hosts # prevents a authenticity of host cant be established prompt
|
246
|
+
ssh -i /home/joebloggs/.ssh/bitbucket-repo-private-key.pem -vT "joebloggs276@$GIT_HOST_IP" # test that all will be okay
|
247
|
+
git clone git@bitbucket.org:joeltd/bigdata.git mirror.bigdata # this clone against bigdata account and repo is bigdata
|
248
|
+
```
|
249
|
+
|
250
|
+
BITBUCKET_USER=joebloggs276;
|
251
|
+
# curl --user ${BITBUCKET_USER} https://api.bitbucket.org/2.0/repositories/joeltd
|
252
|
+
curl --user ${BITBUCKET_USER} git@api.bitbucket.org/2.0/repositories/joeltd
|
253
|
+
|
254
|
+
|
255
|
+
Note that the clone command uses the bitbucket account called joeltd and the repository is called big_data_scripts.
|
256
|
+
|
257
|
+
The response to the SSH test against a bitbucket repository for user
|
258
|
+
|
259
|
+
`ssh -i /home/joebloggs/.ssh/bitbucket-repo-private-key.pem -vT "joebloggs276@$GIT_HOST_IP"`
|
260
|
+
|
261
|
+
## Setup Git in Existing Directory
|
262
|
+
|
263
|
+
To hook up with a new repository from a directory with files you first
|
264
|
+
|
265
|
+
- create the remote repository (use safe's github and gitlab tooling)
|
266
|
+
- safe will have created a public / private keypair and installed it in the remote repo
|
267
|
+
- locally their should be a private key (with 0600 permissions) and an entry in ~/.ssh/config
|
268
|
+
- go to the git directory (without a .git folder)
|
269
|
+
|
270
|
+
The commands to run
|
271
|
+
|
272
|
+
git init
|
273
|
+
git add -A
|
274
|
+
git status
|
275
|
+
git commit -am "First checkin of project."
|
276
|
+
git remote add origin git@<<Host>>:<<userOrGroup>>/<<repo-name>>.git
|
277
|
+
git remote -v
|
278
|
+
git push --set-upstream origin master
|
279
|
+
|
280
|
+
=end
|
281
|
+
|
282
|
+
|
283
|
+
# @todo -- also see temp-git-code.rb class in this directory
|
284
|
+
# @todo -- also see temp-git-code.rb class in this directory
|
285
|
+
# @todo -- also see temp-git-code.rb class in this directory
|
286
|
+
# @todo -- also see temp-git-code.rb class in this directory
|
287
|
+
# @todo -- also see temp-git-code.rb class in this directory
|
288
|
+
# @todo -- also see temp-git-code.rb class in this directory
|
289
|
+
# @todo -- also see temp-git-code.rb class in this directory
|
290
|
+
# @todo -- also see temp-git-code.rb class in this directory
|
291
|
+
# @todo -- also see temp-git-code.rb class in this directory
|
292
|
+
# @todo -- also see temp-git-code.rb class in this directory
|
293
|
+
|
294
|
+
|
295
|
+
puts ""
|
296
|
+
the_384_key = OpenSSL::PKey::EC.new('secp384r1')
|
297
|
+
the_384_key.generate_key!
|
298
|
+
|
299
|
+
puts "#############################"
|
300
|
+
puts "the 384 key"
|
301
|
+
puts "#############################"
|
302
|
+
puts the_384_key.private_key.to_pem()
|
303
|
+
puts "#############################"
|
304
|
+
puts the_384_key.private_key.export()
|
305
|
+
puts "#############################"
|
306
|
+
puts the_384_key.public_key.export()
|
307
|
+
puts "#############################"
|
308
|
+
puts the_384_key.public_key.to_pem()
|
309
|
+
puts "#############################"
|
310
|
+
puts the_384_key.to_pem()
|
311
|
+
puts "#############################"
|
312
|
+
puts the_384_key.to_text()
|
313
|
+
puts ""
|
314
|
+
|
315
|
+
ec_private_key_encoded = Base64.urlsafe_encode64( the_384_key.to_pem() )
|
316
|
+
|
317
|
+
puts "Private Key Encoded"
|
318
|
+
puts "ec_private_key_encoded"
|
319
|
+
puts ""
|
320
|
+
return
|
321
|
+
|
322
|
+
return
|
323
|
+
puts ""
|
324
|
+
|
325
|
+
removable_drive_path = xxx # ~~~~ read this from the --to variable
|
326
|
+
removable_drive_file = File.join( removable_drive_path, Indices::MASTER_INDICES_FILE_NAME )
|
327
|
+
removable_drive_file_exists = File.exist?( removable_drive_file ) && File.file?( removable_drive_file )
|
328
|
+
|
329
|
+
puts "Removable Drive Location => #{removable_drive_path}"
|
330
|
+
puts "Removable Drive Filepath => #{removable_drive_file}"
|
331
|
+
|
332
|
+
if removable_drive_file_exists
|
333
|
+
drive_filename = TimeStamp.yyjjj_hhmm_sst() + "-" + Indices::MASTER_INDICES_FILE_NAME
|
334
|
+
drive_backup_filepath = File.join( removable_drive_path, drive_filename )
|
335
|
+
File.write( drive_backup_filepath, File.read( removable_drive_file ) )
|
336
|
+
puts "Backup of Clobbered File => #{drive_backup_filepath}"
|
337
|
+
end
|
338
|
+
|
339
|
+
is_git = File.exist?( Indices::MASTER_CRYPTS_GIT_PATH ) && File.directory?( Indices::MASTER_CRYPTS_GIT_PATH )
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
return
|
344
|
+
|
345
|
+
|
346
|
+
end
|
347
|
+
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
|
352
|
+
end
|