Skip to content

Commit

Permalink
Fix for viewport issue (#22)
Browse files Browse the repository at this point in the history
* Set a wider viewport, this way force the browser to render a non-mobile version of the app
* Correct timeout functionality, since the current implementation did not work correctly
* Adjust README to make the projects mission clearer
  • Loading branch information
0x111 authored Jun 18, 2020
1 parent f58538f commit 194ee79
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
43 changes: 28 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# servicenow-instance-wakeup

This app is here to help you with wakeing up your instance if needed.
At the first sight, this project may look like something you might have seen before.
A promise of never waking up your instance anymore. If you are in a search of something like that, you are in the wrong place!

This app symbolizes everything, that the process of waking up your instance should be!
A simple task of issuing one command to wake up your instance. No more time spent waiting on redirects.

Simply run the app and do something useful in the meanwhile instead of repetitive steps to wake your instance.

----
**Disclaimer**: This app is not made to keep your instance awake. This app was created due to the amount of time it takes for you, to wake up your instance.

It takes you approximately three to four minutes (sometimes more), to wake up your instance up right now. 90% of this time, is spent with waiting for redirects, filling out the username and password, waiting for some more redirects and then pushing one button.
It takes you approximately three to four minutes (sometimes more), to wake up your instance right now. 90% of this time, is spent with waiting for redirects, filling out the username and password, waiting for some more redirects and then pushing one button.

This app can be used, to reduce the time to do the manual steps required to wake up your instance. I do not condone keeping any instance awake just for the sake of it. This app only clicks the wakeup button if existing. This is not generating any actions that would keep your instance awake. It is simply emulating the manual tasks that you would do anyways if your instance would go to sleep. The app does not even work or does anything if your instance is already awake.
This app can be used, to reduce the time to do the manual steps required to wake up your instance. I do not condone keeping any instance awake just for the sake of it. This app only clicks the wake up button if existing (e.g. if the instance is already hibernated). This is not generating any actions that would keep your instance awake. It is simply emulating the manual tasks that you would do anyways if your instance would go to sleep. The app does not even work or does anything if your instance is already awake.

This is not a software to keep any instance awake. Please respect that! There were attempts, to make this a tool to keep it awake, like you can see in [#10](https://github.com/0x111/servicenow-instance-wakeup/issues/10) but this was rejected. Simply said, please do not categorize this app as something, that is jeopardizing the free PDI program. It has nothing to do with it.

Expand All @@ -16,17 +22,15 @@ This is not a software to keep any instance awake. Please respect that! There we
All of you who work with dev instances, you know what is this about.
Dev instances expire after a specific time period.

With this program, you do not need to log in manually to the developer portal anymore to wake up your instance.
With this software, you do not need to log in manually to the developer portal anymore to wake up your instance.

All this app is doing is taking your login credentials, logging you into the developer portal and then waking up your instance.

You can use this both ways but only choose one.

The app accepts cli parameters but if this is not something you would like to do, then you can have a `config.json` file in the same directory as the program based on the sample file here.

So an example for the cli app would be something like this:
```
program -username=some@email -password=somepassword -debug=false
program -username some@email -password somepassword -debug false
```

This would mean that the program will be started with the specified username and password values and with debugging disabled.
Expand All @@ -37,40 +41,47 @@ If we do not want to always specify parameters, we could use the config file in
{
"username": "developer@email",
"password": "password",
"timeout": 60,
"headless": false,
"debug": false
}
```

## Docker

To simplify cross platform delivery, the following docker image is capable of waking your ServiceNow Developer Instance
To simplify cross platform delivery, the following docker image is capable of waking your ServiceNow Developer Instance.

**Note**: This image does not contain anything, that would run the app periodically or automate it in any way.
You run the docker image, the app starts and after the specified timeout it does exit and thus, the docker container does the same too.
You should only run servicenow-instance-wakeup when you need to wake up your instance to try something. It is not recommended to run this
periodically.


### Docker hub

You can use the pre-built docker image from the [Docker hub](https://hub.docker.com/r/ruthless/servicenow-instance-wakeup) or you can pull the image issuing this command:
You can use the pre-built docker image from the [Docker hub](https://hub.docker.com/r/ruthless/servicenow-instance-wakeup) or you can pull the image.
```
docker pull ruthless/servicenow-instance-wakeup
```

### Build from source

In order to build this image do the following.
In order to build this image from source yourself, follow these steps.

Clone this github repository and change into the cloned directory
Clone this github repository and change into the cloned directory.

To build the image run the following
Run the build process:
```bash
docker build --rm -f "Dockerfile" -t servicenowinstancewakeup:latest "."
```

To run the docker image run the following
After the build is done, you are ready to run your own docker image:
```bash
docker run -e USERNAME='YOUR_USERNAME@YOUR_DOMAIN.com' -e PASSWORD='YOUR_SERVICENOW_DEVELOPER_PASSWORD' servicenow-instance-wakeup
```
The DEBUG and HEADLESS environment variables are available in this container should you need them.

By default the following env variables are set:
By default, the following environment variables are set:
```bash
DEBUG = false
HEADLESS = true
Expand All @@ -81,4 +92,6 @@ You can configure any of the existing cli flags in the docker container using th
docker run -e USERNAME='YOUR_USERNAME@YOUR_DOMAIN.com' -e PASSWORD='YOUR_SERVICENOW_DEVELOPER_PASSWORD' -e DEBUG=`true` -e HEADLESS='false` servicenowinstancewakeup
```
If you have any bugs or suggestions please open an issue or pull request.
If you have any bugs or suggestions please open an issue or pull request!
Every contribution is welcome!
14 changes: 12 additions & 2 deletions servicenow-instance-wakeup.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ func main() {
var err error
var configFile string
var timeout time.Duration
var seconds int64
userDetails := &User{}

flag.StringVar(&userDetails.Username, "username", "", "write the username/email with which you are logging in to the developers account")
flag.StringVar(&userDetails.Password, "password", "", "write the password with which you are logging in to the developers account")
flag.BoolVar(&userDetails.ChromeHeadless, "headless", false, "bool, if we need headless mode with chrome or not, default:false")
flag.BoolVar(&userDetails.Debug, "debug", false, "bool, if you want debug output or not, default:false")
flag.StringVar(&configFile, "config", "", "Provide the config file name, it can be a relative path or a full path, e.g. /home/user/servicenow-config.json or just simply 'config.json'")
flag.DurationVar(&timeout, "timeout", 60, "Set the timeout after which the app should exit. This is a number in seconds, default:60")
flag.Int64Var(&seconds, "timeout", 60, "Set the timeout after which the app should exit. This is a number in seconds, default:60")
flag.Parse()

// Read config into struct if exists
Expand Down Expand Up @@ -73,6 +74,8 @@ func main() {
)
defer cancel()

timeout = time.Duration(seconds) * time.Second

err = wakeUpInstance(ctx, userDetails.Username, userDetails.Password, timeout)

if err != nil {
Expand All @@ -84,11 +87,18 @@ func main() {
func wakeUpInstance(ctx context.Context, username string, password string, timeout time.Duration) error {
var cancel func()
// create a timeout
ctx, cancel = context.WithTimeout(ctx, timeout*time.Second)
ctx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()

initialURL := "https://developer.servicenow.com/ssologin.do?relayState=%2Fdev.do%23%21%2Fhome"

// setting viewport to a wider screen so we see the wakeup button
if err := chromedp.Run(ctx, chromedp.EmulateViewport(1920, 1280)); err != nil {
return fmt.Errorf("could not set viewport: %v", err)
} else {
fmt.Printf("Successfully set the viewport...\n")
}

fmt.Printf("Navigating to the webpage: %s\n", initialURL)
// first navigate to the sso login page
if err := chromedp.Run(ctx, chromedp.Navigate(initialURL)); err != nil {
Expand Down

0 comments on commit 194ee79

Please sign in to comment.