4Trabes Historias de una empresa en 100 metros cuadrados

El blog de Trabe Soluciones

wsecli: a websocket client in Erlang

| | Comentarios

I’m combining my work at Trabe with doing my end of degree project - someday I’ll post about it. This end of degree project (EOP from now on) uses a nice amount of technologies being Erlang one of them.

A part of the EOP is a WebSocket endpoint built in Erlang (with cowboy). To run some automated test on this endpoint I needed a WebSocket client in Erlang that was conformant to the last WebSocket version, wich now is the RFC6455 for WebSocket version 13. To my dispair I could only find clients (not many) that were built for old versions of the protocol.

So…I had two choices:

  • Skip all the tests wich involved using a client.
  • Build a client wich implements the RFC6455.

So…being me I built it.

The result is wsecli, a WebSocket client writen in Erlang wich implements the aforementioned WebSocket rfc6455. It was a nice toy-project to get a deeper understanding of:

  • Erlang’s bit sintax which kicks asses when having to deal with data at a bit/byte level. Oh, fuck yeah!
  • WebSocket protocol itself.

Using this project as a base I’m now working on wsock, a library to help you build WebSocket clients (like wsecli) and servers in Erlang. That’s for a future post (woo, too may posts piling up).

If you have any doubt or question comment or tweet me at @madtrick.

Net::IMAP y autenticación PLAIN con Ruby 1.8.7

| | Comentarios

Hace poco tuvimos que recuperar correos de un servidor utilizando IMAP (con conexión segura) desde una aplicación legacy que corre sobre Ruby 1.8.7. En principio, era una tarea sencilla, sólo teníamos que usar net/imap: conectarnos, autenticarnos, recuperar los correos y listo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ irb -r
>> require 'net/imap'
=> true
>> session = Net::IMAP.new("mail.server.com", 993, true)
=> #<Net::IMAP:0x19fb2c0 @tagno=0, @continuation_request=nil, ...

>> session.capability
=> ["ACL", "BINARY", "CATENATE", "CHILDREN", "CONDSTORE", "ENABLE", "ESEARCH", "ID", "IDLE", 
    "IMAP4REV1", "LIST-EXTENDED", "LITERAL+", "MULTIAPPEND", "NAMESPACE", "QRESYNC", "QUOTA", 
    "RIGHTS=EKTX", "SASL-IR", "SEARCHRES", "UIDPLUS", "UNSELECT", "WITHIN", "ESORT", "I18NLEVEL=1", 
    "SORT", "THREAD=ORDEREDSUBJECT", "AUTH=PLAIN"]

>> session.authenticate('PLAIN', "user", "plain_password")
ArgumentError: unknown auth type - "PLAIN"
  from /home/david/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/net/imap.rb:359:in `authenticate'
  from (irb):4

¡Ups!. Consultando la documentación observamos que la librería sólo soporta los métodos de autenticación, LOGIN y CRAM-MD5. Ningún problema. net/imap permite registrar mecanismos de autenticación adicionales.

1
2
3
4
5
6
7
8
9
10
11
12
class ImapPlainAuthenticator
  def initialize(user, password)
    @user = user
    @password = password
  end

  def process(data)
    return "#{@user}\0#{@user}\0#{@password}"
  end
end

Net::IMAP::add_authenticator('PLAIN', ImapPlainAuthenticator)
1
2
3
4
5
6
7
$ irb -r
>> require 'net/imap'
>> require 'imap_plain_authenticator.rb'
>> session = Net::IMAP.new("mail.udc.es", 993, true
=> #<Net::IMAP:0x1b0edb0 @tagno=0, @continuation_request=nil, ...
>> session.authenticate('PLAIN', "user", "plain_password")
=> #<struct Net::IMAP::TaggedResponse tag="RUBY0001", name="OK", ...

Voilà, C’est fini.

¿Qué pasa con Ruby 1.9.x?

En la documentación no lo indica, pero si utilizáis Ruby 1.9.x veréis que sí incorpora soporte AUTH=PLAIN y no es necesario que registréis esta extensión.

Bye bye Mephisto, Hello Octopress

| | Comentarios

Un silencio en el blog de cuatro meses significa varias cosas: que estamos trabajando como animales, que estamos demasiado vagos para escribir o que también, como sucede en este caso, le hayamos dado un lavado de cara.

La novedad más destacable no es el cambio de look, si no el cambio tecnológico. Abandonamos Mephisto (que llevaba con nosotros desde 2006) y adoptamos Octopress.

Octopress es un framework que utiliza Jekyll como base y que facilita la creación y gestión de blogs. Incopora una plantilla HTML5 semántica, un layout “responsive”, temificación con Compass y Sass, integración con Disqus, una pléyade de plugins y alguna cosilla más. Para nosotros, más que un cambio tecnológico implica un cambio en la manera de trabajar: en lugar de pegarnos con la administración de Mephisto nos dedicamos a abrir un editor, escribir, hacer commits y desplegar.

En cuanto al look (o al no-look), aun no estamos del todo satisfechos, pero no queríamos seguir con el blog parado. Podéis considerar que es un work in progress y aun tenemos que ajustar cosillas. Consideramos que lo más importante es tener buenos contenidos en el blog y últimamente no hemos estado muy productivos. Esperemos que este reset venga acompañado de muchos e interesantes posts.