Пример #1
0
        /// <exception cref="System.IO.IOException"/>
        private void ReadTokensFromFiles(Configuration conf, Credentials credentials)
        {
            // add tokens and secrets coming from a token storage file
            string binaryTokenFilename = conf.Get("mapreduce.job.credentials.binary");

            if (binaryTokenFilename != null)
            {
                Credentials binary = Credentials.ReadTokenStorageFile(FileSystem.GetLocal(conf).MakeQualified
                                                                          (new Path(binaryTokenFilename)), conf);
                credentials.AddAll(binary);
            }
            // add secret keys coming from a json file
            string tokensFileName = conf.Get("mapreduce.job.credentials.json");

            if (tokensFileName != null)
            {
                Log.Info("loading user's secret keys from " + tokensFileName);
                string localFileName = new Path(tokensFileName).ToUri().GetPath();
                bool   json_error    = false;
                try
                {
                    // read JSON
                    ObjectMapper mapper             = new ObjectMapper();
                    IDictionary <string, string> nm = mapper.ReadValue <IDictionary>(new FilePath(localFileName
                                                                                                  ));
                    foreach (KeyValuePair <string, string> ent in nm)
                    {
                        credentials.AddSecretKey(new Text(ent.Key), Sharpen.Runtime.GetBytesForString(ent
                                                                                                      .Value, Charsets.Utf8));
                    }
                }
                catch (JsonMappingException)
                {
                    json_error = true;
                }
                catch (JsonParseException)
                {
                    json_error = true;
                }
                if (json_error)
                {
                    Log.Warn("couldn't parse Token Cache JSON file with user secret keys");
                }
            }
        }