nova 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +19 -0
  3. data/README.md +29 -0
  4. data/bin/nova +8 -0
  5. data/lib/generator/template/new_install/galaxy/some_star.rb +3 -0
  6. data/lib/generator/template/new_install/supernova.yml +16 -0
  7. data/lib/nova.rb +49 -0
  8. data/lib/nova/cli.rb +62 -0
  9. data/lib/nova/commands/server.rb +71 -0
  10. data/lib/nova/common.rb +17 -0
  11. data/lib/nova/common/event_handler.rb +165 -0
  12. data/lib/nova/common/event_handler/event.rb +147 -0
  13. data/lib/nova/common/features.rb +93 -0
  14. data/lib/nova/common/features/feature.rb +65 -0
  15. data/lib/nova/common/metadata.rb +65 -0
  16. data/lib/nova/common/metadata/data.rb +171 -0
  17. data/lib/nova/common/star_management.rb +164 -0
  18. data/lib/nova/constructor.rb +84 -0
  19. data/lib/nova/exceptions.rb +16 -0
  20. data/lib/nova/project.rb +199 -0
  21. data/lib/nova/remote.rb +10 -0
  22. data/lib/nova/remote/fake.rb +51 -0
  23. data/lib/nova/remote/fake/commands.rb +44 -0
  24. data/lib/nova/remote/fake/file_system.rb +76 -0
  25. data/lib/nova/remote/fake/operating_system.rb +52 -0
  26. data/lib/nova/remote/fake/platform.rb +89 -0
  27. data/lib/nova/star.rb +25 -0
  28. data/lib/nova/starbound.rb +14 -0
  29. data/lib/nova/starbound/client.rb +59 -0
  30. data/lib/nova/starbound/encryptor.rb +134 -0
  31. data/lib/nova/starbound/encryptors.rb +13 -0
  32. data/lib/nova/starbound/encryptors/openssl.rb +122 -0
  33. data/lib/nova/starbound/encryptors/plaintext.rb +64 -0
  34. data/lib/nova/starbound/encryptors/rbnacl.rb +67 -0
  35. data/lib/nova/starbound/protocol.rb +81 -0
  36. data/lib/nova/starbound/protocol/encryption.rb +48 -0
  37. data/lib/nova/starbound/protocol/exceptions.rb +38 -0
  38. data/lib/nova/starbound/protocol/messages.rb +116 -0
  39. data/lib/nova/starbound/protocol/packet.rb +267 -0
  40. data/lib/nova/starbound/protocol/socket.rb +231 -0
  41. data/lib/nova/starbound/server.rb +182 -0
  42. data/lib/nova/version.rb +5 -0
  43. data/spec/constructor_spec.rb +20 -0
  44. data/spec/local_spec.rb +26 -0
  45. data/spec/nova_spec.rb +7 -0
  46. data/spec/spec_helper.rb +19 -0
  47. data/spec/star/some_type.rb +27 -0
  48. data/spec/star_spec.rb +107 -0
  49. data/spec/starbound/encryptor_spec.rb +33 -0
  50. data/spec/starbound/openssl_encryptor_spec.rb +80 -0
  51. data/spec/starbound/packet_spec.rb +61 -0
  52. data/spec/starbound/plaintext_encryptor_spec.rb +27 -0
  53. data/spec/starbound/protocol_spec.rb +163 -0
  54. data/spec/starbound/rbnacl_encryptor_spec.rb +70 -0
  55. metadata +166 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98f99f8e3d4e94b3634e3881015900048f2d1565
4
+ data.tar.gz: 16f716c8f300fa1ed9d2ff472f0ca0e1ee6e97cc
5
+ SHA512:
6
+ metadata.gz: e53c896e97cda1f47557f7cfa670af707175f2e13bddde1dbc9e3a0ca87daaf15f85ba15bbe943a7251cbbd73a9f7e9bb519fdfadeb833665989b03241480997
7
+ data.tar.gz: 4d46a1cfbc412411ffa75ed218c3cd4e907e6fdc8b63008fe7b3c78f15c0815fd7e1df5f81dcc16726c3bc9bc05f417e4f1509fc5277b16c40e190e62187b454
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Jeremy Rodi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Nova
2
+ [![Build Status](https://travis-ci.org/redjazz96/nova.png?branch=master)](https://travis-ci.org/redjazz96/nova) [![Code Climate](https://codeclimate.com/github/redjazz96/nova.png)](https://codeclimate.com/github/redjazz96/nova) [![Coverage Status](https://coveralls.io/repos/redjazz96/nova/badge.png?branch=master)](https://coveralls.io/r/redjazz96/nova?branch=master) [![Gem Version](https://badge.fury.io/rb/nova.png)](http://badge.fury.io/rb/nova)
3
+
4
+ ![A Very Pretty Nova](http://i.imgur.com/48AoWKo.jpg)
5
+ *Image credit to NASA*
6
+
7
+ ## What is Nova?
8
+ Nova is a way to set up software on computers in a definite and consistant process.
9
+ Its goals are to be cross-platform compatible, easy to use and understand, and
10
+ powerful.
11
+
12
+ ## Great! How do I get started?
13
+ It's not ready yet. It's still early in development, and there are a few things that need
14
+ tweaking. As of right now, it's 100% documented, and completely written in Ruby.
15
+ I have marked things that need to be done with a `@todo` tag. Go check it out if you want.
16
+ There are a few things I plan on adding to Nova before I release it.
17
+
18
+ ## Terminology
19
+ I came up with Nova as a name because I couldn't think of anything better. Turns out, it actually
20
+ fits. The code to set up a piece of software is called a `Star`, a server with stars is called a
21
+ `Cluster`, and (if applicable) the server to manage Clusters is called a `Nucleus` (or
22
+ `Axis`, I haven't made up my mind which).
23
+
24
+ ## License
25
+ Nova is licensed under the MIT License, which can be found [here](LICENSE).
26
+
27
+ @TODO: note benefit of installing posix-spawn when using local remote.
28
+
29
+ (note: in order to work with libsodium, the location of the library needs to be added to `LD_LIBRARY_PATH`)
data/bin/nova ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'thor'
5
+ require 'nova'
6
+ require 'nova/cli'
7
+
8
+ Nova::CLI.start
@@ -0,0 +1,3 @@
1
+ Nova star: :some_star do
2
+ # do something here
3
+ end
@@ -0,0 +1,16 @@
1
+ load_paths:
2
+ - ./galaxy
3
+
4
+ # If this is an array, every time we run +Nova server up+, multiple
5
+ # instances are created, each matching the values here.
6
+ servers:
7
+ - :name: tcp_server
8
+ :type: :tcp
9
+ :host: 0.0.0.0
10
+ :port: 2010
11
+ - :name: unix_server
12
+ :type: :unix
13
+ :path: "./Nova.sock"
14
+ :protocol:
15
+ :allow_plaintext: true
16
+
data/lib/nova.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'logger'
2
+
3
+ require 'nova/version'
4
+ require 'nova/project'
5
+ require 'nova/constructor'
6
+ require 'nova/exceptions'
7
+ require 'nova/remote'
8
+ require 'nova/star'
9
+
10
+ require 'nova/starbound'
11
+
12
+ # A Game management software. Also note that a method named
13
+ # +Nova+ is available under the top-level namespace, which acts
14
+ # as an alias for {Nova.create}.
15
+ #
16
+ # @api public
17
+ module Nova
18
+
19
+ # The Nova logger. By default outputs to STDOUT.
20
+ #
21
+ # @return {Logger}
22
+ def self.logger
23
+ @logger ||= Logger.new(STDOUT)
24
+ end
25
+
26
+ attr_writer :logger
27
+
28
+ # This creates a star with a given block, unless it already exists;
29
+ # if it does, it just modifies that star.
30
+ #
31
+ # @param options [Hash{Symbol => Symbol}] the first key value pair
32
+ # is used to determine the star type and star name, while the
33
+ # rest is ignored.
34
+ # @yield [] to create the star.
35
+ # @return [Class] the new star.
36
+ def self.create(options, &block)
37
+ Constructor.new(options, &block).modify_or_create
38
+ end
39
+ end
40
+
41
+ # Creates or modifies a star, with the given options and block.
42
+ #
43
+ # @see Nova.create
44
+ # @param (see Nova.create)
45
+ # @yield (see Nova.create)
46
+ # @return [Class] the new star.
47
+ def Nova(options, &block)
48
+ Nova.create(options, &block)
49
+ end
data/lib/nova/cli.rb ADDED
@@ -0,0 +1,62 @@
1
+ require 'nova/commands/server'
2
+ module Nova
3
+
4
+ # Handles the command line interface. Uses thor to do that.
5
+ class CLI < ::Thor
6
+
7
+ include Thor::Actions
8
+
9
+ class_option :path, :type => :string, :default => "."
10
+
11
+ # The source thor should use for managing files.
12
+ #
13
+ # @api private
14
+ # @return [String]
15
+ def self.source_root
16
+ File.absolute_path("../../generator/template", __FILE__)
17
+ end
18
+
19
+ desc "install PATH", "Installs a Galaxy into the given path."
20
+ # Installs a galaxy into the given path. Just copies the files
21
+ # and folders in lib/generator/template/new_install into the
22
+ # given folder.
23
+ #
24
+ # @return [void]
25
+ def install(to)
26
+ directory("new_install", to)
27
+ end
28
+
29
+ desc "list", "List all of the available stars."
30
+ # Lists all of the stars that the project has available to it.
31
+ # Requires the --path parameter or to be in a project folder.
32
+ #
33
+ # @return [void]
34
+ def list
35
+ project.require_files
36
+
37
+ Star.stars.each do |key, value|
38
+ shell.say("#{key}:", :green, :bold)
39
+
40
+ value.each do |k, v|
41
+ shell.say "\t#{k}"
42
+ end
43
+ end
44
+ end
45
+
46
+ desc "server SUBCOMMAND [...ARGS]", "Manage Nova servers."
47
+ subcommand "server", Commands::Server
48
+
49
+ private
50
+
51
+ # Returns the project instance for the folder.
52
+ #
53
+ # @see Project
54
+ # @return [Project]
55
+ def project
56
+ @_project ||= Project.new(options[:path])
57
+ end
58
+ end
59
+ end
60
+
61
+ # Subcommands and other stuff to be used with thor.
62
+ module Nova::Commands; end
@@ -0,0 +1,71 @@
1
+ module Nova
2
+ module Commands
3
+
4
+ # Handles server operations for projects.
5
+ class Server < ::Thor
6
+
7
+ desc "up", "Runs the servers."
8
+ method_option :foreground, :type => :boolean,
9
+ :desc => "Run the process in the foreground.",
10
+ :default => false
11
+ method_option :which, :type => :array, :banner => "<servers>",
12
+ :desc => "Which servers to run. Empty means all.",
13
+ :default => []
14
+ long_desc <<-DESC
15
+ Runs servers defined in Nova.yml. If the forgeground
16
+ option is specified, the process is run in the foreground.
17
+ Otherwise, it's ran as a daemon. If the which parameter is
18
+ specified, it only runs the servers that were specified.
19
+
20
+ Options that can be defined for servers include:
21
+
22
+ :name :: the name of the server. Used to name the pid
23
+ files and the log files.
24
+
25
+ :type :: the type of server. Can be :tcp or :unix. If
26
+ it's :tcp, options :ip and :port can be defined
27
+ and will be used. If it's :unix, the option :path
28
+ can be defined for the path to the socket.
29
+ Defaults to :tcp.
30
+
31
+ :host :: the IP address to bind to. Only applicable if
32
+ :type is :tcp. Defaults to 127.0.0.1.
33
+
34
+ :port :: the port to bind to. Only applicable if :type is
35
+ :tcp. Defaults to 2010.
36
+
37
+ :path :: the path to the UNIX socket. Only applicable if
38
+ :type is :unix. Defaults to /tmp/sock.
39
+
40
+ :protocol:: protocol options, used for settings in the
41
+ protocol. only current option is :allow_plaintext,
42
+ which prevents the server from raising an
43
+ exception if the protocol negotiates a plaintext
44
+ encryption (insecure).
45
+ DESC
46
+ # Runs the servers. Run +Nova server help up+ for
47
+ # information on this command.
48
+ #
49
+ # @see Project
50
+ # @see Project#run_servers
51
+ # @return [void]
52
+ def up
53
+ Project.new(parent_options[:path]).run_servers(
54
+ !options[:foreground], options[:which])
55
+ end
56
+
57
+ desc "down", "Takes down running servers."
58
+ method_option :which , :type => :array, :banner => "<servers>",
59
+ :desc => "Which servers to remove. Empty means all.",
60
+ :default => []
61
+ # Handles taking down servers.
62
+ #
63
+ # @see Project
64
+ # @see Project#shoot
65
+ # @return [void]
66
+ def down
67
+ Project.new(parent_options[:path]).shoot(options[:which])
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,17 @@
1
+ require 'nova/common/event_handler'
2
+ require 'nova/common/star_management'
3
+ require 'nova/common/metadata'
4
+ require 'nova/common/features'
5
+
6
+ module Nova
7
+
8
+ # This defines the methods that are common to all remotes, as in,
9
+ # platform independent, in the truest sense of the word.
10
+ module Common
11
+
12
+ # The possible platforms that can exist.
13
+ POSSIBLE_PLATFORMS = [:posix, :linux, :osx, :windows, :ubuntu,
14
+ :red_hat, :arch].freeze
15
+
16
+ end
17
+ end
@@ -0,0 +1,165 @@
1
+ require 'set'
2
+
3
+ require 'nova/common/event_handler/event'
4
+
5
+ module Nova
6
+ module Common
7
+ # Handles events sent to the receiver to be processed.
8
+ module EventHandler
9
+
10
+ # Class methods.
11
+ module ClassMethods
12
+
13
+ # A list of all of the events defined in the class.
14
+ #
15
+ # @return [Set<EventHandler::Event>]
16
+ def events
17
+ @_events ||= Set.new
18
+ end
19
+
20
+ # Creates an event, adds it to the list, and returns it.
21
+ #
22
+ # @param event [Symbol] the name of the event.
23
+ # @param options [Hash] the options for the event, when creating
24
+ # it.
25
+ # @yieldparam options [Hash] the options for the event when ran.
26
+ # The contents of the options hash is defined at the time when
27
+ # ran.
28
+ # @option (see Event#initialize)
29
+ # @return [Event] the event.
30
+ def on(event, options = {})
31
+ events << Event.new(event, options, Proc.new)
32
+ end
33
+
34
+ alias_method :to, :on
35
+
36
+ # Checks to see if an event with the given name exists.
37
+ #
38
+ # @note Even if the event with the given name may exist,
39
+ # the event may still not exist if the options don't match.
40
+ # If you want to make sure that the event will respond to
41
+ # the name and options, check {#has_event_with_options?}.
42
+ # @param name [Symbol] the name of the event.
43
+ # @return [nil, Event]
44
+ def has_event?(name)
45
+ events.dup.keep_if { |e| e.name == name }.to_a.first
46
+ end
47
+
48
+ # Checks to see if an event can respond to the given name and
49
+ # options.
50
+ #
51
+ # @param name [Symbol] the name of the event.
52
+ # @param options [Hash] the options for the event.
53
+ # @return [nil, Event]
54
+ def has_event_with_options?(name, options = {})
55
+ event = Event.new(name, options)
56
+ event.type = :search
57
+ events.dup.keep_if { |e| e.match? Star.new, event }.to_a.first
58
+ end
59
+ end
60
+
61
+ # Instance methods.
62
+ module InstanceMethods
63
+
64
+ include ClassMethods
65
+
66
+ # Automatically binds the {Star} to itself on initialization.
67
+ def initialize(*)
68
+ bind remote.new
69
+ super()
70
+ end
71
+
72
+ # Returns the event list.
73
+ #
74
+ # @see ClassMethods#events
75
+ # @return [Set<EventHandler::Event>]
76
+ def events
77
+ @_events ||= self.class.events.dup
78
+ end
79
+
80
+ # Checks to see if an event can respond to the given name and
81
+ # options.
82
+ #
83
+ # @param (see ClassMethods#has_event_with_options?)
84
+ # @return (see ClassMethods#has_event_with_options?)
85
+ def has_event_with_options?(name, options = {})
86
+ event = Event.new(name, options)
87
+ event.type = :search
88
+ events.dup.keep_if { |e| e.match? self, event }.to_a.first
89
+ end
90
+
91
+ # Runs an event, with the given name and options.
92
+ #
93
+ # @raise [NoEventError] when it can't find the event.
94
+ # @param name [Symbol] the name of the event.
95
+ # @param options [Hash] the options to pass to the
96
+ # event.
97
+ # @return [Object] the result of the event.
98
+ def run!(name, options = {})
99
+ matched = has_event_with_options? name, options
100
+
101
+ if matched
102
+ matched.run(bind, options)
103
+ else
104
+ raise NoEventError, "Could not find event #{name}."
105
+ end
106
+ end
107
+
108
+ # Calls {#run!}, but if it raises a [NoEventError] it returns it
109
+ # instead of raising it.
110
+ #
111
+ # @see #run!
112
+ # @param (see #run!)
113
+ # @return [Object, NoEventError] the result of the event, or the
114
+ # exception.
115
+ def run(name, options = {})
116
+ run! name, options
117
+
118
+ rescue NoEventError => e
119
+ e
120
+ end
121
+
122
+
123
+ # Binds this event handler to a given object, running all events in
124
+ # the context of that object.
125
+ #
126
+ # @param bind [Object] the object to bind to.
127
+ # @return [self]
128
+ def bind!(bind)
129
+ @bind = bind
130
+ self
131
+ end
132
+
133
+ # @overload bind(bind)
134
+ # Binds a copy of this object to a given object, running
135
+ # all events in the context of that object.
136
+ #
137
+ # @param bind [Object] the object to bind to.
138
+ # @return [Feature]
139
+ # @overload bind
140
+ # Returns the current bind. Creates an empty object if
141
+ # it doesn't exist.
142
+ #
143
+ # @return [Object]
144
+ def bind(bind = nil)
145
+ if bind
146
+ dup.bind!(bind)
147
+ else
148
+ @bind ||= Object.new
149
+ end
150
+ end
151
+ end
152
+
153
+ # Called when {EventHandler} is included. Extends what included
154
+ # it by {ClassMethods}, and includes {InstanceMethods}.
155
+ #
156
+ # @param receiver [Object]
157
+ # @return [void]
158
+ # @api private
159
+ def self.included(receiver)
160
+ receiver.extend ClassMethods
161
+ receiver.send :include, InstanceMethods
162
+ end
163
+ end
164
+ end
165
+ end