Can't create new RavenDB database with Ruby rest_client - ruby

I'm trying to create a new RavenDb using the Ruby rest_client but I continually get 400 errors. Below is my simple script which I'm running on the local machine. I have also tried the PUTS command but it results in the same error. Thank you for your help!
Windows Server 2012
RavenDB version 2261
require 'rest_client'
require 'json'
config = Hash.new
config["Settings"] = Hash.new
config["Settings"]["Raven/DataDir"] = "~\\Databases\\TempWebState2"
config["Settings"]["Raven/ActiveBundles"] = "PeriodicBackup;DocumentExpiration"
RestClient.post "http://localhost:8081/Raven/Databases/TempWebState2", config.to_json

To fix this I had to change the RestClient command to put and change the URL to admin/databases/. Also Raven/AnonymousAccess had to be set to Admin
RestClient.put "http://localhost:8081/admin/databases/TempWebState2", config.to_json

Related

Ruby cannot get Azure VM metadata from Azure Instance Metadata service

According to MS documentation https://learn.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service
Azure provide instance metadata service at "http://169.254.169.254/metadata/instance?api-version=2017-08-01" .
But I failed to get the metadata on one of my VMs with ruby. While, I can get the metadata with PowerShell.
OS Environment: Windows Server 2012R2.
Ruby version: ruby 2.5.3p105 (2018-10-18 revision 65156) [x64-mingw32]
PowerShell version: 4.0
PowerShell code:
Invoke-WebRequest -Headers #{"Metadata"="true"} -URI "http://169.254.169.254/metadata/instance?api-version=2017-08-01"
response from powershell code:
StatusCode : 200
StatusDescription : OK
...
Ruby Code:
require 'net/http'
AZURE_METADATA_ADDR = "169.254.169.254".freeze unless defined?(AZURE_METADATA_ADDR)
AZURE_METADATA_URL = "/metadata/instance?api-version=2017-08-01".freeze unless defined?(AZURE_METADATA_URL)
def http_get(uri)
conn = Net::HTTP.start(AZURE_METADATA_ADDR)
conn.read_timeout = 6
conn.get(uri, { "Metadata" => "true" })
end
puts "Fetching metadata from host #{AZURE_METADATA_ADDR} at #{AZURE_METADATA_URL}"
response = http_get(AZURE_METADATA_URL)
puts response
Response from Ruby code:
Fetching metadata from host 169.254.169.254 at /metadata/instance?api-version=2017-08-01
#<Net::HTTPNotFound:0x0000000002372128>
Anyone can advice how to continue troubleshooting this issue? Is the problem inside Ruby?
PS. this is an embedded Ruby provided by chef client
So, this worked for me:
require 'net/http'
require 'json'
http = Net::HTTP.new('169.254.169.254', '80')
request = Net::HTTP::Get.new('/metadata/instance?api-version=2020-06-01')
request['Metadata'] = 'true'
response = http.request(request)
JSON.parse(response.body)
... on Ruby 2.5.5. The only obvious difference I see is the explicit port setting to '80'.
It turned out to be an environment variable "http_proxy" is preventing ruby from accessing the endpoint. The resolution is to set "no_proxy" environment variable and set '169.254.169.254' in the list of "no_proxy".
Ruby honors "http_proxy" while other languages like powershell and java don't honor it.

Send request and response get from server - Need working code for this WSDL file in RUBY

Please help me, I need code for my WSDL file for below wsdl file url using RUBY language parameter can be passed as pcEmployeecode...
Parameter can passed as STRING ie.,pcEmployeeCode="02385"
url ="http://online.mccolls.com.au:8080/wsa/wsa1/wsdl?targetURI=urn:OHWebServiceFMGT"
Please Refer this WSDL file and post me if you have sucess fully got the response result...
Any idea's....
I used like this, Still error hitting.
require 'rubygems'
#require 'soap4r'
require 'http-access2'
require 'soap/rpc/driver'
require 'soap/rpc/driver'
require 'net/http'
Net::HTTP.version_1_2
url =
"http://online.mccolls.com.au:8080/wsa/wsa1/wsdl?targetURI=urn:OHWebServiceFMGT"
soap = SOAP::RPC::Driver.new(url,"urn:OHWebServiceFMGT")
soap.wiredump_dev = STDERR
soap.options["protocol.http.ssl_config.verify_mode"] =
OpenSSL::SSL::VERIFY_NONE
soap.add_method('getEmployeeFmgtDetails','pcEmployeeCode')
puts soap.getEmployeeFmgtDetails('02385')

SOAP - Need to understand the error I get

I'm trying to initialize a variable called proxy like this:
proxy = Savon::Client.new "http://192.168.1.1:8080"
The thing is, when I run my code, I only get the error:
NameError: uninitialized constant NameOfTheClass::Savon
Thanks for any help!
PD: I'm using Ruby 1.9.2
PD2: I'm trying to run this from console.
You found probably the documentation for versions < 0.8.x.
Unfortunately the syntax has changed! Have a look here: https://github.com/rubiii/savon/blob/master/README.md
Savon works with blocks now.
Your example should now look like this
require 'savon'
require 'pp'
proxy = Savon::Client.new do
wsdl.document = "http://my.webservices.net/service?wsdl"
end
pp proxy.wsdl.soap_actions

adding 'curl' command to sinatra and rails?

(GAVE UP ON INSTALLING CURB. POSTED NEW QUESTION PER SUGGESTION OF ONE OF THE RESPONDENTS)
I thought 'curl ' was 'built-in' but got an undefined method error in a sinatra app. is there a gem i need to add?
Same question for rails 3?
The application is that I have to simply 'hit' an external url (http://kickstartme.someplace.com?action=ACTIONNAME&token=XYZXYZXYZ) to kickstart a remote process.
the external url returns XML describing success/failure in the format:
<session>
<success>true</success>
<token>xyzxyzxyz</token>
<id>abcabcabc</id>
</session>
So really, ALL I need is for my rails and sinatra apps to hit that url and parse whatever is returned AND grcefully handle the remote server failing to reply.
require 'open-uri'
require 'nokogiri'
response = open("http://kickstartme.someplace.com?action=ACTIONNAME&token=XYZXYZXYZ").read
doc = Nokogiri::XML(response)
Use curb, a Ruby binding to libcurl. You will get all the curl features without having to shell out with system.
curl -b "auth=abcdef; ASP.NET_SessionId=lotsatext;" example.com
turns into
curl = Curl::Easy.new('http://example.com/')
curl.cookies = 'auth=abcdef; ASP.NET_SessionId=big-wall-of-text;'
curl.perform
More curb examples

Ruby Sinatra - connect to mongoDB on mongoHQ failed

This is just for my weekend project/study, I am very new to Sinatra and MongoDB.
I've installed the gems for mongoDB, such as: mongo, mongo_mapper and mongoid.
When I tried connecting to my database on MongoHQ from localhost, it encountered such an error:
Mongo::ConnectionFailure at /
failed to connect to any given host:port
* file: connection.rb
* location: connect
* line: 489
I found a similar thread on SO, but frankly speaking, I don't quite understand the answers...
Here is my code snippet:
require 'rubygems'
require 'sinatra'
require 'mongo'
require 'mongo_mapper'
get '/' do
MongoMapper.connection = Mongo::Connection.new('flame.mongohq.com', 27044)
MongoMapper.database = 'notes'
MongoMapper.database.authenticate('foo', 'bar')
erb :list
end
I took the above code from here, but it seems not working...
Which part is wrong? Is there another way to do this? In the end this test web app will be deployed onto heroku, so I hope the solution can work with both localhost and my heroku server.
Updated:
I just created a minimal code snippet to test the mongodb connection:
require 'rubygems'
require 'mongo'
db = Mongo::Connection.new("flame.mongohq.com", 27044).db("notes")
But still got the error, after timeout:
$ ruby mongodbtest.rb
/Library/Ruby/Gems/1.8/gems/mongo-1.0.8/lib/../lib/mongo/connection.rb:489:in
`connect': failed to connect to any given host:port (Mongo::ConnectionFailure)
from /Library/Ruby/Gems/1.8/gems/mongo-1.0.8/lib/../lib/mongo/connection.rb:137:in
`initialize'
from mongodbtest.rb:4:in `new'
from mongodbtest.rb:4
The hostname and port are according to mongoHQ documentation, so they must be right.
Thanks for the help in advance.
2nd Update:
I just tested the mongodb connection string using terminal:
mongo mongodb://flame.mongohq.com:27044/notes -u foo -p bar
Unfortunately this would get me an connection failed error, honestly, I don't know why...
I use
uri = URI.parse(ENV['MONGOHQ_URL'])
#mongo_connection = Mongo::Connection.from_uri( uri )
#mongo_db = #mongo_connection.db(uri.path.gsub(/^\//, ''))
#mongo_db.authenticate(uri.user, uri.password)
You can look up your mongo url using the heroku config --long command
Just gave this another try, this time, I was using the ip address taken from ping:
So, if I change :
db = Mongo::Connection.new('flame.mongohq.com', 27060).db("notes")
db.authenticate('fake', 'info')
To:
db = Mongo::Connection.new('184.73.224.5', 27060).db("notes")
db.authenticate('fake', 'info')
That will work...
I still don't understand why the domain name approach won't work, but at least I can finish this off :)

Resources