How to tag a block storage using softlayer api - api

I can't find any method about tag a block storage in following link:
https://sldn.softlayer.com/reference/services/SoftLayer_Network_Storage_Iscsi
Also I checked the command of tag:
https://sldn.softlayer.com/reference/services/SoftLayer_Tag
This command seems like what I want, but I still met some problems:
For the parameter tagTypes, the supported types I get are:
{'keyName': 'HARDWARE', 'description': 'Hardware'},
{'keyName': 'GUEST', 'description': 'CCI'},
{'keyName': 'ACCOUNT_DOCUMENT', 'description': 'Account Document'},
{'keyName': 'TICKET', 'description': 'Ticket'},
{'keyName': 'NETWORK_VLAN_FIREWALL', 'description': 'Vlan Firewall'},
{'keyName': 'CONTRACT', 'description': 'Contract'},
{'keyName': 'IMAGE_TEMPLATE', 'description': 'Image Template'},
{'keyName': 'APPLICATION_DELIVERY_CONTROLLER', 'description': 'Application Delivery Controller'},
{'keyName': 'NETWORK_VLAN', 'description': 'Vlan'}
Not sure which one is proper for block storage.
I tried with tagType "HARDWARE" and tired to set the tag to block storage, the response shows "You do not have permissions to tag this object"
Anyone can help to give some advice, thanks in advance.

I am affraid that is not possbiel to tag the block storages, the object Network_Storage_Iscsi should have a property called tagReference but as you can see in documentation it does not have it:
https://sldn.softlayer.com/reference/datatypes/SoftLayer_Network_Storage_Iscsi
For example other objects that can be tagged have that property e.g. Tickets or image templates see:
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Ticket
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest_Block_Device_Template_Group
Addiotionally the method: https://sldn.softlayer.com/reference/services/SoftLayer_Tag/getAllTagTypes
it should return Network_Storage as a valid type, but it does not.
Regards

Related

How to use Ethereum RPC API to swap tokens?

I am trying to code a client for swapping tokens through BSC chain (I really don't want to use web3 libraries) using Ethereum API. So learned some stuff from Ethereum RPC API documentation, but i can't really understand what are the steps for sending Raw Signed transaction. So here is my example payload:
data = {"jsonrpc": "2.0",
"method": "eth_sendTransaction",
"params": [
{
'from': address,
'to': self.router_address,
'gas': hex(gas),
'gasPrice': hex(gasPrice),
'value': hex(ETH_amount),
'data': query,
"nonce": await self.getTransactionCount(address)
}],
"id": _id}
And of course necessary header {"Content-Type": "application/json"}
The data field (query variable) basically was taken from this transaction. If you scroll down, you can see the original payload, which of course was successfully processed, because the operation was created with PancakeSwap. But when i send the same (even with modified deadline parameter) i get the this:
{'jsonrpc': '2.0', 'id': 1, 'error': {'code': -32000, 'message': 'unknown account'}}
Obvioulsy somewhere should be done signing function, but i just don't know how to make it. Can somebody help me? How do I process the data and make requests so that the swap succeeds? (From BNB to BUSD, for example - without approving step).

Google sRich Snippets. Redirect from https://schema.org to http://schema.org

I tried to add data to google rich spinner to my application. I add this code structure
return {
'#context': 'https://schema.org',
'#type': 'Product',
'sku': this.currentProduct.sku,
'category': this.productCategory,
'name': this.productName,
'description': this.productDescription,
'offers': {
'#type': 'Offer',
'price': this.bestPrice,
'priceCurrency': 'USD',
'availability': this.currentProduct.stock?.is_in_stock ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock'
},
'image': this.thumbnail
}
But if I look to result on search.google.com/test/rich-results I will see that the availability field has been assigned a https://schema.org/InStock value (not https). why is this happening? Is it important for the project?
It's not an issue. Schema.org are transitioning to use https, but for a long time it was http, and http will with for a long time to come.

How to compare 2 JSON objects that contains array using Karate tool and feature files

Files for the scenario
All the files are on same directory.
title-update-request.json
{id: 12, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
title-update-response.json
{id: 12, name: 'New Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
title-update-error-request.json
{id: 00, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
title-update-error-response.json
{Error: 'not found', Message: 'The provided Book is not found.'}
book-record.feature
Feature: CRUD operation on the book records.
Background:
* def signIn = call read('classpath:login.feature')
* def accessToken = signIn.accessToken
* url baseUrl
Scenario: Change title of book in the single book-record.
* json ExpResObject = read('classpath:/book-records/title-update-response.json')
* json ReqObject = read('classpath:/book-records/title-update-request.json')
* call read('classpath:/book-records/update.feature') { Token: #(accessToken), ReqObj: #(ReqObject), ResObj: #(ExpResObject), StatusCode: 200 }
Scenario: Change title of book in the non-existing book-record.
* json ExpResObject = read('classpath:/book-records/title-update-error-request.json')
* json ReqObject = read('classpath:/book-records/title-update-error-response.json')
* call read('classpath:/book-records/update.feature') { Token: #(accessToken), ReqObj: #(ReqObject), ResObj: #(ExpResObject), StatusCode: 400 }
update.feature
Feature: Update the book record.
Scenario: Update single book-record.
Given path '/book-record'
And header Authorization = 'Bearer ' + __arg.Token
And header Content-Type = 'application/json'
And request __arg.ReqObj
When method put
Then status __arg.StatusCode
And response == __arg.ExpectedResponse
Actual API response for scenario: 1 is :
{name: 'New Hello', config:[{username: 'abc', password: 'xyz'},{username: 'qwe', password: 'tyu'}]}
Actual API response for scenario: 2 is :
{Error: 'not found', Message: 'The provided Book is not found.'}
Question: How should I validate the response in update.feature file since problem is if I make change s as using #^^config that will not works for scenario :2 and response == _arg.ExpectedResponse is not working for Scenario: 1?
This is classic over-engineering of tests. If someone has told you that "re-use" is needed for tests, please don't listen to that person.
You have two scenarios, one happy path and one negative path. I am providing how you should write the negative path here below, the rest is up to you.
Scenario: Change title of book in the non-existing book-record.
Given path 'book-record'
And header Authorization = 'Bearer ' + accessToken
And request {id: 00, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
When method put
Then status 400
And response == {Error: 'not found', Message: 'The provided Book is not found.'}
See how clean it is ? There is no need for "extreme" re-use in tests. If you still insist that you want a super-generic re-usable feature file that will handle ALL your edge cases, you are just causing trouble for yourself. See how un-readable your existing tests have become !!
EDIT: Since I refer the question to others often as an example of how NOT to write tests, I wanted to make my point more clear and add a couple of links for reference.
Sometimes it is okay to "repeat yourself" in tests. Tests don't have to be DRY. Karate is a DSL that enables you to make HTTP calls or JSON manipulation in one or two lines. When you start attempting "re-use" like this, it actually leads to more harm than good. For example, you now need to look at multiple files to understand what your test is doing.
If you don't believe me, maybe you will believe the team at Google: https://testing.googleblog.com/2019/12/testing-on-toilet-tests-too-dry-make.html

Have I found a bug in the Sonos Self-test Suite?

Summary
The Sonos self-test suite seems to incorrectly fail for an item with itemType=other if it also has a custom browse icon.
I believe that the item type other should be included in this list from utility.py:
17 BROWSEABLE_CONTAINER_TYPES = ('artist', 'album', 'genre', 'playlist', 'favorites', 'albumList', 'trackList', 'artistTrackList', 'container', 'favorite', 'collection', 'program', 'show')
Details
When running the sonos self-test suite, I got the following error as part of the output:
...
INFO Start Test Case: 844 Albumart test_custom_browse_icon_configuration
STOP Discovered custom browse icon URI should be something other than None. (is None)
STOP 844 Albumart test_custom_browse_icon_configuration
...
By debugging albumart.py (test_custom_browse_icon_configuration method), I traced the issue to the following extract of the get_sample_custom_browse_icon_url method:
# TODO: Need to drill down one level deeper if the target image url cannot be found on the root level containers
for mediaColl in response.Items:
if mediaColl.itemType in container_types:
if substitution_str in mediaColl.albumArtURI:
return mediaColl.albumArtURI
elif hasattr(mediaColl.albumArtURI,'value') and substitution_str in mediaColl.albumArtURI.value:
return mediaColl.albumArtURI.value
This code was supposed to find containers with custom album art. However, it turns out that container_types was defined by an earlier line:
container_types = [t for t in Validation.BROWSEABLE_CONTAINER_TYPES if t.lower() != 'album']
and Validation.BROWSEABLE_CONTAINER_TYPES was defined in utility.py as follows:
# sonos-selftest/smapi/content_workflow/utility.py
15 class Validation(WorkflowTestFixture, SMAPIClient, SMAPIService):
16
17 BROWSEABLE_CONTAINER_TYPES = ('artist', 'album', 'genre', 'playlist', 'favorites', 'albumList', 'trackList', 'artistTrackList', 'container', 'favorite', 'collection', 'program', 'show')
Note that the type 'other' is missing from this list! I'm pretty sure it is supposed to be inluded in the list, browse.py mentions it:
234 **Reference:** BROWSEABLE_CONTAINER_TYPES = 'artist', 'album', 'genre', 'playlist', 'favorites', 'albumList', 'trackList', 'artistTrackList', 'container', 'favorite', 'collection', 'other', ' program'
Workaround
I was able to work around this issue by changing itemType=other to itemType=container (which are pretty much equivalent).
However, it would be nice if this was fixed in future versions of the Sonos self-test suite.

Mandrill API E-mail queue with sinatra

Trying to get form to send e-mail to Mandrill api. My email keeps getting queued and will not send.
post '/my-handling-form-page' do
m = Mandrill::API.new
message = {
:subject => "Hello from the Mandrill API",
:from_name => "#{params[:name]} #{params[:email]}",
:text => "Hi message how are you?",
:to => [
{
:email => "anonymous#gmail.com",
:name => "Recipient1"
}
],
:html => "<html>#{params[:msg]}</html>",
:from_email => "anonymous#gmail.com"
}
sending = m.messages.send message
puts sending
erb :index
end
Error says:
{"email"=>"anonymous#gmail.com", "status"=>"queued", "_id"=>"216c30f42ee849e2a70528e3d4f9774f", "reject_reason"=>nil}
Help would be appreciated.
From the Mandrill docs:
Why does a delivered message say "queued"?
Mandrill automatically tracks and records the SMTP response we receive
from recipient mail servers for each email you send. Some successfully
delivered emails will include a "queued" notation in the SMTP response
such as 250 OK; queued as 12345. The email has still been delivered to
the recipient as expected, but may require additional processing
before it lands in the recipient's mailbox. For example, most times
Mandrill can send email much faster than recipient servers are able to
accept or process it. In many cases, things like the time of day and
overall email traffic to that ISP or recipient server can affect how
quickly they're able to receive and process your email.
Your code seems fine. Looks there could be an issue with the recipient's server.
A Response Mail From Mandrill :
Thanks for reaching out. In this case, it appears that the API call being passed to Mandrill contains several invalid parameters - however, since you're also passing us an attachment array in that API call, you won't see the response indicating that it's an invalid API call.
Whenever Mandrill receives an attachment, we will always return a response of "Queued," as our systems will set that message aside to scan the attachment for viruses/malware before we process it in any other way. This means that, if something else is wrong with the API call, you won't be alerted, and it will "silently" fail.
It looks as though you've included several parameters from our default API docs, but those are intended to show users how those parameters would be included.
**"subaccount"**: "customer-123",
and
**"ip_pool"**: "Main Pool",
Will both cause this API call to fail, as you're specifying options that don't exist within your account. I would recommend that you go through your API code and remove anything that you aren't using. For reference, the minimum API call required to send an email would look like:
{
"message": {
"html": "<html content>",
"subject": "<subject>",
"from_email": "<sender email address>",
"from_name": "<sender name>",
"to": [
{
"email": "<recipient email address>",
"name": "<recipient name>",
"type": "to"
}
],
"headers": {
"Reply-To": "<reply-to address>"
}
},
"async": false,
"ip_pool": null,
"send_at": null,
"key": "<valid API key>"
}
So after this valuable response this what that work in Django for me :)
def send_mail_msg():
import mandrill
try:
mandrill_client = mandrill.Mandrill('xxxxxxxxxxxxxxx')
message = {
# 'attachments': [{'content': 'ZXhhbXBsZSBmaWxl',
# 'name': 'myfile.txt',
# 'type': 'text/plain'}],
'auto_html': None,
'auto_text': None,
# 'bcc_address': 'message.bcc_address#example.com',
'from_email': 'xxxxx#xxxx.com',
'from_name': 'Example Name',
'global_merge_vars': [{'content': 'merge1 content', 'name': 'merge1'}],
'google_analytics_campaign': 'gaurav#nexthoughts.com',
'google_analytics_domains': ['example.com'],
# 'headers': {'Reply-To': 'message.reply#example.com'},
'html': '<p>Example HTML content</p>',
'images': [{'content': 'ZXhhbXBsZSBmaWxl',
'name': 'IMAGECID',
'type': 'image/png'}],
'important': False,
'inline_css': None,
'merge': True,
'merge_language': 'mailchimp',
# 'merge_vars': [{'rcpt': 'recipient.email#example.com',
# 'vars': [{'content': 'merge2 content', 'name': 'merge2'}]}],
'metadata': {'website': 'www.example.com'},
'preserve_recipients': None,
'recipient_metadata': [{'rcpt': 'recipient.email#example.com',
'values': {'user_id': 123456}}],
'return_path_domain': None,
'signing_domain': None,
# 'subaccount': 'customer-123',
'subject': 'example subject',
'tags': ['password-resets'],
'text': 'Example text content',
'to': [{'email': 'xxxxx#xxxx.com',
'name': 'Recipient Name',
'type': 'to'}],
'track_clicks': None,
'track_opens': None,
'tracking_domain': None,
'url_strip_qs': None,
'view_content_link': None}
result = mandrill_client.messages.send(message=message, async=False, ip_pool='Main Pool')
# send_at=str(datetime.datetime.now().time()))
'''
[{'_id': 'abc123abc123abc123abc123abc123',
'email': 'recipient.email#example.com',
'reject_reason': 'hard-bounce',
'status': 'sent'}]
'''
return result
except mandrill.Error as e: # Mandrill errors are thrown as exceptions
print 'A mandrill error occurred: %s - %s' % (e.__class__, e)
# A mandrill error occurred: <class 'mandrill.UnknownSubaccountError'> - No subaccount exists with the id 'customer-123'
raise`
According to Mandrill api:
subaccount
the unique id of a subaccount for this message - must already exist or will fail with an error.
(At least for me the test start working after removing that field).
Mandrill definitely should improve their response errors.