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

Make FileBackend VCS diff friendly #317

Closed
2 changes: 1 addition & 1 deletion .github/workflows/ci-integration-test-legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
matrix:
os: [ubuntu-latest]
java: [8]
cpversion: [5.5.3, 6.0.2, 6.1.0]
cpversion: [6.1.2, 6.2.0]

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-integration-test-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
matrix:
os: [ubuntu-latest]
java: [11.0.x]
cpversion: [5.5.3, 6.0.2, 6.1.0]
cpversion: [6.1.2, 6.2.0]

runs-on: ${{ matrix.os }}

Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/nightly-artifacts-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Import private GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v3
with:
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: Import public GPG Key
run: rpm --import release/keys/public.key
- uses: docker/setup-buildx-action@v1
- name: Set up the JDK
uses: actions/setup-java@v1
Expand Down Expand Up @@ -70,19 +62,29 @@ jobs:
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Import private GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v4
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Import public GPG Key
run: rpm --import release/keys/public.key
- name: Build the rpm
run: mvn rpm:rpm
- name: Sign rpm
run: |
rpm --define "_gpg_name $GPG_KEY_NAME" --addsign target/rpm/julie-ops/RPMS/noarch/*.rpm
rpm --define "_gpg_name ${{ steps.import_gpg.outputs.keyid }}" --addsign target/rpm/julie-ops/RPMS/noarch/*.rpm
rpm --checksig target/rpm/julie-ops/RPMS/noarch/*.rpm
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_KEY_NAME: ${{ steps.import_gpg.outputs.email }}
- name: Sign deb
run: |
sudo apt-get install dpkg-sig -y
dpkg-sig -k $GPG_KEY_NAME --sign builder $FILE target/*.deb
dpkg-sig -k ${{ steps.import_gpg.outputs.keyid }} --sign builder $FILE target/*.deb
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_KEY_NAME: ${{ steps.import_gpg.outputs.email }}
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/release-artifacts-build-legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,29 @@ jobs:
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Import private GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v4
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Import public GPG Key
run: rpm --import release/keys/public.key
- name: Build the rpm
run: mvn rpm:rpm
- name: Sign rpm
run: |
rpm --define "_gpg_name ${{ steps.import_gpg.outputs.keyid }}" --addsign target/rpm/julie-ops/RPMS/noarch/*.rpm
rpm --checksig target/rpm/julie-ops/RPMS/noarch/*.rpm
- name: Sign deb
run: |
sudo apt-get install dpkg-sig -y
dpkg-sig -k ${{ steps.import_gpg.outputs.keyid }} --sign builder $FILE target/*.deb
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_KEY_NAME: ${{ steps.import_gpg.outputs.email }}
- uses: actions/upload-artifact@v2
with:
name: RPM package
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/release-artifacts-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ jobs:
- uses: actions/checkout@v2
- name: Import private GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v3
uses: crazy-max/ghaction-import-gpg@v4
with:
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Import public GPG Key
run: rpm --import release/keys/public.key
- name: Set up the JDK
Expand All @@ -34,15 +36,15 @@ jobs:
run: mvn rpm:rpm
- name: Sign rpm
run: |
rpm --define "_gpg_name $GPG_KEY_NAME" --addsign target/rpm/julie-ops/RPMS/noarch/*.rpm
rpm --define "_gpg_name ${{ steps.import_gpg.outputs.keyid }}" --addsign target/rpm/julie-ops/RPMS/noarch/*.rpm
rpm --checksig target/rpm/julie-ops/RPMS/noarch/*.rpm
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_KEY_NAME: ${{ steps.import_gpg.outputs.email }}
- name: Sign deb
run: |
sudo apt-get install dpkg-sig -y
dpkg-sig -k $GPG_KEY_NAME --sign builder $FILE target/*.deb
dpkg-sig -k ${{ steps.import_gpg.outputs.keyid }} --sign builder $FILE target/*.deb
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GPG_KEY_NAME: ${{ steps.import_gpg.outputs.email }}
Expand Down
65 changes: 49 additions & 16 deletions release/keys/public.key
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBF8q4tcBCADUXVN8G0smSfgHz7EmgN2Ou69kFjMfvP2t7Yncj6X1xS1YlurB
IfQ5rRw9ZVX5mvbqyQ9/GNrqFK23sdxrusiWImewDBzHRQLnXPmqaukjZJ8eM+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
h8Y//9aYg2LnfFY6rl8MQ6kIue2KiPgGzChIQQIFlNsF89RSmS+Re3eS2MF7hbea
q6Faf9J1QAhqUlyqy+28J6VBVJHFqtyNIbbEC0nPU4TI8BDMhNDe5/BaWtECc1Ew
eJjNGEI5FHA9S+fvkVG8YCPdf3l32rLMeX5TOdsMJ11qSh3uV6AEgJ270OpLyCF1
BOpvMCgMDJNYtnV+Mu+PHKva8SHWiCGDv+2hK2QpP21Y2ts8QTWkncfPR8DZnzG/
z8lRT/aPsUMhTmL8hUm3WgtKeI8ZgHHT+kb1Xt6c4ukP3OMsfoFBD/EkPsAqHnWW
b7l6TrgGA4J/SJadEzKZ3YQ3IeAlA4zQ/UWy+xQO1z6oHhoNPXkhGkWSiQ488/qx
QYUcJEVofmbo88KwwQ1/VrnPbTC94z8P1EpN+ZnYELsohaSGEWob8Jg9a5bzmBgV
BHEWkAuvfB/iRR2q6i+K4dfOA6zxkeMBwbMZhjrjdQ9Z1m9AmGBmIWP5pg8EfIOG
1jTgvdWVobp+w2qSADQeI+PWz7ZHZUzXYk1+esVkzQCjV4pzR4+23nOwEoDPCgyf
FgrSDuBNkk2qzvYUoQD++m0FJDwrCmFdQ6Ig/PBerIyX8luCyMQ+FU8tb0faRAyC
CRNminCORZgJISzle5IG4NSu
=2myt
-----END PGP PUBLIC KEY BLOCK-----
10 changes: 2 additions & 8 deletions src/main/java/com/purbon/kafka/topology/KSqlArtefactManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,9 @@ private Collection<? extends Artefact> getClustersState() throws IOException {
.map(
artefact -> {
if (artefact instanceof KsqlStreamArtefact) {
return new KsqlStreamArtefact(
artefact.getPath(),
null,
artefact.getName());
return new KsqlStreamArtefact(artefact.getPath(), null, artefact.getName());
} else if (artefact instanceof KsqlTableArtefact) {
return new KsqlTableArtefact(
artefact.getPath(),
null,
artefact.getName());
return new KsqlTableArtefact(artefact.getPath(), null, artefact.getName());
} else {
LOGGER.error("KSQL Artefact of wrong type " + artefact.getClass());
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class AbstractBackend implements Backend {
class BackendHelper {

private final String expression =
private static final String expression =
"^\"?\\'(\\S+)\\',\\s*\\'(\\S+)\\',\\s*\\'(\\S+)\\',\\s*\\'(\\S+)\\',\\s*\\'(.+)\\',\\s*\\'(\\S+)\\'\"?$";
private Pattern regexp;
private static Pattern regexp = Pattern.compile(expression);

public AbstractBackend() {
this.regexp = Pattern.compile(expression);
}
private BackendHelper() {}

protected TopologyAclBinding buildAclBinding(String line) throws IOException {
static TopologyAclBinding buildAclBinding(String line) throws IOException {
// 'TOPIC', 'topicB', '*', 'READ', 'User:Connect1', 'LITERAL'
Matcher matches = regexp.matcher(line);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public String asJson() throws JsonProcessingException {
return JSON.asString(this);
}

@JsonIgnore
public String asPrettyJson() throws JsonProcessingException {
return JSON.asPrettyString(this);
}

public void clear() {
bindings.clear();
accounts.clear();
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/com/purbon/kafka/topology/backend/FileBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import com.purbon.kafka.topology.BackendController.Mode;
import com.purbon.kafka.topology.utils.JSON;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -14,7 +12,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class FileBackend extends AbstractBackend {
public class FileBackend implements Backend {

private static final Logger LOGGER = LogManager.getLogger(FileBackend.class);

Expand Down Expand Up @@ -43,7 +41,7 @@ public void createOrOpen(Mode mode) {

@Override
public void save(BackendState state) throws IOException {
writeLine(state.asJson());
writeText(state.asPrettyJson());
}

@Override
Expand All @@ -52,16 +50,20 @@ public BackendState load() throws IOException {
if (Files.size(filePath) == 0) { // if we are loading when there is no file or is empty.
return new BackendState();
}
try (BufferedReader reader = new BufferedReader(new FileReader(filePath.toFile()))) {
String backendStateAsJsonString = reader.readLine();
return (BackendState) JSON.toObject(backendStateAsJsonString, BackendState.class);
return load(filePath);
}

BackendState load(Path stateFilePath) throws IOException {
String backendStateAsJsonString = Files.readString(stateFilePath);
if (OldFileBackendLoader.isControlTag(backendStateAsJsonString.split("\\r?\\n")[0])) {
return new OldFileBackendLoader().load(stateFilePath.toFile());
}
return (BackendState) JSON.toObject(backendStateAsJsonString, BackendState.class);
}

private void writeLine(String line) throws IOException {
private void writeText(String text) throws IOException {
try {
writer.write(line);
writer.write("\n");
writer.write(text);
} catch (IOException e) {
LOGGER.error(e);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class GCPBackend extends AbstractBackend {
public class GCPBackend implements Backend {

private static final Logger LOGGER = LogManager.getLogger(GCPBackend.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.purbon.kafka.topology.backend;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.purbon.kafka.topology.model.cluster.ServiceAccount;
import com.purbon.kafka.topology.roles.TopologyAclBinding;
import com.purbon.kafka.topology.utils.JSON;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

class OldFileBackendLoader {

private static final Logger LOGGER = LogManager.getLogger(OldFileBackendLoader.class);
static final String SERVICE_ACCOUNTS_TAG = "ServiceAccounts";
static final String TOPICS_TAG = "Topics";
static final String ACLS_TAG = "acls";

BackendState load(File file) throws IOException {
BackendState state = new BackendState();
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
String type = null;
String line;
while ((line = in.readLine()) != null) {
if (type == null || isControlTag(line)) {
type = line;
continue;
}
if (type.equalsIgnoreCase(SERVICE_ACCOUNTS_TAG)) {
final ServiceAccount serviceAccount = parseServiceAccount(line);
if (serviceAccount != null) {
state.addAccounts(Collections.singleton(serviceAccount));
}
} else if (type.equalsIgnoreCase(ACLS_TAG)) {
state.addBindings(Collections.singleton(parseAcl(line)));
} else if (type.equalsIgnoreCase(TOPICS_TAG)) {
state.addTopics(Collections.singleton(parseTopic(line)));
} else {
throw new IOException("Binding type \"" + type + "\" not supported.");
}
}
}
return state;
}

private ServiceAccount parseServiceAccount(final String line) {
try {
return (ServiceAccount) JSON.toObject(line, ServiceAccount.class);
} catch (JsonProcessingException e) {
LOGGER.error(e);
return null;
}
}

private TopologyAclBinding parseAcl(final String line) throws IOException {
return BackendHelper.buildAclBinding(line);
}

private String parseTopic(final String line) {
return line.trim();
}

static boolean isControlTag(String line) {
return line.equalsIgnoreCase(SERVICE_ACCOUNTS_TAG)
|| line.equalsIgnoreCase(TOPICS_TAG)
|| line.equalsIgnoreCase(ACLS_TAG);
}
}
Loading