diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2011-01-29 19:57:58 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2011-01-29 19:57:58 -0200 |
commit | 4d4df2e46f9fde08ca73fe809f7e87379602f78f (patch) | |
tree | 545014212f32968589bef827f4b94df0b3510b96 | |
parent | 5d0ae3722c6889fff8c00018066662260a71f3e2 (diff) | |
parent | ce02d9f01ca366be945caf286c0b77f8eaab24d1 (diff) | |
download | keyringer-4d4df2e46f9fde08ca73fe809f7e87379602f78f.tar.gz keyringer-4d4df2e46f9fde08ca73fe809f7e87379602f78f.tar.bz2 |
Merge commit 'origin/ruby' into ruby
-rwxr-xr-x | bin/keyringer | 23 | ||||
-rw-r--r-- | lib/backend.rb | 1 | ||||
-rw-r--r-- | lib/backend/recipients_store.rb | 79 | ||||
-rw-r--r-- | lib/keyring.rb | 1 | ||||
-rw-r--r-- | lib/keyring/recipients.rb | 26 | ||||
-rw-r--r-- | lib/keyringer.rb | 1 | ||||
-rw-r--r-- | lib/keyringer/actions/recipients.rb | 25 |
7 files changed, 147 insertions, 9 deletions
diff --git a/bin/keyringer b/bin/keyringer index c643369..098719b 100755 --- a/bin/keyringer +++ b/bin/keyringer @@ -25,20 +25,25 @@ require 'keyringer' begin Keyringer::Parser.new - action = Keyringer::Actions.const_get($action.capitalize) - - if action.is_a?(Class) - instance = action.new - output = instance.execute - puts output + puts "Performing action #{$action.capitalize}" + begin + action = Keyringer::Actions.const_get($action.capitalize) + rescue NameError + wrapper = Keyringer::BashWrapper.new + wrapper.execute + else + if action.is_a?(Class) + instance = action.new + output = instance.execute + puts output + end end -rescue NameError - wrapper = Keyringer::BashWrapper.new - wrapper.execute rescue SystemExit => e exit e.status rescue Exception => e puts "Fatal error: #{e.inspect}" + puts e.backtrace.join("\n") + exit 1 end diff --git a/lib/backend.rb b/lib/backend.rb index 18f220c..6be9016 100644 --- a/lib/backend.rb +++ b/lib/backend.rb @@ -1,3 +1,4 @@ # internal requires $:.unshift File.dirname(__FILE__) require 'backend/crypt' +require 'backend/recipients_store' diff --git a/lib/backend/recipients_store.rb b/lib/backend/recipients_store.rb new file mode 100644 index 0000000..158aabf --- /dev/null +++ b/lib/backend/recipients_store.rb @@ -0,0 +1,79 @@ +module Backend
+ # a store for the recipients configuration
+ class RecipientsStore
+ # Instantiates and stores password
+ def initialize(aBaseDir = "")
+ @baseDir = aBaseDir
+ end
+
+ def addRecipient(aRecipientAddress, aRecipientKey)
+ @recipients.push(Recipient.new(aRecipientAddress, aRecipientKey))
+ end
+
+ def removeRecipient(aRecipientKey)
+# read()
+# @recipients.push(Recipient.new(aRecipientAddress, aRecipientKey))
+# write()
+ end
+
+ def getRecipients()
+ return @recipients
+ end
+
+ def load()
+ read()
+ end
+
+ def save()
+ write()
+ end
+
+ private
+
+ def read()
+ fileName = File.join(@baseDir, "config", "recipients")
+ file = File.new(fileName, "r")
+ begin
+ recipients = []
+
+ while (line = file.gets)
+ parts = line.split()
+ if (parts.length == 2)
+ recipients.push(Recipient.new(parts[1], parts[0]))
+ end
+ end
+
+ @recipients = recipients
+ rescue => err
+ throw err
+ ensure
+ file.close
+ end
+ end
+
+ def write()
+ fileName = File.join(@baseDir, "config", "recipients")
+ file = File.new(fileName, "w")
+ begin
+ @recipients.each do |recipient|
+ file.puts("#{recipient.email} #{recipient.keySignature}")
+ end
+ rescue => err
+ throw err
+ ensure
+ file.close
+ end
+ end
+
+ end
+
+ class Recipient
+ def initialize(aKeySignature, anEmail)
+ @keySignature = aKeySignature
+ @email = anEmail
+ end
+
+ attr_reader :keySignature
+ attr_reader :email
+ end
+end
diff --git a/lib/keyring.rb b/lib/keyring.rb index 7bfdb86..d3e9260 100644 --- a/lib/keyring.rb +++ b/lib/keyring.rb @@ -3,3 +3,4 @@ $:.unshift File.dirname(__FILE__) require 'backend' require 'keyring/crypt' require 'keyring/fs' +require 'keyring/recipients' diff --git a/lib/keyring/recipients.rb b/lib/keyring/recipients.rb new file mode 100644 index 0000000..4cd9a48 --- /dev/null +++ b/lib/keyring/recipients.rb @@ -0,0 +1,26 @@ +module Keyring
+ class Recipients
+ def initialize(aBaseDirectory = '..')
+ @recipientsStore = Backend::RecipientsStore.new(aBaseDirectory)
+
+ end
+ def addRecipient(anEmail, aKeySignature)
+
+ @recipientsStore.load()
+ @recipientsStore.addRecipient(anEmail, aKeySignature)
+ @recipientsStore.save()
+ end
+
+ def removeRecipient(aKeySignature)
+ @recipientsStore.load()
+ @recipientsStore.removeRecipient(aKeySignature)
+ @recipientsStore.save()
+ end
+
+ def listRecipients()
+ @recipientsStore.load()
+
+ return @recipientsStore.getRecipients()
+ end
+ end
+end
diff --git a/lib/keyringer.rb b/lib/keyringer.rb index 1f5dace..257c5ad 100644 --- a/lib/keyringer.rb +++ b/lib/keyringer.rb @@ -5,6 +5,7 @@ require 'keyringer/bash_wrapper' require 'keyringer/parser' require 'keyringer/checker' require 'keyringer/actions/decrypt' +require 'keyringer/actions/recipients' module Keyringer VERSION = '2.0-alpha' diff --git a/lib/keyringer/actions/recipients.rb b/lib/keyringer/actions/recipients.rb new file mode 100644 index 0000000..c5f30ed --- /dev/null +++ b/lib/keyringer/actions/recipients.rb @@ -0,0 +1,25 @@ +module Keyringer
+ module Actions
+ class Recipients
+ def execute
+ subCommand = $args[0]
+
+ recipients = Keyring::Recipients.new
+
+ if subCommand == "add"
+ recipients.addRecipient($args[1], $args[2])
+ elsif subCommand == "remove"
+ recipients.removeRecipient($args[1])
+ elsif subCommand == "list"
+ recipients.listRecipients().each() do |recipient|
+ puts("#{recipient.email} #{recipient.keySignature}")
+ end
+ else
+ throw "Invalid recipients command: #{subCommand} "
+ end
+
+ return ""
+ end
+ end
+ end
+end
|