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

    https://github.com/apache/storm/pull/1191#discussion_r69239743
  
    --- 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)
    +                return (String)val;
    +        }
    +        return null;
    +    }
    +
    +    /**
          * Construct a principal to local plugin
          * @param storm_conf storm configuration
          * @return the plugin
          */
         public static IPrincipalToLocal GetPrincipalToLocalPlugin(Map 
storm_conf) {
             IPrincipalToLocal ptol;
             try {
    -          String ptol_klassName = (String) 
storm_conf.get(Config.STORM_PRINCIPAL_TO_LOCAL_PLUGIN);
    -          Class klass = Class.forName(ptol_klassName);
    -          ptol = (IPrincipalToLocal)klass.newInstance();
    -          ptol.prepare(storm_conf);
    +            String ptol_klassName = (String) 
storm_conf.get(Config.STORM_PRINCIPAL_TO_LOCAL_PLUGIN);
    --- End diff --
    
    I think we need to convert variable name to use camel case as well. But it 
should be corrected from whole code after porting is complete.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to