Looking to simplify or even "dumb down" this example:
$source = #'
namespace OpenSubtitlesAPI
{
using CookComputing.XmlRpc;
[XmlRpcUrl("http://api.opensubtitles.org/xml-rpc")]
public interface IOpenSubtitles : IXmlRpcProxy
{
[XmlRpcMethod("LogIn")]
XmlRpcStruct LogIn(string username, string password, string language, string useragent);
[XmlRpcMethod("LogOut")]
XmlRpcStruct LogOut(string token);
[XmlRpcMethod("SearchSubtitles")]
XmlRpcStruct SearchSubtitles(string token, XmlRpcStruct[] queries);
[XmlRpcMethod("SearchSubtitles")]
XmlRpcStruct SearchSubtitles(string token, XmlRpcStruct[] queries, int limit);
}
public class ProxyFactory
{
public static IOpenSubtitles CreateProxy()
{
return XmlRpcProxyGen.Create<IOpenSubtitles>();
}
}
}
'#
so that the simplest possible xml-rpc query is invoked. Using .NET Core on Linux.
also trying:
desired output:
$VAR1 = {
'description' => 'Mountain Dew',
'upc' => '012000000850',
'upce' => '01208500',
'issuerCountryCode' => 'us',
'noCacheAfterUTC' => bless( do{\(my $o = '2020-11-16T17:20:29')}, 'Frontier::RPC2::DateTime::ISO8601' ),
'pendingUpdates' => '0',
'issuerCountry' => 'United States',
'ean' => '0012000000850',
'size' => '12fl oz (355mL)',
'found' => bless( do{\(my $o = '1')}, 'Frontier::RPC2::Boolean' ),
'status' => 'success',
'message' => 'Database entry found',
'lastModifiedUTC' => bless( do{\(my $o = '2014-05-27T04:52:02')}, 'Frontier::RPC2::DateTime::ISO8601' )
};
Adapting from an example script in perl:
#!/usr/bin/perl
#
# Get an RPC key assigned on the "Account Info" page on https://www.upcdatabase.com/
# Then substitute your own RPC key for $key below.
#
# Usage examples:
# perl_example_new.pl test
# perl_example_new.pl help
# perl_example_new.pl lookup upc 012000000850
# perl_example_new.pl lookup ean 0012000000850
use Frontier::Client;
use Data::Dumper;
use strict;
my $server_name = 'www.upcdatabase.com';
my $key = '445d...aa3';
my $server = Frontier::Client->new( 'url' => 'https://' . $server_name . '/xmlrpc', debug => 0, );
my $method = shift;
my $result = $server->call($method, { rpc_key => $key, #ARGV } );
print Dumper($result);
__END__
adapting to powershell using the REPL console:
PS /home/nicholas/powershell>
PS /home/nicholas/powershell> Get-Help Send-XmlRpcRequest -Examples
NAME
Send-XmlRpcRequest
SYNOPSIS
Send a XML RPC Request
-------------------------- EXAMPLE 1 --------------------------
PS > Send-XmlRpcRequest -Url "example.com" -MethodName "updateName" -Params #('oldName', 'newName')
---------
Description
Calls a method "updateName("oldName", "newName")" on the server example.com
PS /home/nicholas/powershell>
PS /home/nicholas/powershell> Send-XmlRpcRequest -Url "www.upcdatabase.com" -MethodName "012000000850" -Params #('fjkdlsfjd')
Exception: /home/nicholas/.local/share/powershell/Modules/XmlRpc/1.0.1.1/XmlRpc.psm1:323
Line |
323 | $doc.LoadXml($response)
| ~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "LoadXml" with "1" argument(s): "Root element is missing."
PS /home/nicholas/powershell>
or using a script file.
Related
I am getting the following error in the event viewer on my node during a puppet run. I suspect the issue is with incorrect lookup function in my profile.
Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Scconfig::Coserveradmin[SomeSettings]:
parameter 'parameterA' expects a String value, got Undef
parameter 'parameterB' expects a String value, got Undef
parameter 'parameterC' expects a String value, got Undef
parameter 'parameterD' expects a String value, got Undef
coserveradmin is a define resource with all string parameters. I would like to do lookup of values from a Json file
{
"SASettings" : {
"Watchdog" : {
"ParameterA" : "somevalue",
"ParameterB" : "somevalue"
},
"Serversettings" : {
"ParameterC" : "somevalue",
"ParameterD" : "somevalue",
},
"GeneralSettings" : {
"ParameterE" : "somevalue",
"ParameterF" : "somevalue",
},
"customsettings_prod" : {
"ParameterG" :"somevalue",
"ParameterH" : "%{facts.hostname}.example-cloud.com"
},
"customsettings_dev" : {
"ParameterI" :"",
"ParameterK" : "%{facts.hostname}.example.net"
}
}
}
In my hiera.yaml file I have defined the name and path to the json file.
- name: "Desired Some Settings"
path: "default/serveradmin.json"
In profile I have the following code .
class profile::scconfig_someprofile_a {
.
.
.
$hname= $::facts['hostname']
$mac= "${facts['macaddress'].delete(':')}"
$adminpropeties = lookup('SASettings')
if $hname=~someregex {
scconfig::coserveradmin{ 'SomeSettings':
property1 => $adminpropeties['customsettings_prod.ParameterG'],
property2 => $adminproperties['Watchdog.ParameterA'],
property3 => $adminproperties['Watchdog.ParameterB'],
property4 => $adminproperties['Serversettings.ParameterC'],
.
.
.
.
and so on
.
macaddress => $mac,
}
elsif $hname=~someregex {
scconfig::coserveradmin{ 'SomeSettings':
property1 => $adminpropeties['customsettings_dev.ParameterI'],
property2 => $adminproperties['Watchdog.ParameterA'],
property3 => $adminproperties['Watchdog.ParameterB'],
property4 => $adminproperties['Serversettings.ParameterC'],
.
.
.
.
and so on
.
macaddress => $mac,
}
Also adding the code for the "define" resource as requested.
define scconfig::coserveradmin(
String $Property1,
String $Property2,
String $Property3,
String $Property4,
.
.
.
String $macaddress,
) {
$dscmoduleversion = lookup('requires.modules.codsc.version')
if $dscmoduleversion != '' {
$module = {
'name' => 'codsc',
'version' => $dscmoduleversion,
}
}else{
$module = 'codsc'
}
$configname1='someconfig1'
$configname2='someconfig2'
$configname3='someconfig3'
dsc { 'someconfig1':
require => lookup('requires.cloudopssoftware'),
resource_name => 'Someresourcename',
module => $module,
properties => {
configname => $configname1,
Prop1 => $Property1,
Prop2 => $Property2,
Prop3 =>$Property3,
},
}
dsc { 'someconfig2':
require => lookup('requires.cloudopssoftware'),
resource_name => 'someresourcename2',
module => $module,
properties => {
configname => $configname2,
Prop1 => $Property4,
Prop2 => $Property5,
Prop3 =>$Property6,
},
}
dsc { 'someconfig3':
require => lookup('requires.cloudopssoftware'),
resource_name => 'someresourcename3',
module => $module,
properties => {
configname => $configname3,
Prop1 => $Property6,
Prop2 => $Property7,
Prop3 =>$Property8,
.
.
.
Propn => $macaddress
},
}
Please note that the last property which is the macaddress is evaluated within the profile class therefore I don't see any error for it.
Any ideas what could be the issue.
I suspect the issue is with incorrect lookup function in my profile.
That does not appear to be the case. If your lookup() call were not successfully looking up and returning a hash then you would get a different error when you tried to extract values.
I guess it's possible that you're retrieving the wrong hash -- which would be a matter of your hiera configuration and / or data, not the lookup() call itself -- but whether it's the right hash or the wrong one, the syntax you are trying to use to extract the data from it is not matched to the hash structure presented in the question. For example, this expression
$adminpropeties['customsettings_prod.ParameterG']
attempts to retrieve the value whose key is 'customsettings_prod.ParameterG', but the data presented contain no such key.
What you seem to want is
$adminpropeties['customsettings_prod']['ParameterG']
That extracts the value having key 'customsettings_prod', and, that value being a hash itself, extracts its value associated with key 'ParameterG'.
Alternatively, you may find the dig() function convenient for extracting data from nested data structures such as yours:
dig($adminpropeties, 'customsettings_prod', 'ParameterG')
I am very new to Puppet programming.
I have the following class which configures the resolv.conf file correctly:
class dnsclient (
$nameservers = [ 'ns1 ip',
'ns2 ip' ,
'ns3 ip' ],
$options = [ 'rotate',
'timeout:5',
'attempts:3' ],
$search = [ 'example.com',
'example2.com' ],
$domain = 'UNSET',
$sortlist = ['UNSET'],
$resolver_config_file = '/etc/resolv.conf',
$resolver_config_file_ensure = 'file',
$resolver_config_file_owner = 'root',
$resolver_config_file_group = 'root',
$resolver_config_file_mode = '0644',
) {
# Validates domain
if is_domain_name($domain) != true {
fail("Domain name, ${domain}, is invalid.")
}
# Validates $resolver_config_file_ensure
case $resolver_config_file_ensure {
'file', 'present', 'absent': {
# noop, these values are valid
}
default: {
fail("Valid values for \$resolver_config_file_ensure are \'absent\', \'file\', or \'present\'. Specified value is ${resolver_config_file_ensure}")
}
}
file { 'dnsclient_resolver_config_file':
ensure => $resolver_config_file_ensure,
content => template('dnsclient/resolv.conf.erb'),
path => $resolver_config_file,
owner => $resolver_config_file_owner,
group => $resolver_config_file_group,
mode => $resolver_config_file_mode,
}
}
I created a custom fact default_gateway which should find the client default gateway, and according to that I want to then assign different name servers.
I tried to enter the condition at the beginning of the dnsclient class:
class dnsclient
if $default_gateway == 'DG ip' {
$nameservers = [ 'ns1 ip',
'ns2 ip' ,
'ns3 ip' ],
}
But I am getting a syntax error on the client, please advise. Where do I place the if statement to assign different name servers if the default gateway is different.
I assume you need to also remove the $nameservers class parameter, so you would change the beginning of the file to:
class dnsclient (
# This parameter is no longer required?
# $nameservers = [ 'ns1 ip',
# 'ns2 ip' ,
# 'ns3 ip' ],
$options = [ 'rotate',
'timeout:5',
'attempts:3' ],
$search = [ 'example.com',
'example2.com' ],
$domain = 'UNSET',
$sortlist = ['UNSET'],
$resolver_config_file = '/etc/resolv.conf',
$resolver_config_file_ensure = 'file',
$resolver_config_file_owner = 'root',
$resolver_config_file_group = 'root',
$resolver_config_file_mode = '0644',
) {
# Your code goes here:
if $default_gateway == 'DG ip' {
$nameservers = ['ns1 ip', 'ns2 ip', 'ns3 ip'],
}
...
I would like to execute inset table entity REST API in Table Storage Service but it doesn't work.
I referred this doc.
My request code is here,
<?php
// storage account name
$account = "mystgaccount";
$tablestoragename = "mytablename";
$accessKey = "myaccesskey";
$date = gmdate('D, d M Y H:i:s T',time());
$api_version = "2015-12-11";
$url = "https://$account.table.core.windows.net/$tablestoragename";
$method = "POST";
$body = '{"Address":"MountainView","Age":23,"AmountDue":200.23,"CustomerCode#odata.type":"Edm.Guid","CustomerCode":"c9da6455-213d-42c9-9a793e9149a57833","CustomerSince#odata.type":"Edm.DateTime","CustomerSince":"2008-0710T00:00:00","IsActive":true,"NumberOfOrders#odata.type":"Edm.Int64","NumberOfOrders":"255","PartitionKey":"mypartitionkey","RowKey":"myrowkey"}';
$stringToSign = [
// VERB
$method,
// Content-MD5
'',
// Content-Type
'',
// Date
$date,
];
$stringToSign = array_merge($stringToSign, ["/$account/$tablestoragename"]);
$stringToSign = implode("\n", $stringToSign);
$signature = base64_encode(hash_hmac('sha256', $stringToSign, base64_decode($accessKey), true));
$headers = [
"x-ms-date:{$date}",
"x-ms-version:$api_version",
"Authorization:SharedKey $account:{$signature}",
"Content-Type: application/json",
];
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POSTFIELDS => http_build_query($body),
);
curl_setopt_array($ch, $proxy_options);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
var_dump($response);
echo curl_error($ch);
curl_close($ch);
?>
Response
"<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code>AuthenticationFailed</m:code><m:message xml:lang="en-US">Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:b93fe560-0002-0028-129a-571361000000
Time:2017-11-07T07:34:13.3303714Z</m:message></m:error>"
I read related questions but it hasn't resolved yet :(
Do you have any ideas?
One possible reason for this error could be because of Content-Type header. You're specifying this header in your request but is not included in your $stringToSign. Please try again by changing your $stringToSign to something like:
$stringToSign = [
// VERB
$method,
// Content-MD5
'',
// Content-Type
'application/json',
// Date
$date,
];
I am trying to create one file and one symbolic link via Puppet (with Hiera). I'm running on Ubuntu 16.04, and I am using all latest modules.
The file is called "a" and the link is called "b". These files are not related directly.
I have a init.pp file for the node:
define hiera::files (
$ensure,
$content= "",
$target="/./.",
$mode = "",
$owner = "root",
$force = "false" ) {
file { $title:
ensure => $ensure,
owner => $owner,
force => $force,
content => $content,
mode => $mode,
target => $target,
}
}
create_resources('hiera::files', hiera_hash('files', {}))
node "default" {
hiera_include('classes')
}
There is also a node.yaml file containing the corresponding data:
files:
/etc/a.txt:
ensure: "present"
mode: "2770"
owner: "simon"
content: "[d] \n type = sss \n resource = samba_1"
/etc/b:
ensure: "link"
target: "/usr/share/b"
mode: "777"
I have tried other variations, but I always get an error that I cannot specify more than one of content, source, target. Is it possible to have both? Not for the same file, but for separate files like I am trying to do?
The hiera::files defaults are the issue here, as even if you're not specifying content and target in your Hiera hash, they're being set:
define hiera::files ( $ensure, $content= "", $target="/./.", $mode = "", $owner = "root", $force = "false" ){
Change the $content and $target defaults to undef so they must be specified if you're going to use them.
define hiera::files ( $ensure, $content = undef, $target = undef, $mode = "", $owner = "root", $force = "false" ){
If you really need these default values, then you need a way to avoid setting target on a file with content, and content on a file/symlink with target, e.g.
define hiera::files ( $ensure, $content = undef, $target = undef, $mode = "", $owner = "root", $force = "false" ){
# Provide a default empty content value when ensure => present, and no content is given
$real_content = $ensure ? {
"present" => $content ? {
undef => "",
default => $content,
},
default => undef,
}
# Provide a default /./. target value when ensure => link, and no target is given
$real_target = $ensure ? {
"link" => $target ? {
undef => "/./.",
default => $target,
},
default => undef,
}
file { $title:
ensure => $ensure,
owner => $owner,
force => $force,
content => $real_content,
mode => $mode,
target => $real_target,
}
}
Or perhaps preferably, use separate defines to make the behaviour clear.
I am using following puppet class
class myclass{
$foo = [{"id" => "bar", "ip" => "1.1.1.1"}, {"id" => "baz", "ip" => "2.2.2.2"}]
map {$foo:}
define map () { notify {$name['id']: } }
}
But this gives me
err: Could not retrieve catalog from remote server: Could not intern from pson: Could not convert from pson: Could not find relationship target "Change_config::Map[ip1.1.1.1idbar]"
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run
What is the reason for this ?
Regards,
Malintha Adikari
Your array contains hashes. The resource declaration syntax works only for arrays of strings.
$foo = ["bar", "baz"]
map {$foo:}
define map () { notify {$name: } }
If you want to pass data with each resource title, you need to
build a hash of your data, not an array of hashes
use the create_resources function
Untested example code:
$foo = {
"bar" => { "ip" => "1.1.1.1" },
"baz" => { "ip" => "2.2.2.2" },
}
create_resources('map', $foo)
define map ($ip="") { notify { "$name has ip $ip": } }