Skip to content

Commit

Permalink
Implement Service
Browse files Browse the repository at this point in the history
Add Sample Config
Add CI
Add Readme
  • Loading branch information
Felix Dittrich committed Jan 28, 2023
1 parent e4d9c7f commit bf7d38c
Show file tree
Hide file tree
Showing 22 changed files with 1,866 additions and 18 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: ci-main
on:
workflow_dispatch:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-java@v3
with:
java-version: 17
distribution: temurin
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.m2/repository
key: ${{ runner.os }}-${{ hashFiles('**/pom.xml') }}
- name: version
run: >-
APP_SHA=$(git rev-parse --short ${GITHUB_SHA});
APP_REV=$(git rev-list --tags --max-count=1);
APP_TAG=$(git describe --tags ${APP_REV} 2> /dev/null || echo 0.0.0);
APP_VERSION=${APP_TAG}-${APP_SHA};
echo "APP_SHA=${APP_SHA}" >> ${GITHUB_ENV};
echo "APP_TAG=${APP_TAG}" >> ${GITHUB_ENV};
echo "APP_VERSION=${APP_VERSION}" >> ${GITHUB_ENV};
- name: Build Artifact and Docker Image
run: >-
mvn versions:set
--batch-mode
--file ./pom.xml
--define newVersion="${APP_VERSION}";
mvn clean install spring-boot:build-image
--batch-mode
--file ./pom.xml
--define app.packages.username="${APP_PACKAGES_USERNAME}"
--define app.packages.password="${APP_PACKAGES_PASSWORD}"
-Dspring-boot.build-image.imageName="ghcr.io/${{ github.repository }}:${APP_VERSION}";
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Docker Image
run: docker push ghcr.io/${{ github.repository }}:${APP_VERSION}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ build/

### VS Code ###
.vscode/

### Customized Sample Confs ###
sample-conf/**
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Polestar Order Tracker

Automatically track the detailed OrderInformation of you Polestar order!<br />
Get notifications via E-Mail if anything happens regarding your future car!

It checks every 6 hours if the OrderModel of the Polestar GRAPH API of your order has changed. If there are any changes
it will send you an email with a detailed report of what has changed.

The service uses an in-memory database to keep track of the "old" state of the order. On startup the OrderModel will be fetched
and stored date will be used to detect the changes. It makes no sense to run this program just for a short time. I suggest
to run it as a daemon on a server.

## Disclaimer

Polestar has not officially released the used APIs for consumers/ 3rd party apps. That's why I cannot guarantee that the usage
of this service is allowed nor that the APIs will provide the required features in the future.

## Contribution

This is an OpenSource project. If you want to participate just clone the repository, do your changes and create a PullRequests.

## Build

To build the project on your own **Java 17+** is required.
Open a shell within the project directory and execute the following command:

```bash
mvnw install
```

You can find the resulting ```polestar-order-tracker-X.X.X.jar``` in the ```target``` directory.

## Configure & Run

### Direct

Create a copy of the file ```application.yml``` from ```sample-conf``` directory and place it next to the
```polestar-order-tracker-X.X.X.jar``` which you have build on your own or downloaded
from [Releases](https://github.com/f11h/polestar-order-tracker/releases) page.

Adjust the values in this file according to your needs (Setup E-Mail Server and your Polestar order details)

| Property | Description | Possible Values/ Example |
|----------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
| polestar-order-tracker.order-configs[]enabled | Enable this order to keep track of it | true, false |
| polestar-order-tracker.order-configs[]notify-email | Provide a list of E-Mail recipient, which will get notified about changes | [email protected] |
| polestar-order-tracker.order-configs[]order-id | The UUID of your Polestar Order. Open your order via the Web-Portal. You will see an URL like ```https://www.polestar.com/de/order/424641db-6692-49a8-aa10-2fe970516404``` in your Browsers address bar. We need the ID from the end of the url. | 424641db-6692-49a8-aa10-2fe970516404 |
| polestar-order-tracker.order-configs[]username | Your E-Mail of your Polestar ID | [email protected] |
| polestar-order-tracker.order-configs[]password | Your Password of your Polestar ID | sup3rS3cur3 |

Just start the service with the following command

```bash
java -jar polestar-order-tracker-X.X.X.jar
```

### Docker

The service can also started as Docker container. Therefore the configuration should be done via environment variables:

| ENV | Description | Possible Values/ Example |
|---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
| SPRING_MAIL_HOST | SMTP Server Host | smtp.example.org |
| SPRING_MAIL_PORT | SMTP Server Port | 587 |
| SPRING_MAIL_USERNAME | SMTP Username | [email protected] |
| SPRING_MAIL_PASSWORD | SMTP User Password | sup3rS3cur3 |
| POLESTARORDERTRACKER_ORDERCONFIGS_0_ENABLED | Enable this order to keep track of it | true, false |
| POLESTARORDERTRACKER_ORDERCONFIGS_0_NOTIFYEMAIL_0 | Provide a E-Mail recipient, which will get notified about changes | [email protected] |
| POLESTARORDERTRACKER_ORDERCONFIGS_0_ORDERID | The UUID of your Polestar Order. Open your order via the Web-Portal. You will see an URL like ```https://www.polestar.com/de/order/424641db-6692-49a8-aa10-2fe970516404``` in your Browsers address bar. We need the ID from the end of the url. | 424641db-6692-49a8-aa10-2fe970516404 |
| POLESTARORDERTRACKER_ORDERCONFIGS_0_USERNAME | Your E-Mail of your Polestar ID | [email protected] |
| POLESTARORDERTRACKER_ORDERCONFIGS_0_PASSWORD | Your Password of your Polestar ID | sup3rS3cur3 |

39 changes: 22 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.2</version>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>2022.0.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.f11h</groupId>
<artifactId>polestar-order-tracker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>latest</version>
<name>polestar-order-tracker</name>
<description>polestar-order-tracker</description>
<properties>
Expand All @@ -27,33 +27,38 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

<!-- DB -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<!-- 3rd Party Lib -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.flipkart.zjsonpatch</groupId>
<artifactId>zjsonpatch</artifactId>
<version>0.4.14</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
15 changes: 15 additions & 0 deletions sample-conf/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
spring:
mail:
host: smtp.gmail.com
port: 587
username: [email protected]
password: your-gmail-passowrd

polestar-order-tracker:
order-configs:
- enabled: true
notify-email:
- [email protected]
order-id: 424641db-6692-49a8-aa10-2fe970516404
username: [email protected]
password: YourSuperSecurePolestarPassword
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableFeignClients
@EnableConfigurationProperties
@EnableScheduling
public class PolestarOrderTrackerApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.f11h.polestarordertracker.client;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;

@Data
@Getter
public
class AccessTokenResponse {
private Data data;

@lombok.Data
public static class Data {

@JsonProperty("getAuthToken")
private Data.AuthToken getAuthToken;

@lombok.Data
public static class AuthToken {
@JsonProperty("id_token")
private String idToken;
@JsonProperty("access_token")
private String accessToken;
@JsonProperty("refresh_token")
private String refreshToken;
@JsonProperty("expires_in")
private Integer expiresIn;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.f11h.polestarordertracker.client;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public
class GetOrderModelRequest {
private String operationName;
private String query;
private Variables variables;

@Data
@AllArgsConstructor
public static class Variables {

public Variables(String orderId) {
request = new Request(orderId);
}

private Variables.Request request;

@Data
@AllArgsConstructor
public static class Request {
private String id;
}
}
}
Loading

0 comments on commit bf7d38c

Please sign in to comment.