Is it even possible to use Cognito's in build SMS_MFA with CUSTOM_AUTH flow.? - amazon-cognito

I tried to use SMS_MFA challenge with custom auth flow but it always results in error.
Trying to do something like -
import json
event['response']['failAuthentication'] = False
event['response']['issueTokens'] = False
event['response']['challengeName'] = "SMS_MFA"
return event ```

Related

Override/change name of fields in JSON response in API Platform

I am working on an API Platform 3 (Symfony 6) app.
In my JSON response, I have the following :
{
...
"totalItems": 7065,
"itemsPerPage": 10,
...
}
Is it possible to change the config so that I get :
{
...
"total_items": 7065,
"page_size": 10,
...
}
So basically I want to rename these fields, in the response I get. Is it possible ?
If your question is about parameter names for pagination only, so then you can just execute bin/console debug:config api_platform and you will see available config parameters (documentation) under api_platform.collection.pagination:
collection:
pagination:
page_parameter_name: page
items_per_page_parameter_name: perPage
enabled: true
partial: false
client_enabled: false
client_items_per_page: false
client_partial: false
items_per_page: 30
maximum_items_per_page: null
enabled_parameter_name: pagination
partial_parameter_name: partial
Hope you will find what you want. Anyway, you can always to find the place where this piece is serialized and try to decorate/override it.
Otherwise, if you want to change the name of some another parameter from api resource you can use SerializedName() attribute on this property
The custom normalizer is the solution to this question.
A custom event listener is also a solution but it is not GraphQL friendly.

How to call api in powerbi to get data?

I am a bit beginner of powerbi, I want to call api from power bi to get some data.
I tried to write this code but always return this error once I clicked invoke button
Here is the code that I used:
let
GetWorkItemIds = () =>
let
Source = Json.Document(Web.Contents("https://dev.azure.com/XXX/XXX/_apis/wit/workitems/13?api-version=7.0")),
workItems = Source[workItems],
#"Converted to Table" = Table.FromList(workItems, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expand Ids" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id"}, {"Work Item Id"})
in
#"Expand Ids"
in
GetWorkItemIds
Anyone can give idea please. Thanks a lot
2nd try:
() =>
let body = [username = "", password = "xxxxxx"],
Data = Json.Document(Web.Contents("https://dev.azure.com/X/X/_apis/wit/workitems/13")),
result = Record.Field(Data[result] {
0
}, "token")
in
result
this is my second try, it also return the same error as the picture above.
Your JSON isn't correct. Try this and see what comes back in the preview window.
let
Source = Web.Contents("https://dev.azure.com/XXX/XXX/_apis/wit/workitems/13?api-version=7.0")
in
Source
Based on the documentation on the API endpoint response, it looks to me like you are treating the response erroneously. The endpoint does not return a list of work items, but a JSON representing one singular work item based on its ID - in your case ID = 13.
As you can see in the linked documentation, the response does not contain anything called workItems, which I suspect is causing your error.
However, I think your error stems from lack of authentication.

await in a python for loop never finishing

I'm trying a new thing for me, using playwright in google colab.
this combination requires/forces async programming.
I've got a context manager which is able to handle the login and logout called "Login". That works great!
The internal page I'm trying to get to has datasets, with no links, just div's to click on.
the locator (I believe) is working fine and should return multiple elements when combined with .element_handles() I'm assuming.
from playwright.async_api import async_playwright
import asyncio
from IPython.display import Image
import nest_asyncio
nest_asyncio.apply()
# browser is set to webkit in the Login() context manager
...
async def loop_over_datasets(browser=None, page=None):
print("starting")
datasets = page.locator("div.horizontal.clickable")
print("continuing")
datasets = await asyncio.gather(datasets.element_handles())
for ds in datasets:
print(f'inside the loop, ds is {ds}')
print("doesn't get here in tact")
# for each dataset I want to launch a new page where the dataset is clicked but I'll settle for sync programming at this point.
# new_page = await ds.click()
# ds_page = await browser.new_page(new_page)
# ds_page.click()
async def get_all_new_info():
async with Login() as (b,l):
await loop_over_datasets(browser=b,page = l)
asyncio.run(get_all_new_info()) #has to be killed manually or it will run forever.
In the line datasets = await asyncio.gather(datasets.element_handles()) gather() doesn't actually work without await and await never returns
which means I don't get "inside the loop...".
without await I get the "ds" variable but it's not anything I can do something with.
How is this supposed to be used?
Without full code it's a little bit hard to test but wanted to share few things that may help:
datasets = await asyncio.gather(datasets.element_handles())
As far as I can see in Playwright documentation element_handles() returns <List[ElementHandle]> and your are trying to pass this list to asyncio.gather which needs awaitable objects which are coroutines, Tasks, and Futures and probably thats why it's not working, so I would just done
datasets = datasets.element_handles()
Now, I assume you'd like to go through those datasets in an asynchronous manner. You should be able to put the content of the for loop into a coroutine and based on that create tasks that will be executed by gather.
async def process_dataset(ds):
new_page = await ds.click()
ds_page = await browser.new_page(new_page)
ds_page.click()
tasks = []
for ds in datasets:
tasks.append(asyncio.create_task(process_dataset(ds)))
await asyncio.gather(*tasks)

Requesting a BigQuery API from Google Spreadsheet generates an Error

I am trying to fetch data from Bigquery and show them into my spreadsheet using the App script. First, I created a Spreadsheet file in my G-drive and then put my code into the script editor.
Here is the code I have used to get all the datasets from Bigquery:
function getAllDataSets(filter){
try{
let req_for_datasets = BigQuery.Datasets.list(PROJECT_ID);
let datasets = req_for_datasets.datasets;
let list = [];
datasets.forEach( obj => {
if(obj.datasetReference.datasetId.indexOf(filter)>-1)
list.push(obj.datasetReference.datasetId);
});
return list;
}catch(e){
return [];
}
}
this script works fine and I can see the result while running my script through Code Editor. I try to use this script in onOpen() or onEdit() to be able to get data when the spreadsheet gets opened.
but using the spreadsheet I receive this message:
GoogleJsonResponseException: API call to bigquery.tables.list failed with error: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.
this is the code I have put in onOpen function:
function onOpen(){
let ui = SpreadsheetApp.getUi();
let method_list = ["SUM", "AVG", "COUNT"];
//Adding a Custom menu
ui.createMenu("Media Budget")
.addItem("Facebook", "makeQuery")
.addSeparator()
.addItem("Google Ads", "makeQuery")
.addToUi();
//Getting all datasets from the specified project
let dataset_list = getAllDataSets("dw_sandbox_");
Browser.msgBox(dataset_list);
//Creating dropdown list cell
let cell = SHEET.getRange("B1");
applyValidationToCell(dataset_list, cell);
}
other than that if I try to execute the function using the custom menu in the spreadsheet everything works fine as well.
It would be really appreciated if you can help me.
If you can perform a request when running code manualy, but not on simple onOpen or onEdit trigger - the reason is authorization issues
See restrictions:
Because simple triggers fire automatically, without asking the user
for authorization, they are subject to several restrictions:
...
They cannot access services that require authorization. For example, a
simple trigger cannot send an email because the Gmail service requires
authorization, but a simple trigger can translate a phrase with the
Language service, which is anonymous.
Workaround
Option a)
Rather than running the request onOpen, implement it into a separate function that will be called when chosen from custom menu
Sample:
function onOpen(){
let ui = SpreadsheetApp.getUi();
let method_list = ["SUM", "AVG", "COUNT"];
//Adding a Custom menu
ui.createMenu("Media Budget")
.addItem("Facebook", "makeQuery")
.addSeparator()
.addItem("Google Ads", "makeQuery")
.addSeparator()
.addItem("bigQuery", "makeBigQuery")
.addToUi();
}
function makeBigQuery(){
//Getting all datasets from the specified project
let dataset_list = getAllDataSets("dw_sandbox_");
Browser.msgBox(dataset_list);
//Creating dropdown list cell
let cell = SHEET.getRange("B1");
applyValidationToCell(dataset_list, cell);
}
Option b)
Run your exisitng code on installable instead on simple trigger.
Installable triggers can run funcitons that reuire auhtorization
To convert your simple trigger into an installable
rename the function from onOpen (otherisw you might run into conflicts from having both simple and installable triggers run simultaneously)
Go on Edit -> Current project's triggers - > New trigger - see also here

I am having trouble with web2py routes.example.py

Hi I would like to ask a question about routes.example.py
My app is called "HelloWorld"
If I use following URL
http://127.0.0.1:8000/helloWorld/default/index
The user is guided to the main page.
I am trying to figure out handling errors.
For example If I have a following URL
http://127.0.0.1:8000/helloWorld/default/index11
I have to handle the error.
Based on my research, I know that I need to work on "routes.example.py"
The following is my work in routes.example.py
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
from fileutils import abspath
from languages import read_possible_languages
possible_languages = read_possible_languages(abspath('applications', app))
routers = {
app: dict(
default_language = possible_languages['default'][0],
languages = [lang for lang in possible_languages
if lang != 'default']
)
}
*** above part is given by the web2py***
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
default_application = "HelloWorld"
default_controller = "default"
default_function = "index"
routes_onerror = [
('HelloWorld/400', '/HelloWorld/default/login'),
('HelloWorld/*', '/HelloWorld/static/fail.html'),
('*/404', '/HelloWorld/static/cantfind.html'),
('*/*', '/HelloWorld/error/index')
]
I define the default application, default controller and default fuction
Bases on these, I define the error cases in routes_onerror...
Can you tell me that what I am missing?