-
Notifications
You must be signed in to change notification settings - Fork 4
Unified, no more logic than dispatch in SecDispatcher, and is self-describable #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
711d5c4
Make Dispatchers and Sources self described
cstamas 7c4f27b
Reformat
cstamas 35e76ab
Dispatcher prevails
cstamas 6aac500
Reformat
cstamas eae95a3
Final touches
cstamas 8904363
Split meta and the thing
cstamas b02edda
Lazy!
cstamas 1bcbbc2
WIP
cstamas 90831d4
Add pinentry
cstamas 3c5a2c2
Fix scope
cstamas 4509688
Some slight improvements
cstamas 0aaf015
Simplify it more
cstamas 5a578bf
Move off from deprecated config
cstamas b5bd3a4
Make clear the intent
cstamas ce44581
Support legacy
cstamas 1cd393b
Finish up legacy
cstamas c523461
Add all attributes and shorten them
cstamas 433f8d4
Add "deep validation"
cstamas 98231b3
Dispatcher cares only about its own required attributes,
cstamas 945d2e6
Report is fallback possible
cstamas c32d618
Improve legacy report
cstamas ac0d93c
Fix validation on CI
cstamas 67f78ab
Tidy up messages
cstamas 5c1e252
Move out legacy, is independent
cstamas 69e3c31
Do not use single char attributes
cstamas 1ae037a
Tidy up
cstamas 56bcc6c
Sprinkle some javadoc
cstamas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/main/java/org/codehaus/plexus/components/secdispatcher/DispatcherMeta.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package org.codehaus.plexus.components.secdispatcher; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* Meta description of dispatcher. | ||
*/ | ||
public interface DispatcherMeta { | ||
final class Field { | ||
private final String key; | ||
private final boolean optional; | ||
private final String defaultValue; | ||
private final String description; | ||
private final List<Field> options; | ||
|
||
private Field(String key, boolean optional, String defaultValue, String description, List<Field> options) { | ||
this.key = requireNonNull(key); | ||
this.optional = optional; | ||
this.defaultValue = defaultValue; | ||
this.description = requireNonNull(description); | ||
this.options = options; | ||
} | ||
|
||
/** | ||
* The key to be used in configuration map for field. | ||
*/ | ||
public String getKey() { | ||
return key; | ||
} | ||
|
||
/** | ||
* Is configuration optional? | ||
*/ | ||
public boolean isOptional() { | ||
return optional; | ||
} | ||
|
||
/** | ||
* Optional default value of the configuration. | ||
*/ | ||
public Optional<String> getDefaultValue() { | ||
return Optional.ofNullable(defaultValue); | ||
} | ||
|
||
/** | ||
* The human description of the configuration. | ||
*/ | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
/** | ||
* Optional list of options, if this configuration accepts limited values. Each option is represented | ||
* as field, where {@link #getKey()} represents the value to be used, and {@link #displayName()} represents | ||
* the description of option. The {@link #getDefaultValue()}, if present represents the value to be used | ||
* instead of {@link #getKey()}. | ||
*/ | ||
public Optional<List<Field>> getOptions() { | ||
return Optional.ofNullable(options); | ||
} | ||
|
||
public static Builder builder(String key) { | ||
return new Builder(key); | ||
} | ||
|
||
public static final class Builder { | ||
private final String key; | ||
private boolean optional; | ||
private String defaultValue; | ||
private String description; | ||
private List<Field> options; | ||
|
||
private Builder(String key) { | ||
this.key = requireNonNull(key); | ||
} | ||
|
||
public Builder optional(boolean optional) { | ||
this.optional = optional; | ||
return this; | ||
} | ||
|
||
public Builder defaultValue(String defaultValue) { | ||
this.defaultValue = defaultValue; | ||
return this; | ||
} | ||
|
||
public Builder description(String description) { | ||
this.description = requireNonNull(description); | ||
return this; | ||
} | ||
|
||
public Builder options(List<Field> options) { | ||
this.options = requireNonNull(options); | ||
return this; | ||
} | ||
|
||
public Field build() { | ||
return new Field(key, optional, defaultValue, description, options); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Option to hide this instance from users, like for migration or legacy purposes. | ||
*/ | ||
default boolean isHidden() { | ||
return false; | ||
} | ||
|
||
/** | ||
* The name of the dispatcher. | ||
*/ | ||
String name(); | ||
|
||
/** | ||
* Returns the display (human) name of the dispatcher. | ||
*/ | ||
String displayName(); | ||
|
||
/** | ||
* Returns the configuration fields of the dispatcher. | ||
*/ | ||
Collection<Field> fields(); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/org/codehaus/plexus/components/secdispatcher/MasterSource.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2008 Sonatype, Inc. All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | ||
*/ | ||
|
||
package org.codehaus.plexus.components.secdispatcher; | ||
|
||
/** | ||
* Source of master password. | ||
*/ | ||
public interface MasterSource { | ||
/** | ||
* Handles the config to get master password. Implementation may do one of the following things: | ||
* <ul> | ||
* <li>if the config cannot be handled by given source, return {@code null}</li> | ||
* <li>otherwise, if master password retrieval based on config was attempted but failed, throw {@link SecDispatcherException}</li> | ||
* <li>happy path: return the master password.</li> | ||
* </ul> | ||
* | ||
* @param config the source of master password, and opaque string. | ||
* @return the master password, or {@code null} if implementation does not handle this config | ||
* @throws SecDispatcherException If implementation does handle this masterSource, but cannot obtain master password | ||
*/ | ||
String handle(String config) throws SecDispatcherException; | ||
|
||
/** | ||
* Validates master source configuration. | ||
* <ul> | ||
* <li>if the config cannot be handled by given source, return {@code null}</li> | ||
* <li>otherwise, implementation performs validation and returns non-{@code null} validation response</li> | ||
* </ul> | ||
*/ | ||
SecDispatcher.ValidationResponse validateConfiguration(String config); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.