package com.perforce.workspace.tjuricek.p4oauth.storage; import com.perforce.workspace.tjuricek.p4oauth.config.P4OAuthConfig; import com.perforce.workspace.tjuricek.p4oauth.models.AuthorizationCode; import java.io.File; import java.io.IOException; import java.util.Optional; /** * Implements reading and writing various AuthorizationCodes. * <p> * Currently backed by the filesystem. */ public class AuthorizationCodeStore implements FilesystemStore { private P4OAuthConfig config; public AuthorizationCodeStore(P4OAuthConfig config) { this.config = config; } public Optional<AuthorizationCode> read(String code) throws IOException { File codePath = getCodeFile(code); if (codePath.exists()) { return Optional.of(readYamlFile(AuthorizationCode.class, codePath)); } else { return Optional.empty(); } } public void delete(String code) throws IOException { File codeFile = getCodeFile(code); if (codeFile.exists()) { codeFile.delete(); } } public void update(AuthorizationCode authCode) throws IOException { File codePath = getCodeFile(authCode.getAuthorizationCode()); ensureParentExists(codePath); writeYamlFile(authCode, codePath); } public File getCodeFile(String code) { return getFile("authorizations", code); } @Override public P4OAuthConfig getConfig() { return config; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 9095 | tjuricek | Added some basic test data and renamed "workspace" to "workshop" in package name | ||
#1 | 9089 | tjuricek |
Moving some code that worked via some manual validation to the workshop. This just implements a basic code authorization grant scheme. Automated tests are forthcoming, awating some gradle plugin work that should sit outside of this project. |