Skip to content

Commit 68ca0b3

Browse files
authored
windows support: stage 2 (#36)
and prepare to release v0.1.0
1 parent f9c0921 commit 68ca0b3

File tree

32 files changed

+281
-129
lines changed

32 files changed

+281
-129
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# This is for Test, would merge to client_build.yml
2+
name: fornet client windows build
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
commandLine:
8+
runs-on: windows-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
with:
12+
submodules: true
13+
- name: Install Rust
14+
uses: actions-rs/toolchain@v1
15+
with:
16+
toolchain: stable
17+
target: x86_64-pc-windows-msvc
18+
profile: minimal
19+
- name: Set up cargo cache
20+
uses: actions/cache@v3
21+
with:
22+
path: |
23+
~/.cargo/bin/
24+
~/.cargo/registry/index/
25+
~/.cargo/registry/cache/
26+
~/.cargo/git/db/
27+
client/target/
28+
key: windows-cargo-${{ hashFiles('**/Cargo.lock') }}
29+
restore-keys: windows-cargo
30+
31+
- name: build
32+
shell: pwdsh
33+
run: ./build.ps1
34+
35+
- name: Upload artifact
36+
uses: actions/upload-artifact@v2
37+
with:
38+
path: release/*
39+
if-no-files-found: error
40+
41+

admin-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "admin-web",
3-
"version": "0.0.4",
3+
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
66
"@reduxjs/toolkit": "^1.9.5",

backend/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
If Scala 3 is a good choice?
21

3-
### TODO
42

5-
- [ ] create IpArrange util to handle all, should be careful use.
6-
- [ ] needs async runtime(thread pool) to handle push.
3+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"dev": {
33
"host": "http://dev.fornetcode.com/api",
4-
"keycloak": "http://keycloak-dev.fornetcode.com"
4+
"keycloak": "http://keycloak-dev.fornetcode.com",
5+
"mqtt": "http://dev.fornetcode.com/mqtt"
56
}
67
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
###
2+
#@name mqtt auth
3+
POST {{mqtt}}/auth
4+
Content-Type: application/json
5+
6+
{"clientId":"nqjKd_9K8yY","username":"rGgmdNOn3tO1am2mn/S/Rno5ijPOTTMK0XscDeXpZVnk3KEcGEL5Uk+gW91lM7JgK1TiBYyHt4o8xQUxkizUCw==","password": "PSIFTk6vYNyLu9ODdjoJfg==|1695308250|W5UghfFvbj7S3wDhfHSJsxOHnMhwBOuNRv/uipInHk21S2Qxthwc54iqCrjxfySl/xTpLHGQQ8mgBxUtz0HgCw=="}

backend/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ lazy val webSugar = RootProject(file("../third/web-sugar"))
2121
lazy val app = project
2222
.in(file("."))
2323
.settings(
24-
version := "0.0.4",
24+
version := "0.1.0",
2525
scalaVersion := scala3Version,
2626
libraryDependencies ++=
2727
Seq(

backend/src/main/resources/db/migration/V3__support_multiple_network.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
alter table network
2-
add column token text not null default 'network-token';
2+
add column token text not null default 'network';
33
comment on column network.token is 'special token to protect from brute force';
44

55
alter table node

backend/src/main/scala/com/timzaak/fornet/controller/NodeController.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ trait NodeController(
162162
.findById(networkId, nodeId)
163163
.filter(_.status == NodeStatus.Waiting)
164164
.map { _ =>
165+
val networkSecretId = networkDao.findById(_networkId).get.tokenId.secretId
165166
String(
166167
Base64.getEncoder.encode(
167-
s"1|${config.getString("server.grpc.endpoint")}|${networkId.secretId}|${nodeId.secretId}".getBytes
168+
s"1|${config.getString("server.grpc.endpoint")}|${networkSecretId}|${nodeId.secretId}".getBytes
168169
)
169170
)
170171
}

backend/src/main/scala/com/timzaak/fornet/dao/Device.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DeviceDao(using quill: DB, hashids: Hashids) {
2828
if(ids.isEmpty) {
2929
Map.empty
3030
} else {
31-
quill.run(quote(query[Device])).filter(v => liftQuery(ids).contains(v.id)).map(v => v.id.id -> v).toMap
31+
quill.run(quote(query[Device]).filter(v => liftQuery(ids).contains(v.id))).map(v => v.id.id -> v).toMap
3232
}
3333
}
3434
}

backend/src/main/scala/com/timzaak/fornet/grpc/AuthGRPCController.scala

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.timzaak.fornet.grpc
22

3-
import ch.qos.logback.core.joran.action.Action
4-
import com.google.common.base.Charsets
5-
import com.google.protobuf.empty.Empty
63
import com.timzaak.fornet.config.AppConfig
74
import com.timzaak.fornet.controller.auth.AppAuthStrategyProvider
85
import com.timzaak.fornet.dao.*
@@ -20,12 +17,8 @@ import very.util.keycloak.KeycloakJWTAuthStrategy
2017
import very.util.security.{ IntID, TokenID }
2118
import very.util.web.LogSupport
2219
import zio.json.*
23-
import zio.json.ast.{ Json, JsonCursor }
2420

25-
import java.net.http.HttpRequest.BodyPublishers
26-
import java.net.http.{ HttpClient, HttpRequest }
27-
import java.net.{ URI, URLEncoder }
28-
import java.time.{ LocalDateTime, OffsetDateTime }
21+
import java.time.OffsetDateTime
2922
import scala.concurrent.Future
3023
import scala.util.{ Failure, Success, Try }
3124

@@ -49,9 +42,9 @@ class AuthGRPCController(
4942
private def errorResponse(message: String) = ActionResponse(
5043
ActionResponse.Response.Error(message)
5144
)
52-
private def successResponse(secretId: String) = ActionResponse(
45+
private def successResponse(deviceId: TokenID) = ActionResponse(
5346
ActionResponse.Response.Success(
54-
com.timzaak.fornet.protobuf.auth.SuccessResponse(mqttClientUrl, secretId)
47+
com.timzaak.fornet.protobuf.auth.SuccessResponse(mqttClientUrl, deviceId.secretId)
5548
)
5649
)
5750

@@ -181,15 +174,15 @@ class AuthGRPCController(
181174
NodeStatus.Waiting,
182175
NodeStatus.Normal
183176
)
184-
successResponse(node.id.secretId)
177+
successResponse(device.tokenID)
185178
} else {
186179
errorResponse("already active or error response")
187180
}
188181
case (None, Success(device), Right(networkTokenId)) =>
189182
createNode(networkTokenId.intId, publicKey, device) match {
190183
case Left(value) => errorResponse(value)
191184
case Right(id) =>
192-
successResponse(id.secretId)
185+
successResponse(device.tokenID)
193186
}
194187
}
195188
Future.successful(response)
@@ -245,7 +238,7 @@ class AuthGRPCController(
245238
)
246239
createNode(networkTokenId.intId, publicKey, device) match {
247240
case Left(value) => errorResponse(value)
248-
case Right(id) => successResponse(id.secretId)
241+
case Right(id) => successResponse(device.tokenID)
249242
}
250243
case (_, Left(message)) => errorResponse(message)
251244
case _ => errorResponse("Illegal Arguments")

0 commit comments

Comments
 (0)