Replacing Rabbit when using expo-crypto in react native - expo

In our react-native app we were doing this to encrypt:
return CryptoJS.Rabbit.encrypt(hexString, hash).toString();
But now with the expo-crypto package, this is handled differently:
import * as CryptoJS from 'expo-crypto';
That being the case, what should the new syntax be for encrypting, instead of this?
return CryptoJS.Rabbit.encrypt(hexString, hash).toString();
I don't see this mentioned in the expo-crypto documentation.

Related

TypeError: Cannot read property 'AwsCredentialsProvider' of undefined

Been trying to test out the aws-iot-device-sdk-v2 library for a bit. I am currently trying to test out the sample app provided by the AWS dev team. I am trying to test out the system incrementally. This is the code I have tested so far:
import { mqtt, auth, http, io, iot } from 'aws-iot-device-sdk-v2';
const client_bootstrap = new io.ClientBootstrap();
let config_builder = iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets({
region: 'us-west-2',
credentials_provider: auth.AwsCredentialsProvider.newDefault(client_bootstrap)
});
config_builder.with_clean_session(false);
config_builder.with_endpoint('example.com');
config_builder.with_client_id(1);
const config = config_builder.build();
const client = new mqtt.MqttClient(client_bootstrap);
const connection = client.new_connection(config);
await connection.connect();
When running this on the AWS console, I am getting the following error:
TypeError: Cannot read property 'AwsCredentialsProvider' of undefined
Any idea what I'm doing wrong here?
Wasn't able to identify why I couldn't use AwsCredentialsProvider as expected but found a work-around. Instead, I was able to initialize the builder with const config_builder = iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets();. Anyway, didn't figure out why I couldn't utilize AwsCredentialsProvider as expected. Might be something to look into if the dev team has time. 👍
I also encounter the same issue when running this example in browser and found the reason :
'aws-iot-device-sdk-v2' just import these 5 classes directly form aws-crt
https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/lib/index.ts
while in aws-crt, it's implementation for browser is in a sub folder ,
https://github.com/awslabs/aws-crt-nodejs/tree/main/lib/browserm, and it don't include 'auth' .
so if you run these example in browser, you need to import form aws-crt's subfolder, and skip 'auth':
import { mqtt, http, io, iot } from 'aws-crt/dist.browser/browser';

Is Intl.Collator possible in an Expo Managed react native app?

Do Expo managed react native apps have access to an Intl Collator?
I don't see it in the docs but thought I'd ask.
Looking to use it for sorting like this 👇.
import { createNewSortInstance } from 'fast-sort';
const naturalSort = createNewSortInstance({
comparer: new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare,
});
It will be in the next SDK that includes React Native 65.0. See https://reactnative.dev/blog/2021/08/17/version-065#whats-new-in-hermes-08 and https://expo.fyi/react-native-releases

How to change the CookieSpec in Jersey Client?

I used Jersey Client in the project like this:
clientConfig.connectorProvider(new ApacheConnectorProvider());
clientConfig.register(MultiPartFeature.class);
client = ClientBuilder.newClient(clientConfig);
it actually use httpClient to do the job. but now I encountered the CookieSpec issue in this question: Fixing HttpClient warning “Invalid expires attribute” using fluent API. I need to change the CookieSpec but I cannot find where to change the config.
Maybe you can try to use the below solution:
RequestConfig requestConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD).build();
clientConfig.property(ApacheClientProperties.REQUEST_CONFIG, requestConfig);

arcpy in django doesnot run

I have a script with ArcGIS using arcpy model. And I want to combine it with Django. The script runs on console successfully, however, when running with Django, I find the arcpy functions do not run. So I make a simple test for it, and get the same result.
test.py
import arcpy
import os
def test_arcpy():
tempFolder = arcpy.env.scratchFolder
tempGDBPath = os.path.join(tempFolder, 'test.gdb')
arcpy.env.overwriteOutput = True
if not arcpy.Exists(tempGDBPath):
arcpy.AddMessage('create..')
arcpy.CreateFileGDB_management(tempFolder, 'test.gdb')
return arcpy.Exists(tempGDBPath)
views.py
from django.http import HttpResponse
from . import test
def t(request):
msg = str(test.test_arcpy())
return HttpResponse(msg)
If I run the test.py in console, it return True.But if I run it in django, it always return false. If I cannot solve it , I cannot make more difficult script in django. Can you help me?
I found the similar question in Flask app with ArcGIS, Arcpy does not run, but no solution in this question.
I think I can use the subprocess model to run the arcpy script in console, and then return the console message back to the django function.
But I really want to know whether arcpy can run with django or not.
i meet the same problem the same as you in Flask.
I check the source code in arcpy, found there is an bug in arcgisscripting.pyd file while i trigger arcpy.Exists() from Flask. And i lost any clew. After searching for some case on ESRI online blog, i certainly found that it's a bug in arcpy. So i advice u:
try higher version arcpy.(my current version is 10.1)
try to run your code in a console
try to run message queue like from multiprocessing import Queue, Process
try to not use the function. In my case, I avoid to use arcpy.Exists()
try to use 64-bit arcpy in arcServer.

No headers in HAR response

I parse website 'http://ok.ru'. To get data from the post request I need to send a specific token that is generated by Javascript on the website and this token is contained in headers.
So I thought maybe one solution would be to open the website, let it generate token, grab headers and that's it.
One tool that can implement Java scripts is Selenium, however, to get headers I need to use brosermob-proxy (or equivalent). That is where I'm stuck.
There's no headers in response and I can't figure it out. Maybe someone who worked with browsermob can see what's wrong? I would also be glad to hear another solutions to my task. The code itself is below:
from browsermobproxy import Server
from selenium import webdriver
from ast import literal_eval
import json, os
os.chdir('C:/browsermob-proxy-2.1.0-beta-2/bin')
server = Server()
server.start()
proxy = server.create_proxy()
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
proxy.new_har('test')
driver.get('http://ok.ru')
driver.find_element_by_xpath('//input[#name="st.email"]').send_keys('****#****.com')
driver.find_element_by_xpath('//input[#name="st.password"]').send_keys('****')
driver.find_element_by_xpath(u'//input[contains(#value,"Log in")]').click()
result = literal_eval(json.dumps(proxy.har, ensure_ascii=False))
driver.close()
for entry in result['log']['entries']:
if len(entry['response']['headers']) > 0:
print entry['response']['headers']
The answer turned to be easy: just to add options to new_har:
proxy.new_har('test', options={'captureHeaders': True})
However, there is no token in headers, which is a new puzzle to me...