-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
CHE-5169: Add Git configuration agent #5285
Changes from 9 commits
fb587a7
2539b5c
c0344fd
2b9383c
2569b5a
0f7f402
e4b79da
6a9c3df
7b6cdeb
9163567
3d5cb2d
a615011
ecb3e86
6f4767c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
|
||
Copyright (c) 2012-2017 Codenvy, S.A. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
|
||
Contributors: | ||
Codenvy, S.A. - initial API and implementation | ||
|
||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>che-agents-parent</artifactId> | ||
<groupId>org.eclipse.che</groupId> | ||
<version>5.12.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>git-credentials-agent</artifactId> | ||
<name>Git Agent</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.inject</groupId> | ||
<artifactId>guice</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-api-agent-shared</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2017 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.api.agent; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
|
||
import org.eclipse.che.api.agent.shared.model.Agent; | ||
import org.eclipse.che.api.agent.shared.model.impl.BasicAgent; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Git credentials agent. | ||
* Creates sh script that retrieves SSH keys from user preferences for console Git SSH operations. | ||
* Injects Git username and email from user preferences to console Git preferences. | ||
* | ||
* @see Agent | ||
* | ||
* @author Igor Vinokur | ||
*/ | ||
@Singleton | ||
public class GitCredentialsAgent extends BasicAgent { | ||
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.git.json"; | ||
private static final String AGENT_SCRIPT = "org.eclipse.che.git.script.sh"; | ||
|
||
@Inject | ||
public GitCredentialsAgent() throws IOException { | ||
super(AGENT_DESCRIPTOR, AGENT_SCRIPT); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": "org.eclipse.che.git", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
"name": "Git-Credentials-Agent", | ||
"description": "Agent fetches SSH keys, Git username and email from CHE user preferences, and injects to console Git" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# | ||
# Copyright (c) 2012-2017 Codenvy, S.A. | ||
# All rights reserved. This program and the accompanying materials | ||
# are made available under the terms of the Eclipse Public License v1.0 | ||
# which accompanies this distribution, and is available at | ||
# http://www.eclipse.org/legal/epl-v10.html | ||
# | ||
# Contributors: | ||
# Codenvy, S.A. - initial API and implementation | ||
# | ||
|
||
SCRIPT_FILE=~/.ssh/git.sh | ||
|
||
token=$(if [ "$USER_TOKEN" != "dummy_token" ]; then echo "$USER_TOKEN"; fi) | ||
che_host=$(cat /etc/hosts | grep che-host | awk '{print $1;}') | ||
api_url=$(if [ "$CHE_API" != "http://che-host:8080/wsmaster/api" ]; then echo "$CHE_API"; else echo "$che_host:8080/api"; fi) | ||
|
||
CURL_INSTALLED=false | ||
WGET_INSTALLED=false | ||
command -v curl >/dev/null 2>&1 && CURL_INSTALLED=true | ||
command -v wget >/dev/null 2>&1 && WGET_INSTALLED=true | ||
|
||
# no curl, no wget, install curl | ||
if [ ${CURL_INSTALLED} = false ] && [ ${WGET_INSTALLED} = false ]; then | ||
PACKAGES=${PACKAGES}" curl"; | ||
CURL_INSTALLED=true | ||
fi | ||
|
||
request=$(if ${CURL_INSTALLED}; then echo 'curl -s'; else echo 'wget -qO-'; fi) | ||
|
||
echo 'host=$(echo $(if [ "$1" = "-p" ]; then echo "$3" ; else echo "$1"; fi) | sed -e "s/git@//")' > ${SCRIPT_FILE} | ||
echo 'token='"$token" >> ${SCRIPT_FILE} | ||
echo 'api_url='"$api_url" >> ${SCRIPT_FILE} | ||
echo 'request="'${request}'"' >> ${SCRIPT_FILE} | ||
# Ssh key request may return key with decoded '=' symbol, so need to replace '\u003d' to '='. | ||
# TODO remove the replacement after https://github.com/eclipse/che/issues/5253 will be fixed. | ||
echo 'ssh_key=$(${request} "$api_url/ssh/vcs/find?name=$host$(if [ -n "$token" ]; then echo "&token=$token"; fi)"| grep -Po '\''"privateKey":.*?[^\\\\]",'\''| sed -e "s/\"privateKey\":\"//" | sed -e "s/\\\\\u003d/=/")' >> ${SCRIPT_FILE} | ||
echo 'if [ -n "$ssh_key" ]' >> ${SCRIPT_FILE} | ||
echo 'then' >> ${SCRIPT_FILE} | ||
echo ' key_file=$(mktemp)' >> ${SCRIPT_FILE} | ||
echo ' echo "$ssh_key" > "$key_file"' >> ${SCRIPT_FILE} | ||
echo ' ssh -i "$key_file" "$@"' >> ${SCRIPT_FILE} | ||
echo ' rm "$key_file"' >> ${SCRIPT_FILE} | ||
echo 'else' >> ${SCRIPT_FILE} | ||
echo ' ssh "$@"' >> ${SCRIPT_FILE} | ||
echo 'fi' >> ${SCRIPT_FILE} | ||
|
||
chmod +x ${SCRIPT_FILE} | ||
|
||
user_name="$(${request} "$api_url/preferences$(if [ -n "$token" ]; then echo "?token=$token"; fi)" | grep -Po '"git.committer.name":.*?[^\\]",' | sed -e "s/\"git.committer.name\":\"//" | sed -e "s/\",//")" | ||
user_email="$(${request} "$api_url/preferences$(if [ -n "$token" ]; then echo "?token=$token"; fi)" | grep -Po '"git.committer.email":.*?[^\\]",' | sed -e "s/\"git.committer.email\":\"//" | sed -e "s/\",//")" | ||
git config --global user.name \""$user_name"\" | ||
git config --global user.email \""$user_email"\" | ||
|
||
if [ -z "$(cat ~/.bashrc | grep GIT_SSH)" ] | ||
then | ||
printf '\n export GIT_SSH='"$SCRIPT_FILE" >> ~/.bashrc | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
<module>che-core-api-agent-shared</module> | ||
<module>che-core-api-agent</module> | ||
<module>ls-json</module> | ||
<module>git</module> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. git-credentials There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
<module>ls-php</module> | ||
<module>ls-python</module> | ||
<module>ls-typescript</module> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix name accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done