This is an automated email from the ASF dual-hosted git repository.
marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
The following commit(s) were added to refs/heads/main by this push:
new 45f7c561 Fixed #1006
45f7c561 is described below
commit 45f7c561dc68839a59dc3c0783b4885f6a591ba5
Author: Marat Gubaidullin <[email protected]>
AuthorDate: Wed Nov 29 15:18:37 2023 -0500
Fixed #1006
---
.../java/org/apache/camel/karavan/api/UsersResource.java | 1 +
.../java/org/apache/camel/karavan/git/GitService.java | 16 +++++++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git
a/karavan-web/karavan-app/src/main/java/org/apache/camel/karavan/api/UsersResource.java
b/karavan-web/karavan-app/src/main/java/org/apache/camel/karavan/api/UsersResource.java
index fbf6e61e..83bd9469 100644
---
a/karavan-web/karavan-app/src/main/java/org/apache/camel/karavan/api/UsersResource.java
+++
b/karavan-web/karavan-app/src/main/java/org/apache/camel/karavan/api/UsersResource.java
@@ -17,6 +17,7 @@
package org.apache.camel.karavan.api;
+import io.quarkus.oidc.UserInfo;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
diff --git
a/karavan-web/karavan-app/src/main/java/org/apache/camel/karavan/git/GitService.java
b/karavan-web/karavan-app/src/main/java/org/apache/camel/karavan/git/GitService.java
index 098b79bd..010750a2 100644
---
a/karavan-web/karavan-app/src/main/java/org/apache/camel/karavan/git/GitService.java
+++
b/karavan-web/karavan-app/src/main/java/org/apache/camel/karavan/git/GitService.java
@@ -17,6 +17,8 @@
package org.apache.camel.karavan.git;
import io.fabric8.kubernetes.api.model.Secret;
+import io.quarkus.oidc.UserInfo;
+import io.quarkus.security.identity.SecurityIdentity;
import io.smallrye.mutiny.tuples.Tuple2;
import io.vertx.core.Vertx;
import jakarta.enterprise.context.ApplicationScoped;
@@ -34,6 +36,7 @@ import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.*;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -59,6 +62,9 @@ public class GitService {
@Inject
KubernetesService kubernetesService;
+ @Inject
+ SecurityIdentity securityIdentity;
+
private Git gitForImport;
private static final Logger LOGGER =
Logger.getLogger(GitService.class.getName());
@@ -305,13 +311,21 @@ public class GitService {
public RevCommit commitAddedAndPush(Git git, String branch,
CredentialsProvider cred, String message) throws GitAPIException {
LOGGER.info("Commit and push changes");
LOGGER.info("Git add: " + git.add().addFilepattern(".").call());
- RevCommit commit = git.commit().setMessage(message).call();
+ RevCommit commit =
git.commit().setMessage(message).setAuthor(getPersonIdent()).call();
LOGGER.info("Git commit: " + commit);
Iterable<PushResult> result =
git.push().add(branch).setRemote("origin").setCredentialsProvider(cred).call();
LOGGER.info("Git push: " + result);
return commit;
}
+ private PersonIdent getPersonIdent() {
+ if (securityIdentity != null &&
securityIdentity.getAttributes().get("userinfo") != null) {
+ UserInfo userInfo = (UserInfo)
securityIdentity.getAttributes().get("userinfo");
+ return new PersonIdent(securityIdentity.getPrincipal().getName(),
userInfo.getEmail());
+ }
+ return new PersonIdent("karavan", "[email protected]");
+ }
+
public Git init(String dir, String uri, String branch) throws
GitAPIException, IOException, URISyntaxException {
Git git =
Git.init().setInitialBranch(branch).setDirectory(Path.of(dir).toFile()).call();
// git.branchCreate().setName(branch).call();