From 20a676c8700c222e0397af6bc4f62adcaa5a0184 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Fri, 2 Sep 2016 03:51:19 +0200
Subject: get CBA api key from .netrc file


diff --git a/rhautoimport.pm b/rhautoimport.pm
index 1af005f..06a0acc 100644
--- a/rhautoimport.pm
+++ b/rhautoimport.pm
@@ -34,13 +34,13 @@ use RHRD::rddb;
 use RHRD::utils;
 use JSON::MaybeXS;
 use URI::QueryParam;
+use Net::Netrc;
 
 
 use constant {
   RD_USER => 'autoimport',
   RHIMPORTD_WATCH_DIR => '/run/rhimportd/watch',
   RHIMPORTD_TIMEOUT => 10,
-  CBA_API_KEY => '/etc/cba-api.key'
 };
 
 sub report_title_and_last
@@ -105,12 +105,11 @@ sub fetch_parse_rss_cba
   my ($url, $ua_str, $headers, $queries) = @_;
 
   my $api_key = undef;
-  if (open my $api_key_file, '<', CBA_API_KEY) {
-    $api_key =  <$api_key_file>;
-    close $api_key_file;
+  my $machine = Net::Netrc->lookup('cba');
+  if (defined $machine) {
+    $api_key = $machine->password();
   }
   if (defined $api_key) {
-    chomp $api_key;
     if (defined $queries) {
       $queries->{'c'} = $api_key;
     } else {
-- 
cgit v0.10.2