class API::V1::ItemsController

Public Instance Methods

show() click to toggle source

Retrieve the password using the Item id or full path to the item. Returns text for password by default, but it can return XML or JSON using the extensions. In that case it will return the hash containg the username, the password and the item ID.

GET|POST /_api/v1/_password/:item_id[.xml|.json]

GET|POST /_api/v1/path_to_item*[.xml|.json]

parameters
  • item_id

  • path to the password (all directories separated by slash, followed by username)

Examples

resp = conn.get("http://localhost:3000/_api/v1/_password/1", email: "email0@example.com", password="password0")
password = resp.body if resp.status == 200
#=> "secret"

resp = conn.get("http://localhost:3000/_api/v1/databases/C84PCPY/scott", email: "email0@example.com", password="password0")
password = resp.body if resp.status == 200
#=> "tiger"

resp = conn.get("http://localhost:3000/_api/v1/databases/C84PCPY/scott.json", email: "email0@example.com", password="password0")
resp.body
#=> "{"username":"scott","password":"tiger"}"

Shell

via get

PASSWORD=`curl "http://localhost:3000/_api/v1/_password/1?email=email0@example.com&password=password0"`

via http authentication

PASSWORD=`curl --user email0@example.com:password0 "http://localhost:3000/_api/v1/_password/1"`

with token

OS_TOKEN=`curl "http://localhost:3000/_api/v1/_authorize?email=email0@example.com&password=password0"`

PASSWORD=`curl -H "Authorization: Token token=$OS_TOKEN" "http://localhost:3000/_api/v1/_password/1"`

using path instead of id

PASSWORD=`curl "http://localhost:3000/_api/v1/databases/C84PCPY/sysadm?email=email0@example.com&password=password0"`

# File app/controllers/api/v1/items_controller.rb, line 35
def show
  # logger.debug " ---------- params: #{params}"
  if params[:id]
    item = Item.find(params[:id])
  elsif params[:path]
    dir = File.dirname(params[:path])
    if dir == "/" || dir == "."
      d = Directory.root
    else
      d = Directory.cd(dir)
    end
    b = File.basename(params[:path])
    case File.extname(b)
    when '.xml', '.text', '.json'
      request.format = File.extname(b).gsub('.', '').to_sym
      b = File.basename b, File.extname(b)
    end
    item = d.items.find_by(username: b)
  end
  if item && item.password(authorization_user: current_user)
    respond_to do |format|
      format.json { render json: item_data(item)}
      format.xml  { render xml:  item_data(item)}
      format.text { render text: item.password(authorization_user: current_user)}
    end
  else
    respond_to do |format|
      format.text { render text: 'unprocessable', status: :unprocessable_entity }
      format.json { render text: {status: 'unprocessable'}, status: :unprocessable_entity }
      format.xml  { render text: {status: 'unprocessable'}, status: :unprocessable_entity }
    end
  end
end