我尝试使用Opscode Chef API验证一个用户
require 'rubygems'
require 'chef/config'
require 'chef/log'
require 'chef/rest'
chef_server_url = 'http://127.0.0.1'
client_name = 'admin'
signing_key_filename = '/root/admin.pem'
rest = Chef::REST.new(chef_server_url, client_name, signing_key_filename)
puts rest.get_rest('/organizations/example/users/admin')
puts rest.get_rest('/organizations/example/clients')
puts rest.get_rest('/organizations/example/users')
bugabuga = {"username" => "admin","password" => "4dm1n1str4t0r"}
puts rest.post_rest('/organizations/example/authenticate_user', bugabuga)
但我收到了POST方法的404。
这是输出
{"username"=>"admin", "email"=>"the_good@example.com", "display_name"=>"the administrator", "first_name"=>"the", "last_name"=>"administrator", "middle_name"=>"", "public_key"=>"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtilYX/92ZuEPcP7D2VQ4\nKyU5koWvzS9SkWwkvRI8nmH6C+ELWz9iDfwCb5r4ioZUYx56i1JB/srhdBQMhDKN\na2qyoqaEiIFkIKKJIqAg1h5UHDjxL/8SF9BTdcoMyDmr7tDd2gpfEOc1+ILaOSca\nY3TjfPbdM+eo5jyEuxGz+OnhuPx1KUwTmMFpVkNXR38R+sbzQWKJrjMhCo/6aIZk\niutH7MCeO9Ff60WeYd+B6PSz+r0UaryPaViFwIGk1AYuTRQJ+9yUAwJwGMIqAUQo\nzZPcgp4tSpqHLojtlDlNvPXRFgtqKMzsndBhbZSoiD1g4ZhWvTbLZlHo9wUQeEXj\nDQIDAQAB\n-----END PUBLIC KEY-----\n\n"}
{"example-validator"=>"https://127.0.0.1/organizations/example/clients/example-validator", "node01"=>"https://127.0.0.1/organizations/example/clients/node01"}
{"user"=>{"username"=>"admin"}}
/usr/lib/ruby/1.9.1/net/http.rb:2633:in `error!': 404 "Not Found" (Net::HTTPServerException)
from /var/lib/gems/1.9.1/gems/chef-11.4.0/lib/chef/rest.rb:199:in `block in raw_http_request'
from /var/lib/gems/1.9.1/gems/chef-11.4.0/lib/chef/rest.rb:280:in `retriable_rest_request'
from /var/lib/gems/1.9.1/gems/chef-11.4.0/lib/chef/rest.rb:164:in `raw_http_request'
from /var/lib/gems/1.9.1/gems/chef-11.4.0/lib/chef/rest.rb:158:in `api_request'
from /var/lib/gems/1.9.1/gems/chef-11.4.0/lib/chef/rest.rb:118:in `post'
from test.rb:18:in `<main>'
从官方文档:https://docs.chef.io/api_chef_server.html#authenticate-user
我无法让它发挥作用。
知道我遗失了什么?
答案 0 :(得分:1)
阅读几天后......我找到了查询Chef API的正确方法。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:call-template name="text">
<xsl:with-param name="node" select="/body/kanaal/antwoord/antwoordTekst" />
</xsl:call-template>
<xsl:call-template name="text">
<xsl:with-param name="node" select="/body/kanaal/antwoord/antwoordProductVeld" />
</xsl:call-template>
<xsl:call-template name="address">
<xsl:with-param name="node" select="/body/kanaal/antwoord/antwoordAdres" />
</xsl:call-template>
<xsl:if test="/body/kanaal/verwijzingOverigeInfo" >
<ul>
<xsl:for-each select="/body/kanaal/verwijzingOverigeInfo" >
<xsl:call-template name="moreinfo">
<xsl:with-param name="node" select="self::node()" />
</xsl:call-template>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
<xsl:template name="text">
<xsl:param name="node" />
<xsl:if test="normalize-space($node/text())">
<xsl:value-of select="$node"/>
</xsl:if>
</xsl:template>
<xsl:template name="address">
<xsl:param name="node" />
<xsl:for-each select="$node/instantie">
<p class="vac_address">
<xsl:for-each select="*">
<xsl:call-template name="address_element"/>
</xsl:for-each>
</p>
</xsl:for-each>
</xsl:template>
<xsl:template name="address_element">
<xsl:if test=". != ''">
<xsl:element name="span">
<xsl:attribute name="class">
<xsl:value-of select ="name(.)"/>
</xsl:attribute>
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template name="moreinfo">
<xsl:param name="node" />
<li>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="$node/@resourceIdentifier" />
</xsl:attribute>
<xsl:value-of select="$node" />
</xsl:element>
</li>
</xsl:template>
</xsl:stylesheet>
现在我收到了403,但至少URL路径是正确的,一旦我修复了禁止的东西,我会给出答案。