Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge version 2 into dev version 3 #28

Merged
merged 6 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 16 additions & 40 deletions .github/workflows/dev-java-publish-sonatype.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,22 @@ on:
branches-ignore:
- master
- version-*
- dependabot*
- dev-version-*
# paths:
# - gradle.properties
paths-ignore:
- README.md
- README.md

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
# Prepare custom build version
- name: Get branch name
id: branch
run: echo ::set-output name=branch_name::${GITHUB_REF#refs/*/}
- name: Get release_version
id: ver
uses: christian-draeger/[email protected]
with:
path: gradle.properties
property: release_version
- name: Build custom release version
id: release_ver
run: echo ::set-output name=value::"${{ steps.ver.outputs.value }}-${{ steps.branch.outputs.branch_name }}-${{ github.run_id }}-SNAPSHOT"
- name: Write custom release version to file
uses: christian-draeger/[email protected]
with:
path: gradle.properties
property: release_version
value: ${{ steps.release_ver.outputs.value }}
- name: Show custom release version
run: echo ${{ steps.release_ver.outputs.value }}
# Build and publish package
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Build with Gradle
run: ./gradlew --info clean build publish
env:
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}

build-job:
uses: th2-net/.github/.github/workflows/compound-java-dev.yml@main
with:
build-target: 'Sonatype'
runsOn: ubuntu-latest
secrets:
sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}

22 changes: 22 additions & 0 deletions .github/workflows/dev-release-java-publish-sonatype.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build and publish dev-release Java distributions to sonatype.

on:
workflow_dispatch:
push:
branches:
- dev-version-*
paths:
- gradle.properties

jobs:
build:
uses: th2-net/.github/.github/workflows/compound-java.yml@main
with:
build-target: 'Sonatype'
runsOn: ubuntu-latest
devRelease: true
secrets:
sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
24 changes: 9 additions & 15 deletions .github/workflows/java-publish-sonatype.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ on:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Build with Gradle
run: ./gradlew --info clean build publish closeAndReleaseSonatypeStagingRepository
env:
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
uses: th2-net/.github/.github/workflows/compound-java.yml@main
with:
build-target: 'Sonatype'
runsOn: ubuntu-latest
secrets:
sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
126 changes: 124 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,118 @@ Outgoing message can be handled differently depending on send mode. There are 4

**NOTE**: when using infra 1.7.0+ it is recommended to load value for `certFile` from a secret by using `${secret_path:secret_name}` syntax.

## Built-in mangler

This library also contains a basic mangler which will be used if library user does not implement its own.

### Configuration

+ *rules* - list of mangling rules

#### Rule

```yaml
name: String # rule name
if-contains: List<ValueSelector> # list of values expected in a message for this rule to be applied
then: List<Action> # list of actions to be applied to a matching message
```

#### Value definition

```yaml
i8: Byte # defines 8-bit integer value
i16: Short # defines 16-bit integer value
i16be: Short # defines big-endian 16-bit integer value
i32: Int # defines 32-bit integer value
i32be: Int # defines big-endian 32-bit integer value
i64: Long # defines 64-bit integer value
i64be: Long # defines big-endian 64-bit integer value
f32: Float # defines 32-bit float value
f32be: Float # defines big-endian 32-bit float value
f64: Double # defines 64-bit double value
f64be: Double # defines big-endian 64-bit double value
str: String # defines string value
bytes: Byte # defines byte-array value
charset: Charset # charset of a string value ("UTF_8" by default)
```

**NOTE**: only single value type can be specified in a definition

#### Value selector definition

Selector defines a single expected value at a specified or arbitrary position in a message.
It is defined the same way as a value except that it can also contain an offset at which value will be expected:

```yaml
at-offset: Int # value offset (-1 by default)
```

**NOTE**: negative or absent offset means that value has no predefined offset in a message

#### Action definitions:

* set - sets a value at a specified position:

```yaml
set: ValueSelector # value to set
```

**NOTE**: value selector must contain value offset


* add - adds a value at a specified position or before/after existing value:

```yaml
add: ValueSelector # value to add
before: ValueSelector # value before which this value will be added (optional)
after: ValueSelector # value after which this value will be added (optional)
```

**NOTE**: `add` selector cannot have an offset if `before` or `after` selector is specified and vice versa


* move - moves a value after or before another value

```yaml
move: ValueSelector # value to move
before: ValueSelector # value before which this value will be placed
after: ValueSelector # value after which this value will be placed
```

* replace - replaces a value with another value

```yaml
replace: ValueSelector # value to replace
with: ValueDefinition # value to replace this value with
```
* remove - removes a value

```yaml
remove: ValueSelector # value to remove
```

### Message will be mangled when:

1) It contains all values from `if-contains` list of a rule from mangler configuration
2) It contains existing rule name in `rule-name` property - in this case rule will be applied unconditionally
3) It contains rule actions in YAML format in `rule-actions` property - specified actions will be applied

### Mangler configuration example

```yaml
rules:
- name: replace_login_username
if-contains:
- i8: 1 # login message type
at-offset: 2 # message type offset
then:
- replace:
str: old_username # username value
at-offset: 10 # username offset
with:
str: new_username
```

## Box configuration example

```yaml
Expand All @@ -72,8 +184,6 @@ spec:
image-version: ...
type: th2-conn
custom-config:
autoStart: true
autoStopAfter: 0
maxBatchSize: 1000
maxFlushTime: 1000
publishSentEvents: true
Expand Down Expand Up @@ -143,6 +253,18 @@ spec:
## 3.0.0

* add support for session groups, books and pages
## 2.2.2

* fix `move` action in mangler not being marked as applied

## 2.2.1

* th2-common upgrade to `3.44.1`
* th2-bom upgrade to `4.2.0`

## 2.2.0

* add basic mangler

## 2.1.0

Expand Down
24 changes: 20 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'signing'
id 'org.jetbrains.kotlin.jvm' version "${kotlin_version}"
id "io.github.gradle-nexus.publish-plugin" version '1.1.0'
id "org.owasp.dependencycheck" version "8.1.2"
}

ext {
Expand Down Expand Up @@ -165,10 +166,10 @@ clean {
}

dependencies {
api platform('com.exactpro.th2:bom:4.1.0')
api platform('com.exactpro.th2:bom:4.2.0')

implementation group: 'com.exactpro.th2', name: 'common', version: '5.1.0-dev-version-5-+'
implementation group: 'com.exactpro.th2', name: 'common-utils', version: '1.0.0-book-and-page-4086360735-d23a5e0-SNAPSHOT'
implementation group: 'com.exactpro.th2', name: 'common', version: '5.2.0-dev'
implementation group: 'com.exactpro.th2', name: 'common-utils', version: '2.0.0-dev'
implementation group: 'com.exactpro.th2', name: 'netty-bytebuf-utils', version: '0.0.1'

implementation 'org.slf4j:slf4j-api'
Expand All @@ -179,8 +180,23 @@ dependencies {
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310'
implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-kotlin', version: '2.11.2'
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: '1.7.9'
implementation group: 'io.netty', name: 'netty-all', version: '4.1.86.Final'
implementation group: 'io.netty', name: 'netty-all'
implementation group: 'org.jctools', name: 'jctools-core', version: '3.3.0'

testImplementation group: 'org.jetbrains.kotlin', name: 'kotlin-test-junit5', version: kotlin_version
}

dependencyLocking {
lockAllConfigurations()
}

dependencyCheck {
formats=['SARIF', 'JSON', 'HTML']
failBuildOnCVSS=5

analyzers {
assemblyEnabled = false
nugetconfEnabled = false
nodeEnabled = false
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 3 additions & 3 deletions src/main/kotlin/com/exactpro/th2/conn/dirty/tcp/core/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.exactpro.th2.conn.dirty.tcp.core.api.IHandlerFactory
import com.exactpro.th2.conn.dirty.tcp.core.api.IHandlerSettings
import com.exactpro.th2.conn.dirty.tcp.core.api.IManglerFactory
import com.exactpro.th2.conn.dirty.tcp.core.api.IManglerSettings
import com.exactpro.th2.conn.dirty.tcp.core.api.impl.DummyManglerFactory
import com.exactpro.th2.conn.dirty.tcp.core.api.impl.mangler.BasicManglerFactory
import com.exactpro.th2.conn.dirty.tcp.core.util.load
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.databind.module.SimpleModule
Expand Down Expand Up @@ -61,8 +61,8 @@ fun main(args: Array<String>) = try {

val handlerFactory = load<IHandlerFactory>()
val manglerFactory = load<IManglerFactory?>() ?: run {
LOGGER.warn { "No mangler was found. Using a dummy one" }
DummyManglerFactory
LOGGER.warn { "No mangler was found. Using a default one" }
BasicManglerFactory
}

LOGGER.info { "Loaded protocol handler factory: ${handlerFactory.name}" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import com.exactpro.th2.common.utils.event.EventBatcher
import com.exactpro.th2.conn.dirty.tcp.core.api.IHandler
import com.exactpro.th2.conn.dirty.tcp.core.api.IHandlerFactory
import com.exactpro.th2.conn.dirty.tcp.core.api.IManglerFactory
import com.exactpro.th2.conn.dirty.tcp.core.api.impl.DummyManglerFactory.DummyMangler
import com.exactpro.th2.conn.dirty.tcp.core.api.impl.HandlerContext
import com.exactpro.th2.conn.dirty.tcp.core.api.impl.ManglerContext
import com.exactpro.th2.conn.dirty.tcp.core.api.impl.mangler.NoOpMangler
import com.exactpro.th2.conn.dirty.tcp.core.util.eventId
import com.exactpro.th2.conn.dirty.tcp.core.util.logId
import com.exactpro.th2.conn.dirty.tcp.core.util.messageId
Expand Down Expand Up @@ -214,7 +214,7 @@ class Microservice(
val handler = handlerFactory.create(handlerContext)

val mangler = when (val settings = session.mangler) {
null -> DummyMangler
null -> NoOpMangler
else -> manglerFactory.create(ManglerContext(settings, readDictionary, sendEvent))
}

Expand Down
Loading
Loading