dakrone / es-mode

An Emacs major mode for interacting with Elasticsearch
GNU General Public License v3.0
195 stars 34 forks source link

Read authinfo for user and password information #52

Open FrancescElies opened 7 years ago

FrancescElies commented 7 years ago

Hi,

I found the following issue, but I am not sure if I am missing something, does anyone know what is going on?

Thanks in advance for your help.

Context

Problem: es-mode does not read .authinfo but a es-mode block in org-mode does.

Description

The following works really nice in org-mode buffer

Buffer content:

  #+srcname: list indices
  #+BEGIN_SRC es
  GET /_cat/indices?v&pretty
  #+END_SRC

Outcome:

  #+RESULTS: list indices
  #+begin_example
  health status index                         uuid                   pri rep docs.count docs.deleted store.size pri.store.size
  yellow open   .watcher-history-3-2017.06.28 2t3Io9wRRN6shonkQZkXvA   1   1       2094            0      1.6mb          1.6mb
  yellow open   .monitoring-es-2-2017.06.28   _YJHpwPfTcKGxDiM-TGNJQ   1   1      32073          110     14.4mb         14.4mb
  ...
  #+end_example

In this case the src-block reads the content of authinfo and uses it to set the headers in the request.

But if I do the same request in es-mode it does not work, see Steps to Test.

Steps to Test

  1. Pull elasticsearch image from docker and run it

    docker pull elasticsearch
    docker run -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" docker.elastic.co/elasticsearch/elasticsearch:5.4.3
  2. This image has a default user and password, add the following line to ~/.authinfo.gpg

    machine localhost login elastic password changeme port 9200
  3. Open scratch buffer and set es-mode

  4. Insert the following text

    GET /_cat/indices?v&pretty
  5. Execute it C-c C-c

  6. I see:

    {
    "error" : {
      "root_cause" : [
        {
          "type" : "security_exception",
          "reason" : "missing authentication token for REST request [/_cat/indices?v&pretty]",
          "header" : {
            "WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
          }
        }
      ],
      "type" : "security_exception",
      "reason" : "missing authentication token for REST request [/_cat/indices?v&pretty]",
      "header" : {
        "WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
      }
    },
    "status" : 401
    }
dakrone commented 7 years ago

Problem: es-mode does not read .authinfo but a es-mode block in org-mode does.

I believe this may be due to es-mode using a different http request library than org-mode does, but I can look into this!

FrancescElies commented 7 years ago

Thanks for your answer, by the way I was gladly surprised that it worked with .authinfo.gpg 👍 Is there any other way of setting user and password for the requests? I'll also investigate this a bit more and report back any findings.

All best and thanks

dakrone commented 7 years ago

(for my reference) looks like I could use the auth-source library to access the .authinfo.gpg file to get the credentials needed https://www.gnu.org/software/emacs/manual/html_mono/auth.html

FrancescElies commented 4 years ago

Closing, I am not using this since a long time and I feel nothing will happen here, thanks for your help.

dakrone commented 4 years ago

I'd prefer to leave this open, I do think it would be an interesting feature, and you never know when I (or someone!) would have time to work on it.