Skip to content

Commit

Permalink
Hide tower tokens from request object
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Jul 30, 2024
1 parent 3683bea commit 5b3d066
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions wave-api/src/main/java/io/seqera/wave/api/ObjectUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@ public static String toString(List list) {
return "(empty)";
return String.join(",",list);
}

static String redact(Object value) {
if( value==null )
return "(null)";
if( isEmpty(value.toString()) )
return ("(empty)");
final String str = value.toString();
return str.length()>=5 ? str.substring(0,3) + "****" : "****";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ public boolean formatSingularity() {
@Override
public String toString() {
return "SubmitContainerTokenRequest{" +
"towerAccessToken='" + towerAccessToken + '\'' +
", towerRefreshToken='" + towerRefreshToken + '\'' +
"towerAccessToken='" + ObjectUtils.redact(towerAccessToken) + '\'' +
", towerRefreshToken='" + ObjectUtils.redact(towerRefreshToken) + '\'' +
", towerEndpoint='" + towerEndpoint + '\'' +
", towerWorkspaceId=" + towerWorkspaceId +
", containerImage='" + containerImage + '\'' +
Expand Down
16 changes: 16 additions & 0 deletions wave-api/src/test/groovy/io/seqera/wave/api/ObjectUtilsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,20 @@ class ObjectUtilsTest extends Specification {
['1'] | '1'
['1','2','3'] | '1,2,3'
}

@Unroll
def 'should strip secret' () {
expect:
ObjectUtils.redact(SECRET) == EXPECTED

where:
SECRET | EXPECTED
'hi' | '****'
'Hello' | 'Hel****'
'World' | 'Wor****'
'12345678' | '123****'
'hola' | '****'
null | '(null)'
'' | '(empty)'
}
}

0 comments on commit 5b3d066

Please sign in to comment.