kubeclient create_namespace NoMethodError - ruby

I have a program in ruby which creates deployments, services and ing in a specific namespace. When I want to create a namespace, it complains for NoMethodError.
This is the code:
namespace = Kubeclient::Resource.new
namespace.metadata = {}
namespace.metadata.name = ns
#kube_client.create_daemon_set namespace
And this is the exception:
Exception occurred undefined method `create_namespace' for #<Kubeclient::Client:0x0000000267b810>
All other functions including creating deployment and service works fine.

This is a snippet from a test:
namespace = Kubeclient::Resource.new
namespace.metadata = {}
namespace.metadata.name = 'development'
client = Kubeclient::Client.new('http://localhost:8080/api/')
created_namespace = client.create_namespace(namespace)
assert_instance_of(Kubeclient::Resource, created_namespace)
assert_equal(namespace.metadata.name, created_namespace.metadata.name)
You forgot parenthesis.

Related

How to update config based on envronment for middleman s3_sync?

I'm trying to push slate docs to 2 different S3 buckets based on the environment.
But it's complaining that s3_sync is not a parameter for middleman.
I have mentioned the S3 bucket in the environment using config.rb but still I'm getting the above issue when I run bundle exec middleman s3_sync --verbose --environment=internal
config.rb:
configure :internal do
s3_sync.bucket = ENV['INTERNAL_DOCS_AWS_BUCKET'] # The name of the internal docs S3 bucket you are targeting. This is globally unique.
end
activate :s3_sync do |s3_sync|
s3_sync.bucket = ENV['DOCS_AWS_BUCKET'] # The name of the S3 bucket you are targeting. This is globally unique.
s3_sync.region = ENV['DOCS_AWS_REGION'] # The AWS region for your bucket.
s3_sync.aws_access_key_id = ENV['DOCS_AWS_ACCESS_KEY_ID']
s3_sync.aws_secret_access_key = ENV['DOCS_AWS_SECRET_ACCESS_KEY']
s3_sync.prefer_gzip = true
s3_sync.path_style = true
s3_sync.reduced_redundancy_storage = false
s3_sync.acl = 'public-read'
s3_sync.encryption = false
s3_sync.prefix = ''
s3_sync.version_bucket = false
s3_sync.index_document = 'index.html'
s3_sync.error_document = '404.html'
end
Error:
bundler: failed to load command: middleman
(/usr/local/bundle/bin/middleman) NameError: undefined local variable
or method `s3_sync' for #Middleman::ConfigContext:0x0000561eca099a40
s3_sync is only defined within the block of activate :s3_sync.
It is undefined within the configure :internal block.
A solution might look like the following, using environment? or environment
activate :s3_sync do |s3_sync|
s3_sync.bucket = if environment?(:internal)
ENV['INTERNAL_DOCS_AWS_BUCKET']
else
ENV['DOCS_AWS_BUCKET']
end
s3_sync.region = ENV['DOCS_AWS_REGION']
# ...
end

Cannot set existing payment profile to be the default for a customer

I am using the updateCustomerPaymentProfile endpoint to try to update a payment profile. This works well, except for the presence of one field: defaultPaymentProfile.
There are two different issues.
1. Authorize.Net Ruby SDK typing issue
The docs say defaultPaymentProfile is an expected field, but the type does not allow it in ruby SDK, see in the official source code:
https://github.com/AuthorizeNet/sdk-ruby/blob/002019e03a94ef582aa82983edf6a7a1a22b2316/lib/authorize...
I opened a Github issue about this.
I then monkey patched the type as following:
module AuthorizeNet::API
class CustomerPaymentProfileExType
xml_accessor :defaultPaymentProfile
end
end
After that, it accepts to send the request but I receive an error response as following:
AuthorizeNetException: E00003: The element 'paymentProfile' in namespace
'AnetApi/xml/v1/schema/AnetApiSchema.xsd' has invalid child element
'defaultPaymentProfile' in namespace 'AnetApi/xml/v1/schema/AnetApiSchema.xsd
Which is the second issue...
2. Authorize.Net API not accepting the defaultPaymentProfile when updating a payment profile
For the record, I dumped the raw XML that is sent to the API once I patched the SDK to be able to actually reach the API:
<updateCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>REDACTED</name>
<transactionKey>REDACTED</transactionKey>
</merchantAuthentication>
<customerProfileId>REDACTED</customerProfileId>
<paymentProfile>
<customerType>individual</customerType>
<billTo>
<firstName>REDACTED</firstName>
<lastName>REDACTED</lastName>
<address>REDACTED</address>
<city>REDACTED</city>
<state>REDACTED</state>
<zip>REDACTED</zip>
<country>REDACTED</country>
<phoneNumber>REDACTED</phoneNumber>
</billTo>
<payment>
<creditCard>
<cardNumber>XXXX4242</cardNumber>
<expirationDate>2022-03</expirationDate>
</creditCard>
</payment>
<customerPaymentProfileId>REDACTED</customerPaymentProfileId>
<!-- This XML passes fine without the line below -->
<defaultPaymentProfile>true</defaultPaymentProfile>
</paymentProfile>
<validationMode>liveMode</validationMode>
</updateCustomerPaymentProfileRequest>
This looks exactly the same as the request suggested by the official API docs, yet, the server respond with a E00003 error that I already shared above.
Notes
As a reference, the block of ruby code that I am using:
profile = AuthorizeNet::API::CustomerPaymentProfileExType.new
profile.customerPaymentProfileId = current_profile.customerPaymentProfileId
profile.billTo = billTo
profile.payment = AuthorizeNet::API::PaymentType.new(
AuthorizeNet::API::CreditCardType.new(
cc_data.cardNumber, cc_data.expirationDate
)
)
profile.taxId = user.tax_id if user.tax_id
profile.defaultPaymentProfile = true
profile.customerType = 'individual'
request = AuthorizeNet::API::UpdateCustomerPaymentProfileRequest.new
request.paymentProfile = profile
request.customerProfileId = customer_profile_id
request.validationMode = AuthorizeNet::API::ValidationModeEnum::LiveMode
response = transaction.update_customer_payment_profile(request)
What am I doing wrong?
The order of the elements matter. Move
<defaultPaymentProfile>true</defaultPaymentProfile>`
above
<customerPaymentProfileId>REDACTED</customerPaymentProfileId>`
<updateCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>REDACTED</name>
<transactionKey>REDACTED</transactionKey>
</merchantAuthentication>
<customerProfileId>REDACTED</customerProfileId>
<paymentProfile>
<customerType>individual</customerType>
<billTo>
<firstName>REDACTED</firstName>
<lastName>REDACTED</lastName>
<address>REDACTED</address>
<city>REDACTED</city>
<state>REDACTED</state>
<zip>REDACTED</zip>
<country>REDACTED</country>
<phoneNumber>REDACTED</phoneNumber>
</billTo>
<payment>
<creditCard>
<cardNumber>XXXX4242</cardNumber>
<expirationDate>2022-03</expirationDate>
</creditCard>
</payment>
<defaultPaymentProfile>true</defaultPaymentProfile>
<customerPaymentProfileId>REDACTED</customerPaymentProfileId>
</paymentProfile>
<validationMode>liveMode</validationMode>
</updateCustomerPaymentProfileRequest>
Thanks to #John Conde, I could fix the issue. The request payload is refused because the properties are not in the right order. 🤷
If you want to set an existing payment profile as the default one using the ruby SDK, you can do so by defining yourself the correct type, as following:
module AuthorizeNet::API
class CustomerPaymentProfileExTypePatched
include ROXML
xml_accessor :customerType
xml_accessor :billTo, as: AuthorizeNet::API::CustomerAddressType
xml_accessor :payment, as: AuthorizeNet::API::PaymentType
xml_accessor :driversLicense, as: AuthorizeNet::API::DriversLicenseType
xml_accessor :taxId
xml_accessor :defaultPaymentProfile
xml_accessor :subsequentAuthInformation
xml_accessor :customerPaymentProfileId
def initialize(customerType = nil, billTo = nil, payment = nil, driversLicense = nil, taxId = nil, defaultPaymentProfile = nil, subsequentAuthInformation = nil, customerPaymentProfileId = nil)
#customerType = customerType
#billTo = billTo
#payment = payment
#driversLicense = driversLicense
#taxId = taxId
#defaultPaymentProfile = defaultPaymentProfile
#subsequentAuthInformation = subsequentAuthInformation
#customerPaymentProfileId = customerPaymentProfileId
end
end
end
Then you can just use this type in your code:
profile = AuthorizeNet::API::CustomerPaymentProfileExTypePatched.new

Unable to pass environment variables to Create_Function AWS SDK method in Ruby

I'm trying to execute the following Ruby code and it constantly fails with "unexpected value at params[:environment]" error. I tried many different options for passing Hash to 'environment' parameter but it triggers the same error.
require 'aws-sdk'
client = Aws::Lambda::Client.new(region: 'us-east-1')
args = {}
args[:role] = "some_role"
args[:function_name] = "function"
args[:handler] = "function_handler"
args[:runtime] = "java8"
code = {}
code[:zip_file] = ::File.open("file.jar", "rb").read
args[:code] = code
environment = {}
environment[:variables] = { "AAA": "BBB" }
args[:environment] = environment
client.create_function(args)
Fixed by upgrading Ruby AWS SDK from 2.6 to 2.9

Puppet: How to require an additional resource in a custom type

I am writing a custom type for Puppet and use the following code to copy a module file specified by a puppet url to the user's home directory:
def generate
if self[:source]
uri = URI.parse(self[:source])
path = File.join(Etc.getpwnam(self[:user])[:dir], File.basename(uri.path))
file_opts = {}
file_opts[:name] = File.join(Etc.getpwnam(self[:user])[:dir], File.basename(uri.path))
file_opts[:ensure] = self[:ensure] == :absent ? :absent : :file
file_opts[:source] = self[:source]
file_opts[:owner] = self[:user]
self[:source] = path
Puppet::Type.type(:file).new(file_opts)
end
end
Things are working fine so far. The resource is added to the catalog and created on the agent side. But I have a problem...
How can I specify that this additional file resource must be created before the actual type gets executed? Unfortunatley, I cannot find an example which shows how to specify a dependency on an optional resource that is defined in a generate method.

fail to use invokeExact of MethodHandle on dynamic load class object

I have some demo code as follwing.
Class<?> myClass = cl.loadClass("com.hp.ac.scriptengine.test." + generateClassName);
Object my_obj = myClass.newInstance();
MethodType mt;
MethodHandle mh;
MethodHandles.Lookup lookup = MethodHandles.lookup();
mt = MethodType.methodType(void.class, int.class);
mh = lookup.findVirtual(my_obj.getClass(), "ToDoit", mt);
mh.invokeExact(my_obj,1);
here '"com.hp.ac.scriptengine.test." + generateClassName' is a generated class.
I got the message as follows.
java.lang.invoke.WrongMethodTypeException: (I)V cannot be called as (Ljava/lang/Object;I)V
at com.hp.ac.scriptengine.test.compliebyCommandline.main(compliebyCommandline.java:138)
Here line 138 is mh.invokeExact(my_obj,1);'
I tried that demo code(such as ... mh.invokeExact("daddy",'d','n')...) in Java 7 API document. It works fine. Such call(mh.invokeExact("daddy",'d','n'))just invoke (CC)Ljava/lang/String other than (Ljava/lang/String;CC)Ljava/lang/String.
But why, in my code, mh.invokeExact(my_obj,1) invoke (Ljava/lang/Object;I)V other than (I)V ?
I think the problem is with int.class. Try Integeer.class or Integer.TYPE instead.

Resources