Errors using Get-AzUserAssignedIdentity on module 0.7.3 and 0.7.2 "Extended 'versions' can't be converted to a boolean" - azure-powershell

The following commands were previously working from a local PS session using module Az.ManagedServiceIdentity version 0.7.2, but broke once I updated to 0.7.3, now can't get it to work again even after downgrading the module version. I'd like to use this module from cloud shell ideally but get the same error.
*$uamiRg = (Get-AzResourceGroup -Name *identity*).ResourceGroupName
$uami = Get-AzUserAssignedIdentity -ResourceGroupName $uamiRg -Name "my-uami"*
This used to grab the ID, RG, Name, Location, TenantId, etc. needed to use the User Assigned Managed Identity for assigning Azure Blueprints. Now the 2nd command throws this error:
*Get-AzUserAssignedIdentity : Extended 'versions' can't be converted to a boolean
At line:1 char:1
+ Get-AzUserAssignedIdentity -ResourceGroupName $uamiRg -Verbose -Error ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzUserAssignedIdentity], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ManagedServiceIdentity.UserAssignedIdentities.GetAzureRmUserAssignedIdentityCmdlet*
Debug results:
DEBUG: 5:51:44 AM - GetAzureRmUserAssignedIdentityCmdlet begin processing with ParameterSet 'ResourceGroupParameterSet'.
DEBUG: 5:51:44 AM - using account id ''...
DEBUG: [Common.Authentication]: Authenticating using Account: '', environment: 'AzureCloud', tenant: '***'
DEBUG: [HttpClientOperations]: Adding Header 'Metadata'
DEBUG: Checking Cache request http://localhost:50342/oauth2/token?resource=https%3A%2F%2Fmanagement.core.windows.net%2F&api-version=2018-02-01
DEBUG: Cache Hit
DEBUG: ============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/***/resourceGroups/***Identity-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my-uami?api-version=2015-08-31-preview
Headers:
x-ms-client-request-id : f0c521dd-5e24-400c-acc5-b47e9f1e75f2
Accept-Language : en-US
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Cache-Control : no-cache
Pragma : no-cache
Strict-Transport-Security : max-age=31536000; includeSubDomains
Server : Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 11997
x-ms-request-id : 8164b0a7-a810-4cb0-b5c1-29484e924c3f
x-ms-correlation-request-id : 8164b0a7-a810-4cb0-b5c1-29484e924c3f
x-ms-routing-request-id : EASTUS:20200405T055145Z:8164b0a7-a810-4cb0-b5c1-29484e924c3f
X-Content-Type-Options : nosniff
Date : Sun, 05 Apr 2020 05:51:44 GMT
Body:
{
"error": {
"code": "BadRequest",
"message": "Extended 'versions' can't be converted to a boolean"
}
}
Get-AzUserAssignedIdentity: Extended 'versions' can't be converted to a boolean
DEBUG: AzureQoSEvent: CommandName - Get-AzUserAssignedIdentity; IsSuccess - False; Duration - 00:00:00.2875296;; Exception - Microsoft.Rest.Azure.CloudException: Extended 'versions' can't be converted to a boolean
at Microsoft.Azure.Management.ManagedServiceIdentity.UserAssignedIdentitiesOperations.GetWithHttpMessagesAsync(String resourceGroupName, String resourceName, Dictionary2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.Commands.ManagedServiceIdentity.UserAssignedIdentities.GetAzureRmUserAssignedIdentityCmdlet.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__31.b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 5:51:45 AM - GetAzureRmUserAssignedIdentityCmdlet end processing.

Not sure what caused the issue, but it is not a bug, the 0.7.3 works on my side.
It also works in cloud shell:
To fix the issue, try to update the Az module, then install the Az.ManagedServiceIdentity module.
Update-Module -Name Az -Force
Install-Module -Name Az.ManagedServiceIdentity -RequiredVersion 0.7.3

Related

How do I implement sendgrid.env file?

I am trying to implement the sendgrid email API.
I have followed all the instructions I can find to try and set up the sendgrid email API but I all I get is this:
Response status: 401 Response Headers - HTTP/1.1 401 Unauthorized
- Server: nginx - Date: Wed, 02 Mar 2022 21:56:45 GMT
- Content-Type: application/json
- Content-Length: 88
- Connection: keep-alive
- Access-Control-Allow-Origin: https://sendgrid.api-docs.io
- Access-Control-Allow-Methods: POST
- Access-Control-Allow-Headers: Authorization, Content-Type, On-behalf-of, x-sg-elas-acl
- Access-Control-Max-Age: 600
- X-No-CORS-Reason: https://sendgrid.com/docs/Classroom/Basics/API/cors.html
- Strict-Transport-Security: max-age=600; includeSubDomains
I installed the SendGrid helper library, ran the Composer command which created a composer.json file in the root of my project, installed the SendGrid helper library for PHP, along with its dependencies in a new directory named vendor.
I then used the following to create sendgrid.env:
echo "export SENDGRID_API_KEY='SG.XXX....XXXX'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env
The API key works fine when I tested it using curl --request POST and email comes through ok.
But I have tried every combination I can think of to integrate the sendgrid.env e.g. changing the location, removing the single quotes etc. but I just get the same error message every time.
Here is my php script to send the email:
declare(strict_types=1);
require 'vendor/autoload.php';
use \SendGrid\Mail\Mail;
$email = new Mail();
// Replace the email address and name with your verified sender
$email->setFrom(
'paul#xxx.com',
'Paul xxx'
);
$email->setSubject('Sending with Twilio SendGrid is Fun');
// Replace the email address and name with your recipient
$email->addTo(
'paul#yyy.com',
'Paul yyy'
);
$email->addContent(
'text/html',
'<strong>and fast with the PHP helper library.</strong>'
);
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
$response = $sendgrid->send($email);
printf("Response status: %d\n\n", $response->statusCode());
$headers = array_filter($response->headers());
echo "Response Headers\n\n";
foreach ($headers as $header) {
echo '- ' . $header . "\n";
}
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."\n";
}
This is the structure of the files:
My domain and email have been verified on Sendgrid.
I have a feeling that there's another step involved to get the API from the sendgrid.env file?
Thanks in advance.

Move-AzDataLakeGen2Item fails with Server failed to authenticate the request

Trying to copy a file or folder within same container in ADLS Gen2.
I generated SAS key at account level, created context and could create new container, folder but can't move files or folder. Am I missing anything?
Error:
Move-AzDataLakeGen2Item : Server failed to authenticate the request. Please refer to the information in the www-authenticate header.
RequestId:f2739649-201f-0057-0f68-196d84000000
Time:2021-03-15T07:00:16.5814369Z
Status: 401 (Server failed to authenticate the request. Please refer to the information in the www-authenticate header.)
ErrorCode: NoAuthenticationInformation
Headers:
x-ms-error-code: NoAuthenticationInformation
x-ms-request-id: f2739649-201f-0057-0f68-196d84000000
x-ms-version: 2020-04-08
x-ms-client-request-id: da2ca9a0-b331-44c1-b8aa-2d8fd61bec44
Content-Length: 250
Content-Type: application/json;charset=utf-8
Date: Mon, 15 Mar 2021 07:00:16 GMT
Server: Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0
WWW-Authenticate: REDACTED
At line:1 char:1
+ Move-AzDataLakeGen2Item -Context $ctx -FileSystem "newcontainer" -Pat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Move-AzDataLakeGen2Item], RequestFailedException
+ FullyQualifiedErrorId : RequestFailedException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.MoveAzDataLakeGen2ItemCommand
PowerShell code:
$ctx = New-AzStorageContext -StorageAccountName "myadlsgen2" -SasToken "?sv=2020-02-10&ss=b&srt=sco&sp=rwdlacx&se=2021-03-16T13:27:14Z&st=2021-03-15T05:27:14Z&spr=https&sig=..."
New-AzStorageContext -StorageAccountName "myadlsgen2" -SasToken $ctx
#below works
Get-AzDatalakeGen2FileSystem -Context $ctx -Name "vccontainer"
New-AzStorageContainer -Context $ctx -Name "newcontainer"
#below fails
Move-AzDataLakeGen2Item -Context $ctx -FileSystem "newcontainer" -Path "Newfolder/" -DestFileSystem "newcontainer" -DestPath "dir/" -Verbose

Karate: How to test multipart form-data endpoint? [duplicate]

This question already has an answer here:
How to upload CSV file as a post request in Karate 0.9.0 version?
(1 answer)
Closed 2 years ago.
I have an file upload endpoint (/document) in a controller defined as follows:
#RestController
public class FileUploadController {
#Autowired
private PersonCSVReaderService personCSVReaderService;
#PostMapping(value = "/document", consumes= {MediaType.MULTIPART_FORM_DATA_VALUE})
public void handleFileUpload3(#RequestPart("file") MultipartFile file, #RequestPart("metadata") DocumentMetadata metadata) {
System.out.println(String.format("uploading file %s of %s bytes", file.getOriginalFilename(), file.getSize()));
personCSVReaderService.readPersonCSV(file, metadata);
}
}
I can test this endpoint using Advanced Rest Client (ARC) or Postman by defining the "file" part referencing the people.csv file and a text part specifying some sample metadata JSON.
Everything works fine and I get a 200 status back with the people.csv file contents being written to the console output by the service method:
uploading file people.csv of 256 bytes
{Address=1, City=2, Date of Birth=6, Name=0, Phone Number=5, State=3, Zipcode=4}
Person{name='John Brown', address='123 Main St.', city='Scottsdale', state='AZ', zipcode='85259', phoneNumber='555-1212', dateOfBirth='1965-01-01'}
Person{name='Jan Black', address='456 University Dr.', city='Atlanta', state='GA', zipcode='30306', phoneNumber='800-1111', dateOfBirth='1971-02-02'}
Person{name='Mary White', address='789 Possum Rd.', city='Nashville', state='TN', zipcode='37204', phoneNumber='888-2222', dateOfBirth='1980-03-03'}
Now, I want to run this as an automated Karate test. I have specified a MockConfig :
#Configuration
#EnableAutoConfiguration
#PropertySource("classpath:application.properties")
public class MockConfig {
// Services ...
#Bean
public PersonCSVReaderService personCSVReaderService() {
return new PersonCSVReaderService();
}
// Controllers ...
#Bean
public FileUploadController fileUploadController() {
return new FileUploadController();
}
}
I also have a MockSpringMvcServlet in the classpath and my karate-config.js is :
function fn() {
var env = karate.env; // get system property 'karate.env'
if (!env) {
env = 'dev';
}
karate.log('karate.env system property was:', env);
var config = {
env: env,
myVarName: 'someValue',
baseUrl: 'http://localhost:8080'
}
if (env == 'dev') {
var Factory = Java.type('MockSpringMvcServlet');
karate.configure('httpClientInstance', Factory.getMock());
//var result = karate.callSingle('classpath:demo/headers/common-noheaders.feature', config);
} else if (env == 'stg') {
// customize
} else if (env == 'prod') {
// customize
}
return config;
}
Other karate tests run ok using the mock servlet.
However, when I try this test to test the /document endpoint:
Feature: file upload end-point
Background:
* url baseUrl
* configure lowerCaseResponseHeaders = true
Scenario: upload file
Given path '/document'
And header Content-Type = 'multipart/form-data'
And multipart file file = { read: 'people.csv', filename: 'people.csv', contentType: 'text/csv' }
And multipart field metadata = { name: "joe", description: "stuff" }
When method post
Then status 200
I get this error:
16:14:42.674 [main] INFO com.intuit.karate - karate.env system property was: dev
16:14:42.718 [main] INFO o.s.mock.web.MockServletContext - Initializing Spring DispatcherServlet ''
16:14:42.719 [main] INFO o.s.web.servlet.DispatcherServlet - Initializing Servlet ''
16:14:43.668 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$a4c7d08f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
16:14:43.910 [main] INFO o.h.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.14.Final
16:14:44.483 [main] INFO o.s.s.c.ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor'
16:14:44.968 [main] INFO o.s.b.a.e.web.EndpointLinksResolver - Exposing 2 endpoint(s) beneath base path '/actuator'
16:14:45.006 [main] INFO o.s.web.servlet.DispatcherServlet - Completed initialization in 2287 ms
16:14:45.066 [main] INFO c.i.k.mock.servlet.MockHttpClient - making mock http client request: POST - http://localhost:8080/document
16:14:45.085 [main] DEBUG c.i.k.mock.servlet.MockHttpClient -
1 > POST http://localhost:8080/document
1 > Content-Type: multipart/form-data
16:14:45.095 [main] ERROR com.intuit.karate - http request failed: null
file-upload.feature:13 - null
HTML report: (paste into browser to view) | Karate version: 0.9.2
I can only assume that the arguments did not conform to what my endpoint was expecting - I never entered the endpoint in debug mode.
I tried this:
And multipart file file = read('people.csv')
And multipart field metadata = { name: "joe", description: "stuff" }
But that was a non-starter as well.
What am I doing wrong? The people.csv is in the same folder as fileupload.feature, so I am assuming it is finding the file. I also looked at upload.feature file in the Karate demo project given here:
Karate demo project upload.feature
But I could not make it work. Any help appreciated. Thanks in advance.
The Postman request looks like this:
EDIT UPDATE:
I could not get the suggested answer to work.
Here is the feature file:
Feature: file upload
Background:
* url baseUrl
* configure lowerCaseResponseHeaders = true
Scenario: upload file
Given path '/document'
And header Content-Type = 'multipart/form-data'
* def temp = karate.readAsString('people.csv')
* print temp
And multipart file file = { value: '#(temp)', filename: 'people.csv', contentType: 'text/csv' }
And multipart field metadata = { value: {name: 'joe', description: 'stuff'}, contentType: 'application/json' }
When method post
Then status 200
And here is the console output from running that test:
09:27:22.051 [main] INFO com.intuit.karate - found scenario at line: 7 - ^upload file$
09:27:22.156 [main] INFO com.intuit.karate - karate.env system property was: dev
09:27:22.190 [main] INFO o.s.mock.web.MockServletContext - Initializing Spring DispatcherServlet ''
09:27:22.190 [main] INFO o.s.web.servlet.DispatcherServlet - Initializing Servlet ''
09:27:23.084 [main] INFO o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$a4c7d08f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
09:27:23.327 [main] INFO o.h.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.14.Final
09:27:23.896 [main] INFO o.s.s.c.ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor'
09:27:24.381 [main] INFO o.s.b.a.e.web.EndpointLinksResolver - Exposing 2 endpoint(s) beneath base path '/actuator'
09:27:24.418 [main] INFO o.s.web.servlet.DispatcherServlet - Completed initialization in 2228 ms
09:27:24.435 [main] INFO com.intuit.karate - [print] Name,Address,City,State,Zipcode,Phone Number,Date of Birth
John Brown,123 Main St.,Scottsdale,AZ,85259,555-1212,1965-01-01
Jan Black,456 University Dr.,Atlanta,GA,30306,800-1111,1971-02-02
Mary White,789 Possum Rd.,Nashville,TN,37204,888-2222,1980-03-03
09:27:24.482 [main] INFO c.i.k.mock.servlet.MockHttpClient - making mock http client request: POST - http://localhost:8080/document
09:27:24.500 [main] DEBUG c.i.k.mock.servlet.MockHttpClient -
1 > POST http://localhost:8080/document
1 > Content-Type: multipart/form-data
09:27:24.510 [main] ERROR com.intuit.karate - http request failed: null
file-upload.feature:14 - null
HTML report: (paste into browser to view) | Karate version: 0.9.2
Note: people.csv file reads successfully and prints in console.
Refer to this part of the docs: https://github.com/intuit/karate#read-file-as-string
So make this change:
* def temp = karate.readAsString('people.csv')
And multipart file file = { value: '#(temp)', filename: 'people.csv', contentType: 'text/csv' }
EDIT: my bad, also refer: https://github.com/intuit/karate#multipart-file
Feature: upload csv
Background: And def admin = read('classpath:com/project/data/adminLogin.json')
Scenario:
Given url baseUrl
And header Authorization = admin.token
And multipart file residentDetails = { read:'classpath:com/project/data/ResidentApp_Details.csv', filename: 'ResidentApp_Details.csv' }
When method POST
Then status 200
Note: Add only one extra line i.e And multipart file residentDetails = { read:'classpath:com/project/data/ResidentApp_Details.csv', filename: 'ResidentApp_Details.csv' }

Lock Timeout when creating index in ArangoDB

I am able to connect to the coordinator of my ArangoDB cluster using the following:
sudo arangosh --server.endpoint tcp://10.32.0.15:1027
Everything works (CRUD, querying, etc.), except when I try to create an index I get a "Lock Timeout" error:
10.32.0.15:1027#_system> db.imdb_vertices.ensureIndex({ type: "skiplist", fields: ["name"] })
JavaScript exception in file '/usr/share/arangodb3/js/client/modules/#arangodb/arangosh.js' at 100,7: ArangoError 18: : lock timeout
! throw error;
! ^
stacktrace: ArangoError: : lock timeout
at Object.exports.checkRequestResult (/usr/share/arangodb3/js/client/modules/#arangodb/arangosh.js:98:21)
at ArangoCollection.ensureIndex (/usr/share/arangodb3/js/client/modules/#arangodb/arango-collection.js:738:12)
at <shell command>:1:18
10.32.0.15:1027#_system>
I get the same error when I try to create the index over HTTP:
$ curl -X POST --data-binary #- --dump - http://10.32.0.15:1027/_api/index?collection=imdb_vertices << EOF
{
"type" : "skiplist",
"fields" : [
"name",
"genre"
]
}
EOF
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Server: ArangoDB
Connection: Keep-Alive
Content-Length: 71
{"error":true,"code":400,"errorNum":18,"errorMessage":": lock timeout"}
From the docs, I see "Will be raised when there's a timeout waiting for a lock." is listed as the cause of the error. However, I am unable to find a solution. Any hints?
Thanks!

The 'Access-Control-Allow-Origin' header contains the invalid value 'null'

I have a Symfony2 application which I am trying to set up using the Nelmio CORS bundle. I am running this on an apache server (BitNami mampstack).
No matter what I do, I keep getting this error logged to my browser's console:
XMLHttpRequest cannot load http://localhost:8000/avrequests. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains the invalid value 'null'. Origin 'http://localhost:8080' is therefore not allowed access.
Sure enough my response headers read like this:
Access-Control-Allow-Origin:null
Cache-Control:no-cache
Connection:close
Content-Type:text/html; charset=UTF-8
Date:Sun, 29 Nov 2015 05:14:13 GMT
Host:localhost:8000
X-Debug-Token:3f40a5
X-Debug-Token-Link:/_profiler/3f40a5
X-Powered-By:PHP/5.5.27
This is the Nelmio configuration in my config.yml file (it's basically default values):
nelmio_cors:
defaults:
allow_credentials: false
allow_origin: []
allow_headers: []
allow_methods: []
expose_headers: []
max_age: 0
hosts: []
origin_regex: false
paths:
'^/':
allow_origin: ['*']
allow_headers: ['origin', 'content-type']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE','OPTIONS']
max_age: 3600
I have tried everything from adding this line into the httpd.conf file....
Header set Access-Control-Allow-Origin "*"
...to creating an .htaccess file. The bundle is properly included in my AppKernel.php file within Symfony. Nothing works; I cannot get anything to properly set the Access-Control-Allow-Origin header.