bog 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MjVhMjNmYmE1NGMyZTg1ZWEwODllZDNkZmZkM2IyZDM4ZmYxZjg3YQ==
5
- data.tar.gz: !binary |-
6
- OTZiYjUxM2ExZDMzYWQxODVjOGM3OTU5YTg0M2NlNDdjOWMwZjE5NQ==
2
+ SHA1:
3
+ metadata.gz: b3be958e003d41498558912eb307039001493d8f
4
+ data.tar.gz: f7f58634bb19e8a07c481bcae18b1b2135c6f71d
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- Mjc2Mzc1MjM4ZDI3NjNkMDc4MWYxNzg0M2MxYmQ2NmU2ODc0OWQzZjZhODhh
10
- NjEwZjY5OTJkYmI2MWY2MzI4YjExMzhiYTdlZmU3M2QyMjJhMmJiYzJkNDNj
11
- OTY0MGJkMDMzZTI4NmZmNGVkYjZlZTA4YzMzNmZiYzhlN2FhODY=
12
- data.tar.gz: !binary |-
13
- YzcxZDdlNmJmNzAzNDRiMDc2Y2I4MTNjOTc5NmRiYmEzZmU5NDViMWNiYzJl
14
- MGZmYjU2NzM4ODEzYzBiZmUwZDQxNWNiMzlhNjZiMmRhYzhlOWQ2N2FhMDBk
15
- MzQ4ZWI2MjJmZjM0MDYyOTQ4NjY2YzhmZmM1ZDcyNzdlOTc2MTg=
6
+ metadata.gz: 9c8b0e7619edd96048d1a5a2ac9d47912c5ea1a855cb6cd0fa2421d2feaafc56f114e770b7f13432b173414a7b9681ba9b94f18e324057b353e03bda8b7c8a4b
7
+ data.tar.gz: 13cc1d0a55f741f3fbe4dce271cac99e88e002be9ba009f37855d4ad3f0a0d1d66ae89b791b3e58f5f762af1ccd05ab14e244f64fe5d2ec416c0ea19f6605323
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ cache: bundler
2
3
  rvm:
3
4
  - 1.9.3
4
5
  - 2.0.0
data/README.md CHANGED
@@ -12,8 +12,10 @@ You may have multiple clients, or may split your environments between EC2 accoun
12
12
  work with collections of dotfile configurations and to swap between those sets.
13
13
 
14
14
  ## Example
15
+ The traditional form, where you manually switch profiles:
16
+
15
17
  ```bash
16
- $ bog myclient init --aws --chef # Configure ~/.bog with stubs for AWS and Chef under profile 'myclient'
18
+ $ bog myclient init --aws # Configure ~/.bog with a stub for AWS under profile 'myclient'
17
19
  Enter your Amazon Secrect Access Key:
18
20
  ...
19
21
  $ bog myclient # Switch to profile 'myclient'
@@ -22,17 +24,34 @@ $ aws s3 ls
22
24
  ...
23
25
  $ bog personal # Switch to another profile
24
26
  ...
27
+ $ bog # Show the current profile
28
+ personal
29
+ ```
30
+ With roaming profiles enabled:
31
+ ```bash
32
+ $ bog personal default # Set default profile
33
+ $ source ~/.bog/bog.sh # Source shell helpers
34
+ $ cd ~/src/project
35
+ $ echo "myclient" > .bog-profile
36
+ $ bog # Profile set by dotfile
37
+ myclient
38
+ $ cd ..
39
+ $ bog # Profile set from default
40
+ personal # without dotfile present
41
+ $ bog someprofile
42
+ $ bog # Setting profile ignored
43
+ personal # with roaming profiles
25
44
  ```
26
45
 
27
46
  ### One-off commands
28
47
  ```bash
29
- $ bog myclient exec aws s3 ls # Exec command as myclient, then
30
- $ bog myclient exec knife client list # switch back to previous profile
48
+ $ bog myclient exec aws s3 ls # Exec command as myclient, then
49
+ $ bog myclient exec knife client list # switch back to previous profile
31
50
  ...
32
51
  ```
33
52
 
34
53
  ## How it works
35
- `bog init myclient --aws --chef` will create
54
+ `bog init myclient --aws` will create
36
55
 
37
56
  ```
38
57
  .bog
@@ -40,14 +59,24 @@ $ bog myclient exec knife client list # switch back to previous profile
40
59
  ├── plugins
41
60
  └── profiles
42
61
  └── myclient
43
- ├── .aws
44
- └── .chef
62
+ └── .aws
45
63
  ```
46
64
  If you passed a switch such as `--aws` then the correctly named configuration files will be present and populated. Otherwise you
47
65
  are free to include whatever you choose.
48
66
 
49
67
  `bog` will never touch your `~/.aws` and similar directories. You will need to symlink these to `~/.bog/current/.aws` (as appropriate) in order to have bog work.
50
68
 
69
+ ### Roaming profiles
70
+ By sourcing `~/.bog/bog.sh` into your shell environment and placing a file called `.bog-profile` into one or more directories you can take advantage of roaming profiles. In short, when `bog` detects such a file it'll automatically change your current profile to that given in the dotfile. This enables you to easily work with per-project profiles, for example.
71
+
72
+ It does this by recursing up from the current directory until it either finds a `.bog-profile` file or fails and continues with the **default profile**. You should be aware of the implications therefore of nested directories and of the implications for concurrency when running commands under `bog` in multiple terminals.
73
+
74
+ It also expects you to have a default profile configured for when a dotfile cannot be found. You can do this by executing `bog PROFILE default`.
75
+
76
+ **Be aware that using roaming profiles is mutally exclusive to using `bog PROFILE` to set your profile. IT WILL BE IGNORED. Your current profile will be determined either from the presence of a dotfile or from your default.**
77
+
78
+ You should be sure to source `~/.bog/bog.sh` **after** anything else that might hook into `$PROMPT_COMMAND`, such as chruby, rvm, or liquidprompt.
79
+
51
80
  ## Why another dotfile manager
52
81
  There are plenty out there. `bog` aims to fit a modern operational workflow and toolset.
53
82
 
data/bin/bog CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  require 'bog'
4
4
  require 'slop'
5
+ require 'require_all'
6
+ require_rel '../lib/bog/command'
5
7
 
6
- profile = ARGV[0].downcase
8
+ profile = ARGV[0].downcase if ARGV[0]
7
9
  command = ARGV[1].downcase if ARGV[1]
8
10
 
9
11
  unless command == 'exec'
@@ -11,7 +13,6 @@ unless command == 'exec'
11
13
  banner 'Usage: bog PROFILE [COMMAND] [options]'
12
14
  on 'h', 'help', 'Display this message'
13
15
  on 'a', 'aws', 'When passed to the \'init\' subcommand, prompt for AWS credentials'
14
- on 'c', 'chef', 'When passed to the \'init\' subcommand, prompt for Chef credentials'
15
16
  end
16
17
 
17
18
  if @options.help?
@@ -22,6 +23,12 @@ else
22
23
  @options = { :commands => ARGV[2..-1].join(' ') }
23
24
  end
24
25
 
26
+ # With no arguments show the current profile name
27
+ unless profile
28
+ Bog::Command::Show.execute
29
+ exit 0
30
+ end
31
+
25
32
  if command
26
33
  case command
27
34
  when 'init'
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
24
 
25
25
  spec.add_dependency "slop", "~> 3.4"
26
+ spec.add_dependency "require_all", "~> 1.3"
26
27
  end
@@ -0,0 +1,15 @@
1
+ require 'bog/profile'
2
+
3
+ module Bog
4
+ class Command
5
+ class Default
6
+ def self.execute(profile,options={})
7
+ old_profile = Bog::Profile.current
8
+ Bog::Profile.switch_to(profile.profile_name)
9
+ Bog::Profile.current.make_default
10
+ Bog::Profile.switch_to(old_profile.profile_name)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -1,17 +1,13 @@
1
+ require 'bog/profile'
2
+
1
3
  module Bog
2
4
  class Command
3
5
  class Exec
4
6
  def self.execute(profile, options)
5
- old_profile = get_current_profile
6
- Bog::Profile.switch_to(profile.profile_name)
7
- system("#{options[:commands]} 2>&1")
8
- Bog::Profile.switch_to(old_profile.profile_name)
9
- end
10
-
11
- private
12
-
13
- def self.get_current_profile
14
- Bog::Profile.find(File.basename(File.readlink(File.expand_path('~/.bog/current'))))
7
+ old_profile = Bog::Profile.current
8
+ Bog::Profile.switch_to(profile.profile_name)
9
+ system("#{options[:commands]} 2>&1")
10
+ Bog::Profile.switch_to(old_profile.profile_name)
15
11
  end
16
12
 
17
13
  end
@@ -1,4 +1,5 @@
1
1
  require 'bog/initializer'
2
+ require 'fileutils'
2
3
 
3
4
  module Bog
4
5
  class Command
@@ -10,7 +11,6 @@ module Bog
10
11
  Dir.mkdir(profile_path) unless File.directory?(profile_path)
11
12
 
12
13
  Bog::Initializer::AWS.new(Bog::Profile.find(profile), options) if options.aws?
13
- Bog::Initializer::Chef.new(Bog::Profile.find(profile), options) if options.chef?
14
14
 
15
15
  end
16
16
 
@@ -21,6 +21,11 @@ module Bog
21
21
  profiles = File.join(bog_root, 'profiles')
22
22
  Dir.mkdir(bog_root) unless File.exists?(bog_root)
23
23
  Dir.mkdir(profiles) unless File.exists?(profiles)
24
+
25
+ # Drop the shell helpers in
26
+ spec = Gem::Specification.find_by_name("bog")
27
+ gem_root = spec.gem_dir
28
+ FileUtils.copy_file(File.join(gem_root, 'libexec/bog.sh'), File.join(bog_root, 'bog.sh'))
24
29
  end
25
30
  end
26
31
  end
@@ -0,0 +1,12 @@
1
+ require 'bog/profile'
2
+
3
+ module Bog
4
+ class Command
5
+ class Show
6
+ def self.execute
7
+ puts Bog::Profile.current.profile_name
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,4 @@
1
1
  require 'bog/initializer/aws'
2
- require 'bog/initializer/chef'
3
2
 
4
3
  module Bog
5
4
  class Initializer
@@ -23,7 +23,7 @@ module Bog
23
23
  if Dir.entries(File.expand_path('~/.bog/profiles')).include?(profile.to_s)
24
24
  return Bog::Profile.load(profile)
25
25
  else
26
- raise Bog::Profile::Exception::ProfileNotFound
26
+ raise Bog::Profile::Exception::ProfileNotFound
27
27
  end
28
28
  end
29
29
 
@@ -37,6 +37,15 @@ module Bog
37
37
  symlink(profile_root, current_status_file,)
38
38
  end
39
39
 
40
+ def make_default
41
+ puts "Making #{self.profile_name} default profile"
42
+ File.write(File.expand_path('~/.bog/default'), self.profile_name)
43
+ end
44
+
45
+ def self.current
46
+ Bog::Profile.find(File.basename(File.readlink(File.expand_path('~/.bog/current'))))
47
+ end
48
+
40
49
  private
41
50
 
42
51
  def profile_root
@@ -1,3 +1,3 @@
1
1
  module Bog
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,29 @@
1
+ #!/bin/bash
2
+ function _set_bog_profile {
3
+ local stop_flag=''
4
+ local current_directory=${PWD}
5
+ while [[ ${current_directory} != '/' ]] && [[ -z ${stop_flag} ]]; do
6
+
7
+ if [[ -e "${current_directory}/.bog-profile" ]]; then
8
+ bog $(cat "${current_directory}/.bog-profile")
9
+ stop_flag='.'
10
+ fi
11
+
12
+ current_directory=$(dirname ${current_directory})
13
+ done
14
+
15
+ # If we've never found a dotfile use the default
16
+ if [[ -z ${stop_flag} ]]; then
17
+ if [[ -e ~/.bog/default ]]; then
18
+ bog $(cat ~/.bog/default)
19
+ else
20
+ echo 'bog cannot find a default profile.'
21
+ echo 'You may set one with `bog PROFILE default`.'
22
+ echo 'If you choose not to do this your current'
23
+ echo 'profile will be set by the last .bog-profile.'
24
+ fi
25
+ fi
26
+ }
27
+
28
+ old_prompt_command=${PROMPT_COMMAND}
29
+ export PROMPT_COMMAND="_set_bog_profile; ${old_prompt_command}"
metadata CHANGED
@@ -1,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-12 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: slop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.4'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: require_all
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
69
83
  description: A tool for managing cloud API and configuration management credentials.
70
84
  rbenv for dotfiles.
71
85
  email:
@@ -75,9 +89,9 @@ executables:
75
89
  extensions: []
76
90
  extra_rdoc_files: []
77
91
  files:
78
- - .gitignore
79
- - .rspec
80
- - .travis.yml
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
81
95
  - Gemfile
82
96
  - LICENSE
83
97
  - README.md
@@ -86,14 +100,16 @@ files:
86
100
  - bog.gemspec
87
101
  - lib/bog.rb
88
102
  - lib/bog/command.rb
103
+ - lib/bog/command/default.rb
89
104
  - lib/bog/command/exec.rb
90
105
  - lib/bog/command/init.rb
106
+ - lib/bog/command/show.rb
91
107
  - lib/bog/initializer.rb
92
108
  - lib/bog/initializer/aws.rb
93
- - lib/bog/initializer/chef.rb
94
109
  - lib/bog/profile.rb
95
110
  - lib/bog/profile/exception.rb
96
111
  - lib/bog/version.rb
112
+ - libexec/bog.sh
97
113
  - spec/bog_spec.rb
98
114
  - spec/spec_helper.rb
99
115
  homepage: https://github.com/opsunit/bog
@@ -106,17 +122,17 @@ require_paths:
106
122
  - lib
107
123
  required_ruby_version: !ruby/object:Gem::Requirement
108
124
  requirements:
109
- - - ! '>='
125
+ - - ">="
110
126
  - !ruby/object:Gem::Version
111
127
  version: '0'
112
128
  required_rubygems_version: !ruby/object:Gem::Requirement
113
129
  requirements:
114
- - - ! '>='
130
+ - - ">="
115
131
  - !ruby/object:Gem::Version
116
132
  version: '0'
117
133
  requirements: []
118
134
  rubyforge_project:
119
- rubygems_version: 2.4.1
135
+ rubygems_version: 2.2.2
120
136
  signing_key:
121
137
  specification_version: 4
122
138
  summary: A tool for managing cloud API and configuration management credentials.
@@ -1,8 +0,0 @@
1
- module Bog
2
- class Initializer
3
- class Chef < Initializer
4
- def initialize(profile, options)
5
- end
6
- end
7
- end
8
- end