Project

silk

0.0
No commit activity in last 3 years
No release in over 3 years
It allows you to write rake tasks to do common tasks, such as creating email addresses, adding users etc. Silk provides a HTTP wrapper the the rake tasks, and allows communication via JSON objects, which makes it dead easy for them to be called from a web app.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 1.6.4
>= 0
>= 0
= 1.2.2

Runtime

 Project Readme

silk¶ ↑

Silk is a a flexible framework for building web hosting consoles. It’s based around a rake task runner that has a HTTP/JSON interface. It allows you to build rake tasks to do things like add users, create email addresses etc. Then you simply wrap the response in a JSON envelope, and you can then build your own custom web hosting console.

This gem is just the runner, that need to be installed on all client servers.

Installation¶ ↑

(Requires Gemcutter)

gem install silk

Create /etc/silk and drop *.rake files in /etc/silk (or $HOME/.silk/) and they will automatically be read in.

Usage¶ ↑

The gem should install an executable called silk run

silk -h

for full argument descriptions.

The system automatically converts the rest URL (only GETs at the moment) into a rake task name - if the name doesn’t exist, you’ll get a 404. Any query params get passed into the task

So http://localhost:8888/users/get?login=myles (Returns Plain text)
So http://localhost:8888/users/get.json?login=myles (Returns JSON)
So http://localhost:8888/users/get.xml?login=myles (Returns XML)

would run the users:get task. do something like this in the rake task:

require 'json'

namespace :users do
  task :get do |t, args|
    # args[:login] will be populated with myles
    if args[:login]
      respond_to do |format|
        format.text { "Success" }
        format.xml { "<body>Success</body>" }
        format.json { "Success".to_json }
      end
    else
      error_respond_to do |format|
        format.text { "Fail" }
        format.xml { "<error>Fail</error>" }
        format.json { "Fail".to_json }
      end
      exit(-1)
    end
  end
end

NOTE: The idea is you write your own rake task to do stuff, and then interface them how you want. The project doesn’t care what data you transfer and represent, although it would be possible to share rakefiles and interfaces for common tasks.

By default it runs on port 8888 and will probably need to be run as root to make sure you can do all the stuff you need to do.

Eventually it’ll support SSL certificates etc, but until then, I suggest you either use SSH tunnels, and/or (at the very least) lock down via a firewall.

Racking it up¶ ↑

You can run Silk as a Rack app, which will allow you to run Silk in Passenger, or other Rack-compatible servers.

First, create a Gemfile

gem 'silk', :version => '>= 0.6'

then run

bundle install

At the moment, you have to create an empty Rakefile

touch Rakefile

Here is a sample config.ru file

require 'rubygems'
require 'bundler'
Bundler.require

Silk.options = { :recipe_paths => [ File.join(File.dirname(__FILE__), 'recipes') ] }
run Silk::Application

Then to test you can run rackup

rackup ./config.ru

Put your .rake files in the recipes directory, and you can hit the rackup test server on port 9292

Testing your recipes¶ ↑

There are two ways to test your recipes - you can chose to just run them on the command line, using the -t switch

silk -t --param user=joe --param email=joe@blogs.com --format json

or via unit tests.

require 'silk'

class TestDSL < Test::Unit::TestCase
  results = Runner.execute('task:name', { 'user' => 'joe', 'email' => 'joe@blogs.com' })
end

the results hash will have three elements: stdout, stderr and a process result object

results[:stdout]
results[:stderr]
results[:status]

To get the exit status of the task:

status = results[:status].exitstatus

Testing Silk¶ ↑

There is a test suite. It uses shoulda + mocha + test::rack

If you are going to submit patches, please try to make sure the tests pass, and that you have created a test covering the changes you have made

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but

    bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010,2011 Myles Eftos. See LICENSE for details.