You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by HeartSaVioR <gi...@git.apache.org> on 2016/07/01 02:21:46 UTC

[GitHub] storm pull request #1191: STORM-1233: Port AuthUtilsTest to java

Github user HeartSaVioR commented on a diff in the pull request:

    https://github.com/apache/storm/pull/1191#discussion_r69239569
  
    --- Diff: storm-core/src/jvm/org/apache/storm/security/auth/AuthUtils.java ---
    @@ -81,48 +81,86 @@ public static Configuration GetConfiguration(Map storm_conf) {
         }
     
         /**
    -     * Pull a set of keys out of a Configuration.
    -     * @param conf The config to pull the key/value pairs out of.
    -     * @param conf_entry The app configuration entry name to get stuff from.
    -     * @return Return a map of the configs in conf.
    +     * Get configurations for a section
    +     * @param configuration The config to pull the key/value pairs out of.
    +     * @param section The app configuration entry name to get stuff from.
    +     * @return Return array of config entries or null if configuration is null
          */
    -    public static SortedMap<String, ?> PullConfig(Configuration conf,
    -                                            String conf_entry) throws IOException {
    -        if(conf == null) {
    +    public static AppConfigurationEntry[] getEntries(Configuration configuration, 
    +                                                String section) throws IOException {
    +        if (configuration == null) {
                 return null;
             }
    -        AppConfigurationEntry configurationEntries[] = conf.getAppConfigurationEntry(conf_entry);
    -        if(configurationEntries == null) {
    -            String errorMessage = "Could not find a '" + conf_entry
    -                + "' entry in this configuration: Client cannot start.";
    +
    +        AppConfigurationEntry configurationEntries[] = configuration.getAppConfigurationEntry(section);
    +        if (configurationEntries == null) {
    +            String errorMessage = "Could not find a '"+ section + "' entry in this configuration.";
                 throw new IOException(errorMessage);
             }
    +        return configurationEntries;
    +    }
     
    +    /**
    +     * Pull a set of keys out of a Configuration.
    +     * @param configuration The config to pull the key/value pairs out of.
    +     * @param section The app configuration entry name to get stuff from.
    +     * @return Return a map of the configs in conf.
    +     */
    +    public static SortedMap<String, ?> pullConfig(Configuration configuration,
    +                                            String section) throws IOException {
    +        AppConfigurationEntry[] configurationEntries = AuthUtils.getEntries(configuration, section);
    +
    +        if (configurationEntries == null) {
    +            return null;
    +        }
    +        
             TreeMap<String, Object> results = new TreeMap<>();
     
    -        for(AppConfigurationEntry entry: configurationEntries) {
    +        for (AppConfigurationEntry entry: configurationEntries) {
                 Map<String, ?> options = entry.getOptions();
    -            for(String key : options.keySet()) {
    +            for (String key : options.keySet()) {
                     results.put(key, options.get(key));
                 }
             }
    +
             return results;
         }
     
         /**
    +     * Pull a the value given section and key from Configuration
    +     * @param configuration The config to pull the key/value pairs out of.
    +     * @param section The app configuration entry name to get stuff from.
    +     * @param key The key to look up inside of the section
    +     * @return Return a the String value of the configuration value
    +     */
    +    public static String get(Configuration configuration, String section, String key) throws IOException {
    +        AppConfigurationEntry[] configurationEntries = AuthUtils.getEntries(configuration, section);
    +
    +        if (configurationEntries == null){
    +            return null;
    +        }
    +
    +        for (AppConfigurationEntry entry: configurationEntries) {
    +            Object val = entry.getOptions().get(key);
    +            if (val != null)
    --- End diff --
    
    Trivial: We're using bracket even though it is single line.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---