How do I access my google user profile on Heroku using Ruby? - ruby

I have a Ruby program that automates simple data entry tasks for a web application with Selenium-Chromedriver. In order for the program to work, I need to create a chromedriver instance that starts out as logged in to my google account, because the web application doesn't let you log in if it doesn't recognize that the browser is being used by someone familiar. To meet these criteria, I set up the driver like this:
args = ['user-data-dir=C:\Users\user\AppData\Local\Google\Chrome\User Data']
options = Selenium::WebDriver::Chrome::Options.new(args: args)
driver = Selenium::WebDriver.for(:chrome, options: options)
$browser = Watir::Browser.start("https://nycseminarcenter.tripleseat.com/calendar", driver)
I want to add this program to a collection of other programs I have on Heroku that are scheduled to automatically run every so often, and I installed the buildpacks that should let me use Selenium from Heroku (https://github.com/heroku/heroku-buildpack-google-chrome and https://github.com/heroku/heroku-buildpack-chromedriver), but when I try to run the program as is, I end up with the following error
/app/vendor/bundle/ruby/2.5.0/gems/selenium-webdriver-3.142.0/lib/selenium/webdriver/remote/response.rb:72:in `assert_ok': unknown error: DevToolsActivePort file doesn't exist (Selenium::WebDriver::Error::UnknownError)
(Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 4.4.0-1038-aws x86_64)
coming from the line where I create the Webdriver object. I'm guessing that the "DevToolsActivePort file doesn't exist" because Heroku doesn't have a copy of my user data directory like my local ruby environment does. Is there some special way to access a google user profile directly on Heroku?

Related

Access to Express.js and Prisma console

So im building app based on Express and using Prisma ORM. What i need is to SSH to a server, open up express.js console and create new db entry using prisma. Something similar to python manage.py shell for Django or rails console for Rails. Is there a solution for this of any kind?
Like I pointed in the comment there is a way ( kind of ) to get access to a running express instance. If that's all you need follow:
How can I open a console to interact with Express app?
Express doesn't exactly have a feature like rails console which is a framework feature in that case.
That said, I question the long term implication of this approach. If you really just need to seed some data, write an "init" script, and call it after you ssh into a server or using some CI/CD approach. This is more re-usable, since you can even pass a json file to the script to load dynamic data.
Also, Prismajs has an official way to seed the data ( if that's what you need) that you can leverage:
https://www.prisma.io/docs/guides/database/seed-database
UPDATE:
If you are able to run to code on your machine and point the remote database, then you can use node --inspect to debug in a chrome console. Which should give you about the same effect as a rails REPL
https://medium.com/#tbernardes/debugging-nodejs-with-chrome-inspector-devtools-1cd2ef323b5e

How to enable networking before User Data scripts are run in AWS Windows instances

I have been struggling with bootstrapping my Windows instances in AWS. I need to download some things from S3 and other places when the instance starts up and execute them.
This seems to be really straightforward for Linux instances, but not so much for Windows instances.
I have a user data script that works when I run it after logging into the instance, but it doesn't work when it runs as part of the EC2Launch/EC2Config described here: https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html
I've found that the reason it doesn't work is that I am unable to download things from the internet due to: "The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist."
Really what I'm trying to do is the following:
Download AWS_CLI Installer
Right now I'm using bitsadmin to try to download the installer from https://s3.amazonaws.com/aws-cli/AWSCLI64.msi
Install AWS_CLI
I am able to install the CLI with the CLI installer using msiexec and the /qn flags once it's on the box
Pull items from S3
This should be able to be done with aws s3 cp or sync
Install Python (installer stored in S3)
I am able to install the installer with msiexec once it's on the box similar to the CLI installer
Execute (python) scripts pulled from S3
Does anyone know of a better way to do this? This all works after I RDP in, but not as part of the Launch Script.
TL;DR - I need to download things using the EC2Launch User Data script provided to my EC2 Windows instances but the network doesn't seem to be available when it runs.
Thanks in advance for your help!
I Ran into a similar issue, I was using BITS to download an installer on a "user data" script and was getting the same error: "The operation being requested was not performed because the user has not logged on to the network. The specified service does not exist."
This not due to network issues, but rather to how BITS works, the user starting the download job must be logged on the machine, which it seems not to be the case for "user data" execution, which "runs as" the local Administrator without the user being logged in a way that BITS recognizes. From BITS documentation:
For BITS to detect that a user is logged on, the user must use one of the following interactive logon options:
Log on through the Welcome screen.
Log on to a terminal client.
Use fast user switching.
Starting with Windows 10, version, log on from another device using Remote Powershell.
During the script execution the network is mounted and ready to use, you can download your files using other methods that do not rely on BITS(e.g.: Invoke-WebRequest (rather slow for bigger files) or using System.Net.WebClient, both on PowerShell).

How to list all Websphere installed applications for a given Middleware server using jython

I have a Websphere 8.5.5.12 installation with multiple applications running on it. For a given Middleware Server, I'd like to be able to list all applications associated with it using Jython.
I have gone as far as writing this code:
wsadmin>print AdminApp.list("WebSphere:cell=myCell,node=myNode")
However this is retrieving applications for a different Dynamic Cluster
If I add a specific server, it errors out
wsadmin>print AdminApp.list("WebSphere:cell=myCell,server=myServer")
ADMA0184E: myServer is not a valid target.
Your query should look like:
wsadmin>AdminApp.list("WebSphere:cell=myCell,node=myNode,server=server1")
It appears you're missing the node identifier in your query. And if wsadmin still returns "myServer is not a valid target", then the server name is wrong, try looking at your app server profile directory structure to double check it.

How to run/debug dashing dashboards on a client PC with Eclipse

I am trying to create a dashboard for work via dashing. I have an openSUSE server set up (command-line only, no X server), and dashing running on it successfully. I want to be able to use my work Windows 7 PC to configure the ruby-based jobs scripts, etc. I have Eclipse set up with Ruby, installed Ruby on Windows and have the debugger configured in eclipse. Git is also set up on the server, for the dashing folder. I have two questions about my methods:
Question 1:
Now, I can configure breakpoints in the ruby jobs and debug my variables, etc., but the debugger throws an error when it reaches the SCHEDULER part (see code pasted below) stating that it is an "uninitialised constant". I'm guessing Eclipse doesn't understand how to run/debug the specific dashing code; apparently dashing uses rufus-scheduler. How can I get Eclipse to run and/or debug my dashing dashboards?
Example of a ruby job in dashing, with rufus-scheduler, from the dashing website:
# :first_in sets how long it takes before the job is first run. In this case, it is run immediately
SCHEDULER.every '1m', :first_in => 0 do |job|
send_event('karma', { current: rand(1000) })
end
Question 2:
Currently the way I move code from my Windows PC to openSUSE, is via git. This means that when I want to test any change (simple or complicated) I must commit to git on the client, then push to the git branch on the server. This means that my commit history is going to be filled with test changes. Is there a better way to do this? (I'm guessing the only way around this, is to create a test web server on my client PC)
Thanks for any help you can provide.
Try "dashing job JOB_NAME AUTH_TOKEN".
The AUTH_TOKEN is stored in config.ru.
Dennis
me#host:~/Projects/my-dashing$ dashing --help
Tasks:
dashing generate (widget/dashboard/job) NAME # Creates a new widget, dashboard, or job.
dashing help [TASK] # Describe available tasks or one specific task
dashing install GIST_ID # Installs a new widget from a gist.
dashing job JOB_NAME AUTH_TOKEN(optional) # Runs the specified job. Make sure to supply your auth token if you have one set.
dashing new PROJECT_NAME # Sets up ALL THE THINGS needed for your dashboard project.
dashing start # Starts the server in style!
me#host:~/Projects/my-dashing$

Querying Active Directory in ruby app on Windows box

I have a small ruby app in which I'm trying to query some information from Active Directory. The app will be run by a Windows user who is already logged in. It looks like the ruby-net-ldap gem wants me to connect to an LDAP server using an IP address, port and then pass my username and password. Is there a way to achieve this (with a different gem, say) so that I don't have to pass this information (I don't have the current user's password for example, so that's not going to work)?
I'm also hosting a Trac website on our intranet (which is written in Python if I remember correctly and that seems to know the current Windows username and domain. If it can do it, surely my little ruby app can access this information too?
I resolved this by using the win32ole gem. I can now write code like this:
require 'win32ole'
ldap_root = WIN32OLE.connect('LDAP://RootDSE')

Resources