Skip to content

Commit

Permalink
Merge pull request #10 from hanscgruber/bug/secretblock
Browse files Browse the repository at this point in the history
issue 9: override dump to obfuscate secretblock; add tests
  • Loading branch information
mahiki authored Nov 26, 2023
2 parents 6a19524 + 551035f commit 7cfc9ef
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/PrefectInterfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export AbstractPrefectInterface,
S3BucketBlock,
StringBlock,
SecretString,
SecretBlock,
CredentialPairBlock,
ls,
getblock,
Expand Down
19 changes: 8 additions & 11 deletions src/prefectblock/prefectblock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@ julia> spec_fsblock = LocalFSBlock("local-file-system/xanadu", "local-file-syste
julia> fsblock = PrefectBlock("local-file-system/xanadu", spec_fsblock);
julia> dump(fsblock)
PrefectBlock
blockname: String "local-file-system/xanadu"
block: LocalFSBlock
blockname: String "local-file-system/xanadu"
blocktype: String "local-file-system"
basepath: String "/usr/mahiki/xanadu/dev"
read_path: #4 (function of type PrefectInterfaces.var"#4#6"{String})
basepath: String "/usr/mahiki/xanadu/dev"
write_path: #5 (function of type PrefectInterfaces.var"#5#7"{String})
basepath: String "/usr/mahiki/xanadu/dev"
julia> fsblock.blockname
"local-file-system/xanadu"
julia> propertynames(fsblock.block)
(:blockname, :blocktype, :basepath, :read_path, :write_path)
julia> fsblock.block.basepath
"/usr/mahiki/xanadu/dev"
```
"""
struct PrefectBlock <: AbstractPrefectBlock
Expand Down
5 changes: 1 addition & 4 deletions src/prefectblock/prefectblocktypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct SecretString
secret::String
end
Base.show(io::IO, s::SecretString) = print(io, "####Secret####")
Base.dump(io::IO, s::SecretString; maxdepth=1) = print(io, "SecretString")
Base.dump(io::IOContext, s::SecretString, n::Int64, indent) = print(io, "SecretString")

struct SecretBlock <: AbstractPrefectBlock
blockname::String
Expand Down Expand Up @@ -101,7 +101,6 @@ struct CredentialPairBlock <: AbstractPrefectBlock
new(blockname, blocktype, id, SecretString(secret_key)
)
end
# TODO: Base.show, Base.dump override

struct S3BucketBlock <: AbstractPrefectBlock
blockname::String
Expand All @@ -117,5 +116,3 @@ struct S3BucketBlock <: AbstractPrefectBlock
)
# TODO: read_path/write_path function
end
# TODO: Base.show, Base.dump override, dump to show maxdepth 1, not working yet
Base.dump(io::IO, block::S3BucketBlock) = Base.dump(io::IO, block; maxdepth=1)
12 changes: 12 additions & 0 deletions test/prefectblock/prefectblocktypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ password = SecretString("abcd1234")
@test password.secret == "abcd1234"
@test repr(password) == "####Secret####"

secretblock = SecretBlock("secret", "necromancer", "abcd1234")
@test typeof(secretblock) == SecretBlock
@test repr(secretblock.value) == "####Secret####"
@test secretblock.value.secret == "abcd1234"
# make sure dump to stdout doesn't contain secret
tmp = tempname()
redirect_stdio(stdout=tmp) do
dump(secretblock)
end
result = read(tmp, String)
@test ! contains(result, "abcd1234")

awscredentials = AWSCredentialsBlock("aws-creds/signals", "aws-creds", "us-west-2"
, "AKIAXXXX1234XXXX1234", "GRU999999BOO")
@test typeof(awscredentials) == AWSCredentialsBlock
Expand Down

0 comments on commit 7cfc9ef

Please sign in to comment.