Skip to content

Commit e90eaa9

Browse files
authored
CHE-6730 Rename user token to machine token (eclipse-che#7036)
1 parent cd0f669 commit e90eaa9

15 files changed

Lines changed: 43 additions & 38 deletions

File tree

agents/git-credentials/src/main/resources/installers/1.0.0/org.eclipse.che.git.script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
SCRIPT_FILE=~/.ssh/git.sh
1313

14-
token=$(if [ "$USER_TOKEN" != "dummy_token" ]; then echo "$USER_TOKEN"; fi)
14+
token=$(if [ "$CHE_MACHINE_TOKEN" != "dummy_token" ]; then echo "$CHE_MACHINE_TOKEN"; fi)
1515
che_host=$(cat /etc/hosts | grep che-host | awk '{print $1;}')
1616
api_url=$(if [ "$CHE_API" != "http://che-host:8080/api" ]; then echo "$CHE_API"; else echo "$che_host:8080/api"; fi)
1717

agents/go-agents/bootstrapper/cfg/cfg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ func Parse() {
136136
log.Fatal("Push logs endpoint protocol must be either ws or wss")
137137
}
138138

139-
// auth-enabled - fetch USER_TOKEN
139+
// auth-enabled - fetch CHE_MACHINE_TOKEN
140140
if AuthEnabled {
141-
Token = os.Getenv("USER_TOKEN")
141+
Token = os.Getenv("CHE_MACHINE_TOKEN")
142142
}
143143

144144
// runtime-id

assembly-multiuser/assembly-wsagent-war/src/main/java/org/eclipse/che/wsagent/server/AgentHttpJsonRequestFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@
2020

2121
/**
2222
* Implementation of {@link org.eclipse.che.api.core.rest.HttpJsonRequestFactory} that add
23-
* ```user.token``` as authorization header. Used to make request from ws-agent to ws-master.
23+
* ```machine.token``` as authorization header. Used to make request from ws-agent to ws-master.
2424
*/
2525
@Singleton
2626
public class AgentHttpJsonRequestFactory extends DefaultHttpJsonRequestFactory {
2727

28-
private final String TOKEN;
28+
private final String machineToken;
2929

3030
@Inject
31-
public AgentHttpJsonRequestFactory(@Named("user.token") String token) {
32-
this.TOKEN = token;
31+
public AgentHttpJsonRequestFactory(@Named("machine.token") String machineToken) {
32+
this.machineToken = machineToken;
3333
}
3434

3535
@Override
3636
public HttpJsonRequest fromUrl(@NotNull String url) {
37-
return super.fromUrl(url).setAuthorizationHeader(TOKEN);
37+
return super.fromUrl(url).setAuthorizationHeader(machineToken);
3838
}
3939

4040
@Override
4141
public HttpJsonRequest fromLink(@NotNull Link link) {
42-
return super.fromLink(link).setAuthorizationHeader(TOKEN);
42+
return super.fromLink(link).setAuthorizationHeader(machineToken);
4343
}
4444
}

dashboard/src/app/diagnostics/test/diagnostics-workspace-start-check.factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class DiagnosticsWorkspaceStartCheck {
210210
this.cheWorkspace.fetchWorkspaceDetails(workspace.id).then(() => {
211211
let workspace = this.cheWorkspace.getWorkspaceById(workspaceId);
212212
diagnosticCallback.shared('workspace', workspace);
213-
diagnosticCallback.shared('machineToken', workspace.runtime.devMachine.runtime.envVariables['USER_TOKEN']);
213+
diagnosticCallback.shared('machineToken', workspace.runtime.devMachine.runtime.envVariables['CHE_MACHINE_TOKEN']);
214214
diagnosticCallback.success('Starting workspace OK');
215215
})
216216
});
@@ -255,7 +255,7 @@ export class DiagnosticsWorkspaceStartCheck {
255255
this.cheWorkspace.fetchWorkspaceDetails(workspace.id).then(() => {
256256
let workspace = this.cheWorkspace.getWorkspaceById(workspaceId);
257257
diagnosticCallback.shared('workspace', workspace);
258-
diagnosticCallback.shared('machineToken', workspace.runtime.devMachine.runtime.envVariables['USER_TOKEN']);
258+
diagnosticCallback.shared('machineToken', workspace.runtime.devMachine.runtime.envVariables['CHE_MACHINE_TOKEN']);
259259
let newCallback : DiagnosticCallback = diagnosticCallback.newCallback('Test connection from browser to workspace agent by using Workspace Agent IP');
260260
this.diagnosticsRunningWorkspaceCheck.checkWsAgent(newCallback, false);
261261
let websocketCallback : DiagnosticCallback = diagnosticCallback.newCallback('Test connection from browser to workspace agent with websocket');

infrastructures/docker/infrastructure/src/main/java/org/eclipse/che/workspace/infrastructure/docker/DockerMachine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public class DockerMachine implements Machine {
6868
*/
6969
public static final String CHE_HOST = "che-host";
7070

71-
/** Environment variable that will be setup in developer machine and contains user token. */
72-
public static final String USER_TOKEN = "USER_TOKEN";
71+
/** Environment variable that will be setup in developer machine and contains machine token. */
72+
public static final String CHE_MACHINE_TOKEN = "CHE_MACHINE_TOKEN";
7373

7474
private final String container;
7575
private final DockerConnector docker;

infrastructures/docker/infrastructure/src/main/java/org/eclipse/che/workspace/infrastructure/docker/provisioner/server/UserTokenEnvVarProvider.java renamed to infrastructures/docker/infrastructure/src/main/java/org/eclipse/che/workspace/infrastructure/docker/provisioner/server/MachineTokenEnvVarProvider.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
package org.eclipse.che.workspace.infrastructure.docker.provisioner.server;
1212

13-
import static org.eclipse.che.workspace.infrastructure.docker.DockerMachine.USER_TOKEN;
13+
import static org.eclipse.che.workspace.infrastructure.docker.DockerMachine.CHE_MACHINE_TOKEN;
1414

1515
import javax.inject.Inject;
1616
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
@@ -25,18 +25,19 @@
2525
* @author Alexander Garagatyi
2626
* @author Sergii Leshchenko
2727
*/
28-
public class UserTokenEnvVarProvider implements ServerEnvironmentVariableProvider {
28+
public class MachineTokenEnvVarProvider implements ServerEnvironmentVariableProvider {
2929
private final MachineTokenProvider machineTokenProvider;
3030

3131
@Inject
32-
public UserTokenEnvVarProvider(MachineTokenProvider machineTokenProvider) {
32+
public MachineTokenEnvVarProvider(MachineTokenProvider machineTokenProvider) {
3333
this.machineTokenProvider = machineTokenProvider;
3434
}
3535

3636
@Override
3737
public Pair<String, String> get(RuntimeIdentity runtimeIdentity) {
3838
try {
39-
return Pair.of(USER_TOKEN, machineTokenProvider.getToken(runtimeIdentity.getWorkspaceId()));
39+
return Pair.of(
40+
CHE_MACHINE_TOKEN, machineTokenProvider.getToken(runtimeIdentity.getWorkspaceId()));
4041
} catch (InfrastructureException e) {
4142
return null;
4243
}

infrastructures/docker/infrastructure/src/main/java/org/eclipse/che/workspace/infrastructure/docker/provisioner/server/ServersEnvVarsProvisioningModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected void configure() {
2323
mb.addBinding().to(JavaOptsEnvVariableProvider.class);
2424
mb.addBinding().to(MavenOptsEnvVariableProvider.class);
2525
mb.addBinding().to(ProjectsRootEnvVariableProvider.class);
26-
mb.addBinding().to(UserTokenEnvVarProvider.class);
26+
mb.addBinding().to(MachineTokenEnvVarProvider.class);
2727
mb.addBinding().to(WorkspaceIdEnvVarProvider.class);
2828
}
2929
}

infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/provision/installer/InstallerConfigProvisioner.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ public void provision(
5656
// CHE_API is used by installers for agent binary downloading
5757
config.getEnv().put("CHE_API", cheServerEndpoint);
5858

59-
config.getEnv().put("USER_TOKEN", machineTokenProvider.getToken(identity.getWorkspaceId()));
59+
config
60+
.getEnv()
61+
.put("CHE_MACHINE_TOKEN", machineTokenProvider.getToken(identity.getWorkspaceId()));
6062

6163
// TODO incorrect place for env variable addition. workspace ID is needed for wsagent
6264
// server, not installer

infrastructures/openshift/src/test/java/org/eclipse/che/workspace/infrastructure/openshift/provision/installer/InstallerConfigProvisionerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ public void provisionWithAgentsRequiredEnvs() throws Exception {
7979
// then
8080
Map<String, String> env = machine1.getEnv();
8181
verifyContainsEnv(env, "CHE_API", CHE_SERVER_ENDPOINT);
82-
verifyContainsEnv(env, "USER_TOKEN", "superToken");
82+
verifyContainsEnv(env, "CHE_MACHINE_TOKEN", "superToken");
8383
verifyContainsEnv(env, "CHE_WORKSPACE_ID", WORKSPACE_ID);
8484

8585
env = machine2.getEnv();
8686
verifyContainsEnv(env, "CHE_API", CHE_SERVER_ENDPOINT);
87-
verifyContainsEnv(env, "USER_TOKEN", "superToken");
87+
verifyContainsEnv(env, "CHE_MACHINE_TOKEN", "superToken");
8888
assertFalse(
8989
env.containsKey("CHE_WORKSPACE_ID"), "Environment variable '%s' found CHE_WORKSPACE_ID");
9090
}

wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/WorkspaceHolder.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class WorkspaceHolder extends WorkspaceProjectsSyncer {
4141

4242
private String workspaceId;
4343

44-
private final String userToken;
44+
private final String machineToken;
4545

4646
private HttpJsonRequestFactory httpJsonRequestFactory;
4747

@@ -54,11 +54,11 @@ public WorkspaceHolder(
5454
this.httpJsonRequestFactory = httpJsonRequestFactory;
5555

5656
this.workspaceId = System.getenv("CHE_WORKSPACE_ID");
57-
this.userToken = System.getenv("USER_TOKEN");
57+
this.machineToken = System.getenv("CHE_MACHINE_TOKEN");
5858

5959
LOG.info("Workspace ID: " + workspaceId);
6060
LOG.info("API Endpoint: " + apiEndpoint);
61-
LOG.info("User Token : " + (userToken != null));
61+
LOG.info("Machine Token : " + (machineToken != null));
6262

6363
// check connection
6464
try {
@@ -92,7 +92,7 @@ protected void addProject(ProjectConfig project) throws ServerException {
9292
UriBuilder.fromUri(apiEndpoint)
9393
.path(WorkspaceService.class)
9494
.path(WorkspaceService.class, "addProject");
95-
if (userToken != null) builder.queryParam("token", userToken);
95+
if (machineToken != null) builder.queryParam("token", machineToken);
9696
final String href = builder.build(workspaceId).toString();
9797
try {
9898
httpJsonRequestFactory.fromUrl(href).usePostMethod().setBody(asDto(project)).request();
@@ -113,7 +113,7 @@ protected void updateProject(ProjectConfig project) throws ServerException {
113113
UriBuilder.fromUri(apiEndpoint)
114114
.path(WorkspaceService.class)
115115
.path(WorkspaceService.class, "updateProject");
116-
if (userToken != null) builder.queryParam("token", userToken);
116+
if (machineToken != null) builder.queryParam("token", machineToken);
117117
final String href =
118118
builder.build(new String[] {workspaceId, project.getPath()}, false).toString();
119119
try {
@@ -129,7 +129,7 @@ protected void removeProject(ProjectConfig project) throws ServerException {
129129
UriBuilder.fromUri(apiEndpoint)
130130
.path(WorkspaceService.class)
131131
.path(WorkspaceService.class, "deleteProject");
132-
if (userToken != null) builder.queryParam("token", userToken);
132+
if (machineToken != null) builder.queryParam("token", machineToken);
133133
final String href =
134134
builder.build(new String[] {workspaceId, project.getPath()}, false).toString();
135135
try {
@@ -149,7 +149,7 @@ private WorkspaceDto workspaceDto() throws ServerException {
149149
UriBuilder.fromUri(apiEndpoint)
150150
.path(WorkspaceService.class)
151151
.path(WorkspaceService.class, "getByKey");
152-
if (userToken != null) builder.queryParam("token", userToken);
152+
if (machineToken != null) builder.queryParam("token", machineToken);
153153
final String href = builder.build(workspaceId).toString();
154154
try {
155155
return httpJsonRequestFactory

0 commit comments

Comments
 (0)