CHE-6730 Rename user token to machine token (#7036)
parent
cd0f66942a
commit
e90eaa97fe
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
SCRIPT_FILE=~/.ssh/git.sh
|
||||
|
||||
token=$(if [ "$USER_TOKEN" != "dummy_token" ]; then echo "$USER_TOKEN"; fi)
|
||||
token=$(if [ "$CHE_MACHINE_TOKEN" != "dummy_token" ]; then echo "$CHE_MACHINE_TOKEN"; fi)
|
||||
che_host=$(cat /etc/hosts | grep che-host | awk '{print $1;}')
|
||||
api_url=$(if [ "$CHE_API" != "http://che-host:8080/api" ]; then echo "$CHE_API"; else echo "$che_host:8080/api"; fi)
|
||||
|
||||
|
|
|
|||
|
|
@ -136,9 +136,9 @@ func Parse() {
|
|||
log.Fatal("Push logs endpoint protocol must be either ws or wss")
|
||||
}
|
||||
|
||||
// auth-enabled - fetch USER_TOKEN
|
||||
// auth-enabled - fetch CHE_MACHINE_TOKEN
|
||||
if AuthEnabled {
|
||||
Token = os.Getenv("USER_TOKEN")
|
||||
Token = os.Getenv("CHE_MACHINE_TOKEN")
|
||||
}
|
||||
|
||||
// runtime-id
|
||||
|
|
|
|||
|
|
@ -20,25 +20,25 @@ import org.eclipse.che.api.core.rest.shared.dto.Link;
|
|||
|
||||
/**
|
||||
* Implementation of {@link org.eclipse.che.api.core.rest.HttpJsonRequestFactory} that add
|
||||
* ```user.token``` as authorization header. Used to make request from ws-agent to ws-master.
|
||||
* ```machine.token``` as authorization header. Used to make request from ws-agent to ws-master.
|
||||
*/
|
||||
@Singleton
|
||||
public class AgentHttpJsonRequestFactory extends DefaultHttpJsonRequestFactory {
|
||||
|
||||
private final String TOKEN;
|
||||
private final String machineToken;
|
||||
|
||||
@Inject
|
||||
public AgentHttpJsonRequestFactory(@Named("user.token") String token) {
|
||||
this.TOKEN = token;
|
||||
public AgentHttpJsonRequestFactory(@Named("machine.token") String machineToken) {
|
||||
this.machineToken = machineToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpJsonRequest fromUrl(@NotNull String url) {
|
||||
return super.fromUrl(url).setAuthorizationHeader(TOKEN);
|
||||
return super.fromUrl(url).setAuthorizationHeader(machineToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpJsonRequest fromLink(@NotNull Link link) {
|
||||
return super.fromLink(link).setAuthorizationHeader(TOKEN);
|
||||
return super.fromLink(link).setAuthorizationHeader(machineToken);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ export class DiagnosticsWorkspaceStartCheck {
|
|||
this.cheWorkspace.fetchWorkspaceDetails(workspace.id).then(() => {
|
||||
let workspace = this.cheWorkspace.getWorkspaceById(workspaceId);
|
||||
diagnosticCallback.shared('workspace', workspace);
|
||||
diagnosticCallback.shared('machineToken', workspace.runtime.devMachine.runtime.envVariables['USER_TOKEN']);
|
||||
diagnosticCallback.shared('machineToken', workspace.runtime.devMachine.runtime.envVariables['CHE_MACHINE_TOKEN']);
|
||||
diagnosticCallback.success('Starting workspace OK');
|
||||
})
|
||||
});
|
||||
|
|
@ -255,7 +255,7 @@ export class DiagnosticsWorkspaceStartCheck {
|
|||
this.cheWorkspace.fetchWorkspaceDetails(workspace.id).then(() => {
|
||||
let workspace = this.cheWorkspace.getWorkspaceById(workspaceId);
|
||||
diagnosticCallback.shared('workspace', workspace);
|
||||
diagnosticCallback.shared('machineToken', workspace.runtime.devMachine.runtime.envVariables['USER_TOKEN']);
|
||||
diagnosticCallback.shared('machineToken', workspace.runtime.devMachine.runtime.envVariables['CHE_MACHINE_TOKEN']);
|
||||
let newCallback : DiagnosticCallback = diagnosticCallback.newCallback('Test connection from browser to workspace agent by using Workspace Agent IP');
|
||||
this.diagnosticsRunningWorkspaceCheck.checkWsAgent(newCallback, false);
|
||||
let websocketCallback : DiagnosticCallback = diagnosticCallback.newCallback('Test connection from browser to workspace agent with websocket');
|
||||
|
|
|
|||
|
|
@ -68,8 +68,8 @@ public class DockerMachine implements Machine {
|
|||
*/
|
||||
public static final String CHE_HOST = "che-host";
|
||||
|
||||
/** Environment variable that will be setup in developer machine and contains user token. */
|
||||
public static final String USER_TOKEN = "USER_TOKEN";
|
||||
/** Environment variable that will be setup in developer machine and contains machine token. */
|
||||
public static final String CHE_MACHINE_TOKEN = "CHE_MACHINE_TOKEN";
|
||||
|
||||
private final String container;
|
||||
private final DockerConnector docker;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
package org.eclipse.che.workspace.infrastructure.docker.provisioner.server;
|
||||
|
||||
import static org.eclipse.che.workspace.infrastructure.docker.DockerMachine.USER_TOKEN;
|
||||
import static org.eclipse.che.workspace.infrastructure.docker.DockerMachine.CHE_MACHINE_TOKEN;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
|
||||
|
|
@ -25,18 +25,19 @@ import org.eclipse.che.commons.lang.Pair;
|
|||
* @author Alexander Garagatyi
|
||||
* @author Sergii Leshchenko
|
||||
*/
|
||||
public class UserTokenEnvVarProvider implements ServerEnvironmentVariableProvider {
|
||||
public class MachineTokenEnvVarProvider implements ServerEnvironmentVariableProvider {
|
||||
private final MachineTokenProvider machineTokenProvider;
|
||||
|
||||
@Inject
|
||||
public UserTokenEnvVarProvider(MachineTokenProvider machineTokenProvider) {
|
||||
public MachineTokenEnvVarProvider(MachineTokenProvider machineTokenProvider) {
|
||||
this.machineTokenProvider = machineTokenProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<String, String> get(RuntimeIdentity runtimeIdentity) {
|
||||
try {
|
||||
return Pair.of(USER_TOKEN, machineTokenProvider.getToken(runtimeIdentity.getWorkspaceId()));
|
||||
return Pair.of(
|
||||
CHE_MACHINE_TOKEN, machineTokenProvider.getToken(runtimeIdentity.getWorkspaceId()));
|
||||
} catch (InfrastructureException e) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ public class ServersEnvVarsProvisioningModule extends AbstractModule {
|
|||
mb.addBinding().to(JavaOptsEnvVariableProvider.class);
|
||||
mb.addBinding().to(MavenOptsEnvVariableProvider.class);
|
||||
mb.addBinding().to(ProjectsRootEnvVariableProvider.class);
|
||||
mb.addBinding().to(UserTokenEnvVarProvider.class);
|
||||
mb.addBinding().to(MachineTokenEnvVarProvider.class);
|
||||
mb.addBinding().to(WorkspaceIdEnvVarProvider.class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,9 @@ public class InstallerConfigProvisioner implements ConfigurationProvisioner {
|
|||
// CHE_API is used by installers for agent binary downloading
|
||||
config.getEnv().put("CHE_API", cheServerEndpoint);
|
||||
|
||||
config.getEnv().put("USER_TOKEN", machineTokenProvider.getToken(identity.getWorkspaceId()));
|
||||
config
|
||||
.getEnv()
|
||||
.put("CHE_MACHINE_TOKEN", machineTokenProvider.getToken(identity.getWorkspaceId()));
|
||||
|
||||
// TODO incorrect place for env variable addition. workspace ID is needed for wsagent
|
||||
// server, not installer
|
||||
|
|
|
|||
|
|
@ -79,12 +79,12 @@ public class InstallerConfigProvisionerTest {
|
|||
// then
|
||||
Map<String, String> env = machine1.getEnv();
|
||||
verifyContainsEnv(env, "CHE_API", CHE_SERVER_ENDPOINT);
|
||||
verifyContainsEnv(env, "USER_TOKEN", "superToken");
|
||||
verifyContainsEnv(env, "CHE_MACHINE_TOKEN", "superToken");
|
||||
verifyContainsEnv(env, "CHE_WORKSPACE_ID", WORKSPACE_ID);
|
||||
|
||||
env = machine2.getEnv();
|
||||
verifyContainsEnv(env, "CHE_API", CHE_SERVER_ENDPOINT);
|
||||
verifyContainsEnv(env, "USER_TOKEN", "superToken");
|
||||
verifyContainsEnv(env, "CHE_MACHINE_TOKEN", "superToken");
|
||||
assertFalse(
|
||||
env.containsKey("CHE_WORKSPACE_ID"), "Environment variable '%s' found CHE_WORKSPACE_ID");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class WorkspaceHolder extends WorkspaceProjectsSyncer {
|
|||
|
||||
private String workspaceId;
|
||||
|
||||
private final String userToken;
|
||||
private final String machineToken;
|
||||
|
||||
private HttpJsonRequestFactory httpJsonRequestFactory;
|
||||
|
||||
|
|
@ -54,11 +54,11 @@ public class WorkspaceHolder extends WorkspaceProjectsSyncer {
|
|||
this.httpJsonRequestFactory = httpJsonRequestFactory;
|
||||
|
||||
this.workspaceId = System.getenv("CHE_WORKSPACE_ID");
|
||||
this.userToken = System.getenv("USER_TOKEN");
|
||||
this.machineToken = System.getenv("CHE_MACHINE_TOKEN");
|
||||
|
||||
LOG.info("Workspace ID: " + workspaceId);
|
||||
LOG.info("API Endpoint: " + apiEndpoint);
|
||||
LOG.info("User Token : " + (userToken != null));
|
||||
LOG.info("Machine Token : " + (machineToken != null));
|
||||
|
||||
// check connection
|
||||
try {
|
||||
|
|
@ -92,7 +92,7 @@ public class WorkspaceHolder extends WorkspaceProjectsSyncer {
|
|||
UriBuilder.fromUri(apiEndpoint)
|
||||
.path(WorkspaceService.class)
|
||||
.path(WorkspaceService.class, "addProject");
|
||||
if (userToken != null) builder.queryParam("token", userToken);
|
||||
if (machineToken != null) builder.queryParam("token", machineToken);
|
||||
final String href = builder.build(workspaceId).toString();
|
||||
try {
|
||||
httpJsonRequestFactory.fromUrl(href).usePostMethod().setBody(asDto(project)).request();
|
||||
|
|
@ -113,7 +113,7 @@ public class WorkspaceHolder extends WorkspaceProjectsSyncer {
|
|||
UriBuilder.fromUri(apiEndpoint)
|
||||
.path(WorkspaceService.class)
|
||||
.path(WorkspaceService.class, "updateProject");
|
||||
if (userToken != null) builder.queryParam("token", userToken);
|
||||
if (machineToken != null) builder.queryParam("token", machineToken);
|
||||
final String href =
|
||||
builder.build(new String[] {workspaceId, project.getPath()}, false).toString();
|
||||
try {
|
||||
|
|
@ -129,7 +129,7 @@ public class WorkspaceHolder extends WorkspaceProjectsSyncer {
|
|||
UriBuilder.fromUri(apiEndpoint)
|
||||
.path(WorkspaceService.class)
|
||||
.path(WorkspaceService.class, "deleteProject");
|
||||
if (userToken != null) builder.queryParam("token", userToken);
|
||||
if (machineToken != null) builder.queryParam("token", machineToken);
|
||||
final String href =
|
||||
builder.build(new String[] {workspaceId, project.getPath()}, false).toString();
|
||||
try {
|
||||
|
|
@ -149,7 +149,7 @@ public class WorkspaceHolder extends WorkspaceProjectsSyncer {
|
|||
UriBuilder.fromUri(apiEndpoint)
|
||||
.path(WorkspaceService.class)
|
||||
.path(WorkspaceService.class, "getByKey");
|
||||
if (userToken != null) builder.queryParam("token", userToken);
|
||||
if (machineToken != null) builder.queryParam("token", machineToken);
|
||||
final String href = builder.build(workspaceId).toString();
|
||||
try {
|
||||
return httpJsonRequestFactory
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ package org.eclipse.che.wsagent.server;
|
|||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.name.Names;
|
||||
import java.net.URI;
|
||||
import org.eclipse.che.MachineTokenProvider;
|
||||
import org.eclipse.che.UriApiEndpointProvider;
|
||||
import org.eclipse.che.UserTokenProvider;
|
||||
import org.eclipse.che.inject.DynaModule;
|
||||
|
||||
/**
|
||||
|
|
@ -27,7 +27,9 @@ public class CheWsAgentModule extends AbstractModule {
|
|||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(Names.named("che.api")).toProvider(UriApiEndpointProvider.class);
|
||||
bind(String.class).annotatedWith(Names.named("user.token")).toProvider(UserTokenProvider.class);
|
||||
bind(String.class)
|
||||
.annotatedWith(Names.named("machine.token"))
|
||||
.toProvider(MachineTokenProvider.class);
|
||||
|
||||
bind(WsAgentAnalyticsAddresser.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ import static com.google.common.base.Strings.nullToEmpty;
|
|||
import com.google.inject.Provider;
|
||||
|
||||
/** @author Anton Korneta */
|
||||
public class UserTokenProvider implements Provider<String> {
|
||||
public class MachineTokenProvider implements Provider<String> {
|
||||
|
||||
public static final String USER_TOKEN = "USER_TOKEN";
|
||||
public static final String CHE_MACHINE_TOKEN = "CHE_MACHINE_TOKEN";
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return nullToEmpty(System.getenv(USER_TOKEN));
|
||||
return nullToEmpty(System.getenv(CHE_MACHINE_TOKEN));
|
||||
}
|
||||
}
|
||||
|
|
@ -40,11 +40,11 @@ public interface RuntimeDto extends Runtime, Hyperlinks {
|
|||
|
||||
RuntimeDto withOwner(String owner);
|
||||
|
||||
String getUserToken();
|
||||
String getMachineToken();
|
||||
|
||||
RuntimeDto withUserToken(String userToken);
|
||||
RuntimeDto withMachineToken(String machineToken);
|
||||
|
||||
void setUserToken(String userToken);
|
||||
void setMachineToken(String machineToken);
|
||||
|
||||
@Override
|
||||
List<WarningDto> getWarnings();
|
||||
|
|
|
|||
|
|
@ -798,7 +798,7 @@ public class WorkspaceService extends Service {
|
|||
RuntimeDto runtimeDto = workspaceDto.getRuntime();
|
||||
if (runtimeDto != null) {
|
||||
try {
|
||||
runtimeDto.setUserToken(machineTokenProvider.getToken(workspace.getId()));
|
||||
runtimeDto.setMachineToken(machineTokenProvider.getToken(workspace.getId()));
|
||||
} catch (MachineTokenException e) {
|
||||
throw new ServerException(e.getMessage(), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ public class WorkspaceServiceTest {
|
|||
|
||||
assertEquals(response.getStatusCode(), 200);
|
||||
WorkspaceDto retrievedWorkspace = unwrapDto(response, WorkspaceDto.class);
|
||||
assertEquals(retrievedWorkspace.getRuntime().getUserToken(), "superToken");
|
||||
assertEquals(retrievedWorkspace.getRuntime().getMachineToken(), "superToken");
|
||||
verify(machineTokenProvider).getToken(workspace.getId());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue