Skip to content

Commit

Permalink
#2379 fixed jwt token requesting problem
Browse files Browse the repository at this point in the history
  • Loading branch information
tjamakeev committed Apr 10, 2018
1 parent 8b82d3e commit 02fc9db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,6 @@ void placeEnvironmentInfoByContainerId( String environmentId, String containerIp

Environment getEnvironment( String environmentId );

/**
* Places JWT token to container
*
* @param environmentId environment ID
* @param containerIp container IP
* @param token JWT token
*/
void placeTokenToContainer( String environmentId, String containerIp, String token )
throws EnvironmentNotFoundException, ContainerHostNotFoundException, CommandException;

/**
* Creates template on Hub ( Global Kurjun ) out of a specified environment container
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2763,25 +2763,6 @@ public Environment getEnvironment( String environmentId )
}


@Override
public void placeTokenToContainer( String environmentId, String containerIp, String token )
throws EnvironmentNotFoundException, ContainerHostNotFoundException, CommandException
{
final LocalEnvironment environment = environmentService.find( environmentId );

if ( environment == null )
{
throw new EnvironmentNotFoundException();
}

EnvironmentContainerImpl containerHost =
( EnvironmentContainerImpl ) environment.getContainerHostByIp( containerIp );
setTransientFields( Sets.<Environment>newHashSet( environment ) );

placeTokenIntoContainer( containerHost, token );
}


//called by remote peer
@Override
public void placeEnvironmentInfoByContainerId( final String environmentId, final String containerId )
Expand Down Expand Up @@ -2827,22 +2808,6 @@ private void placeInfoIntoContainer( EnvironmentDto environmentDto, ContainerHos
}


private void placeTokenIntoContainer( ContainerHost containerHost, String token ) throws CommandException
{
if ( containerHost instanceof EnvironmentContainerImpl )
{
// workaround to disable security checks for this call
( ( EnvironmentContainerImpl ) containerHost ).executeUnsafe( new RequestBuilder(
String.format( "mkdir -p /etc/subutai/ ; echo '%s' > /etc/subutai/jwttoken", token ) ) );
}
else
{
containerHost.execute( new RequestBuilder(
String.format( "mkdir -p /etc/subutai/ ; echo '%s' > /etc/subutai/jwttoken", token ) ) );
}
}


public void cleanupEnvironment( EnvironmentId environmentId )
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;

import io.subutai.common.command.CommandException;
import io.subutai.common.command.RequestBuilder;
import io.subutai.common.environment.Environment;
import io.subutai.common.environment.EnvironmentNotFoundException;
import io.subutai.common.peer.ContainerHost;
import io.subutai.common.peer.HostNotFoundException;
import io.subutai.core.environment.api.EnvironmentManager;
Expand Down Expand Up @@ -64,9 +64,11 @@ public void issueToken( String containerIp ) throws TokenCreateException
String peerId = container.getPeerId();
String origin = String.format( "%s.%s.%s", peerId, containerId, environmentId );
final String token = identityManager.issueJWTToken( origin );
environmentManager.placeTokenToContainer( environmentId, containerIp, token );
// environmentManager.placeTokenToContainer( environmentId, containerIp, token );

placeTokenIntoContainer( container, token );
}
catch ( HostNotFoundException | EnvironmentNotFoundException | CommandException e )
catch ( HostNotFoundException | CommandException e )
{
throw new TokenCreateException( e.getMessage() );
}
Expand Down Expand Up @@ -99,5 +101,12 @@ public void pushEvent( final Event event )
}
// TODO: send event to consumers
}


private void placeTokenIntoContainer( ContainerHost containerHost, String token ) throws CommandException
{
containerHost.executeAsync( new RequestBuilder(
String.format( "mkdir -p /etc/subutai/ ; echo '%s' > /etc/subutai/jwttoken", token ) ) );
}
}

0 comments on commit 02fc9db

Please sign in to comment.