CC-2566: Separate URL config out of config files and put them with API_CLIENT

-fixed
This commit is contained in:
martin 2011-07-19 19:35:39 -04:00
parent 19a549df12
commit 6205b30152
9 changed files with 132 additions and 146 deletions

View file

@ -202,9 +202,7 @@ class AirtimeIni
$api_key = AirtimeIni::GenerateRandomString(); $api_key = AirtimeIni::GenerateRandomString();
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_AIRTIME, 'api_key', $api_key); AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_AIRTIME, 'api_key', $api_key);
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_AIRTIME, 'airtime_dir', AirtimeInstall::CONF_DIR_WWW); AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_AIRTIME, 'airtime_dir', AirtimeInstall::CONF_DIR_WWW);
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_PYPO, 'api_key', "'$api_key'"); AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_API_CLIENT, 'api_key', "'$api_key'");
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_RECORDER, 'api_key', "'$api_key'");
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_MEDIAMONITOR, 'api_key', "'$api_key'");
} }
public static function ReadPythonConfig($p_filename) public static function ReadPythonConfig($p_filename)

View file

@ -568,8 +568,6 @@ class Airtime190Upgrade{
echo "Could not copy media-monitor.cfg to /etc/airtime/. Exiting."; echo "Could not copy media-monitor.cfg to /etc/airtime/. Exiting.";
} }
AirtimeIni::UpdateIniValue(AirtimeIni::CONF_FILE_MEDIAMONITOR, "api_key", $values["general"]["api_key"]);
echo "Reorganizing files in stor directory".PHP_EOL; echo "Reorganizing files in stor directory".PHP_EOL;
$cwd = __DIR__; $cwd = __DIR__;

View file

@ -1 +1,110 @@
bin_dir = "/usr/lib/airtime/api_clients" bin_dir = "/usr/lib/airtime/api_clients"
#############################
## Common
#############################
# Value needed to access the API
api_key = 'AAA'
# Path to the base of the API
api_base = 'api'
# URL to get the version number of the server API
version_url = 'version/api_key/%%api_key%%'
# Hostname
base_url = 'localhost'
base_port = 80
#############################
## Config for Media Monitor
#############################
# URL to setup the media monitor
media_setup_url = 'media-monitor-setup/format/json/api_key/%%api_key%%'
# Tell Airtime the file id associated with a show instance.
upload_recorded = 'upload-recorded/format/json/api_key/%%api_key%%/fileid/%%fileid%%/showinstanceid/%%showinstanceid%%'
# URL to tell Airtime to update file's meta data
update_media_url = 'reload-metadata/format/json/api_key/%%api_key%%/mode/%%mode%%'
# URL to tell Airtime we want a listing of all files it knows about
list_all_db_files = 'list-all-files/format/json/api_key/%%api_key%%/dir_id/%%dir_id%%'
# URL to tell Airtime we want a listing of all dirs its watching (including the stor dir)
list_all_watched_dirs = 'list-all-watched-dirs/format/json/api_key/%%api_key%%'
# URL to tell Airtime we want to add watched directory
add_watched_dir = 'add-watched-dir/format/json/api_key/%%api_key%%/path/%%path%%'
# URL to tell Airtime we want to add watched directory
remove_watched_dir = 'remove-watched-dir/format/json/api_key/%%api_key%%/path/%%path%%'
# URL to tell Airtime we want to add watched directory
set_storage_dir = 'set-storage-dir/format/json/api_key/%%api_key%%/path/%%path%%'
#############################
## Config for Recorder
#############################
# URL to get the schedule of shows set to record
show_schedule_url = 'recorded-shows/format/json/api_key/%%api_key%%'
# URL to upload the recorded show's file to Airtime
upload_file_url = 'upload-file/format/json/api_key/%%api_key%%'
#number of retries to upload file if connection problem
upload_retries = 3
#time to wait between attempts to upload file if connection problem (in seconds)
upload_wait = 60
################################################################################
# Uncomment *one of the sets* of values from the API clients below, and comment
# out all the others.
################################################################################
#############################
## Config for Pypo
#############################
# Schedule export path.
# %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm
# %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm
export_url = 'schedule/api_key/%%api_key%%'
get_media_url = 'get-media/file/%%file%%/api_key/%%api_key%%'
# Update whether a schedule group has begun playing.
update_item_url = 'notify-schedule-group-play/api_key/%%api_key%%/schedule_id/%%schedule_id%%'
# Update whether an audio clip is currently playing.
update_start_playing_url = 'notify-media-item-start-play/api_key/%%api_key%%/media_id/%%media_id%%/schedule_id/%%schedule_id%%'
# ???
generate_range_url = 'generate_range_dp.php'
##############
# OBP config #
##############
# URL to get the version number of the server API
#version_url = 'api/pypo/status/json'
# Schedule export path.
# %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm
# %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm
# Update whether an item has been played.
#update_item_url = 'api/pypo/update_shedueled_item/$$item_id%%?played=%%played%%'
# Update whether an item is currently playing.
#update_start_playing_url = 'api/pypo/mod/medialibrary/?playlist_type=%%playlist_type%%&export_source=%%export_source%%&media_id=%%media_id%%&playlist_id=%%playlist_id%%&transmission_id=%%transmission_id%%'
# ???
#generate_range_url = 'api/pypo/generate_range_dp/'

View file

@ -19,15 +19,16 @@ import json
import os import os
from urlparse import urlparse from urlparse import urlparse
import base64 import base64
from configobj import ConfigObj
AIRTIME_VERSION = "1.9.0-devel" AIRTIME_VERSION = "1.9.0-devel"
def api_client_factory(config): def api_client_factory(config):
logger = logging.getLogger() logger = logging.getLogger()
if config["api_client"] == "airtime": if config["api_client"] == "airtime":
return AirTimeApiClient(config) return AirTimeApiClient()
elif config["api_client"] == "obp": elif config["api_client"] == "obp":
return ObpApiClient(config) return ObpApiClient()
else: else:
logger.info('API Client "'+config["api_client"]+'" not supported. Please check your config file.\n') logger.info('API Client "'+config["api_client"]+'" not supported. Please check your config file.\n')
sys.exit() sys.exit()
@ -135,8 +136,14 @@ class ApiClientInterface:
class AirTimeApiClient(ApiClientInterface): class AirTimeApiClient(ApiClientInterface):
def __init__(self, config): def __init__(self):
self.config = config # loading config file
try:
self.config = ConfigObj('/etc/airtime/api_client.cfg')
except Exception, e:
logger = logging.getLogger()
logger.error('Error loading config file: %s', e)
sys.exit(1)
def __get_airtime_version(self, verbose = True): def __get_airtime_version(self, verbose = True):
logger = logging.getLogger() logger = logging.getLogger()

View file

@ -105,6 +105,8 @@ class AirtimeMediaMonitorBootstrap():
new_files_set = all_files_set - db_known_files_set new_files_set = all_files_set - db_known_files_set
modified_files_set = new_and_modified_files - new_files_set modified_files_set = new_and_modified_files - new_files_set
#NAOMI: Please comment out the "Known files" line, if you find the bug.
#it is for debugging purposes only (Too much data will be written to log). -mk
self.logger.info("Known files: \n%s\n\n"%db_known_files_set) self.logger.info("Known files: \n%s\n\n"%db_known_files_set)
self.logger.info("Deleted files: \n%s\n\n"%deleted_files_set) self.logger.info("Deleted files: \n%s\n\n"%deleted_files_set)
self.logger.info("New files: \n%s\n\n"%new_files_set) self.logger.info("New files: \n%s\n\n"%new_files_set)

View file

@ -1,47 +1,11 @@
api_client = "airtime" api_client = "airtime"
# Hostname
base_url = 'localhost'
base_port = 80
# where the binary files live # where the binary files live
bin_dir = '/usr/lib/airtime/media-monitor' bin_dir = '/usr/lib/airtime/media-monitor'
# where the logging files live # where the logging files live
log_dir = '/var/log/airtime/media-monitor' log_dir = '/var/log/airtime/media-monitor'
# Value needed to access the API
api_key = 'AAA'
# Path to the base of the API
api_base = 'api'
# URL to get the version number of the server API
version_url = 'version/api_key/%%api_key%%'
# URL to setup the media monitor
media_setup_url = 'media-monitor-setup/format/json/api_key/%%api_key%%'
# Tell Airtime the file id associated with a show instance.
upload_recorded = 'upload-recorded/format/json/api_key/%%api_key%%/fileid/%%fileid%%/showinstanceid/%%showinstanceid%%'
# URL to tell Airtime to update file's meta data
update_media_url = 'reload-metadata/format/json/api_key/%%api_key%%/mode/%%mode%%'
# URL to tell Airtime we want a listing of all files it knows about
list_all_db_files = 'list-all-files/format/json/api_key/%%api_key%%/dir_id/%%dir_id%%'
# URL to tell Airtime we want a listing of all dirs its watching (including the stor dir)
list_all_watched_dirs = 'list-all-watched-dirs/format/json/api_key/%%api_key%%'
# URL to tell Airtime we want to add watched directory
add_watched_dir = 'add-watched-dir/format/json/api_key/%%api_key%%/path/%%path%%'
# URL to tell Airtime we want to add watched directory
remove_watched_dir = 'remove-watched-dir/format/json/api_key/%%api_key%%/path/%%path%%'
# URL to tell Airtime we want to add watched directory
set_storage_dir = 'set-storage-dir/format/json/api_key/%%api_key%%/path/%%path%%'
############################################ ############################################
# RabbitMQ settings # # RabbitMQ settings #

View file

@ -27,10 +27,6 @@ log_base_dir = '/var/log/airtime'
pypo_log_dir = '/var/log/airtime/pypo' pypo_log_dir = '/var/log/airtime/pypo'
liquidsoap_log_dir = '/var/log/airtime/pypo-liquidsoap' liquidsoap_log_dir = '/var/log/airtime/pypo-liquidsoap'
# Hostname
base_url = 'localhost'
base_port = 80
############################################ ############################################
# Liquidsoap settings # # Liquidsoap settings #
############################################ ############################################
@ -74,66 +70,3 @@ push_interval = 1 # in seconds
# while 'otf' (on the fly) cues while loading into ls # while 'otf' (on the fly) cues while loading into ls
# (needs the post_processor patch) # (needs the post_processor patch)
cue_style = 'pre' cue_style = 'pre'
################################################################################
# Uncomment *one of the sets* of values from the API clients below, and comment
# out all the others.
################################################################################
#####################
# Airtime Config #
#####################
# Value needed to access the API
api_key = 'AAA'
# Path to the base of the API
api_base = 'api'
# URL to get the version number of the server API
version_url = 'version/api_key/%%api_key%%'
# Schedule export path.
# %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm
# %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm
export_url = 'schedule/api_key/%%api_key%%'
get_media_url = 'get-media/file/%%file%%/api_key/%%api_key%%'
# Update whether a schedule group has begun playing.
update_item_url = 'notify-schedule-group-play/api_key/%%api_key%%/schedule_id/%%schedule_id%%'
# Update whether an audio clip is currently playing.
update_start_playing_url = 'notify-media-item-start-play/api_key/%%api_key%%/media_id/%%media_id%%/schedule_id/%%schedule_id%%'
# ???
generate_range_url = 'generate_range_dp.php'
##############
# OBP config #
##############
# Value needed to access the API
#api_key = 'AAA'
#base_url = 'http://localhost/'
# Path to the base of the API
#api_base = ''
# URL to get the version number of the server API
#version_url = 'api/pypo/status/json'
# Schedule export path.
# %%from%% - starting date/time in the form YYYY-MM-DD-hh-mm
# %%to%% - starting date/time in the form YYYY-MM-DD-hh-mm
# Update whether an item has been played.
#update_item_url = 'api/pypo/update_shedueled_item/$$item_id%%?played=%%played%%'
# Update whether an item is currently playing.
#update_start_playing_url = 'api/pypo/mod/medialibrary/?playlist_type=%%playlist_type%%&export_source=%%export_source%%&media_id=%%media_id%%&playlist_id=%%playlist_id%%&transmission_id=%%transmission_id%%'
# ???
#generate_range_url = 'api/pypo/generate_range_dp/'

View file

@ -1,9 +1,5 @@
api_client = "airtime" api_client = "airtime"
# Hostname
base_url = 'localhost'
base_port = 80
# where the binary files live # where the binary files live
bin_dir = '/usr/lib/airtime/show-recorder' bin_dir = '/usr/lib/airtime/show-recorder'
@ -12,24 +8,3 @@ base_recorded_files = '/var/tmp/airtime/show-recorder/'
# where the logging files live # where the logging files live
log_dir = '/var/log/airtime/show-recorder' log_dir = '/var/log/airtime/show-recorder'
# Value needed to access the API
api_key = 'AAA'
# Path to the base of the API
api_base = 'api'
# URL to get the version number of the server API
version_url = 'version/api_key/%%api_key%%'
# URL to get the schedule of shows set to record
show_schedule_url = 'recorded-shows/format/json/api_key/%%api_key%%'
# URL to upload the recorded show's file to Airtime
upload_file_url = 'upload-file/format/json/api_key/%%api_key%%'
#number of retries to upload file if connection problem
upload_retries = 3
#time to wait between attempts to upload file if connection problem (in seconds)
upload_wait = 60

View file

@ -14,7 +14,7 @@ AirtimeCheck::CheckOsTypeVersion();
AirtimeCheck::CheckConfigFilesExist(); AirtimeCheck::CheckConfigFilesExist();
$pypoCfg = AirtimeCheck::GetPypoCfg(); $apiClientCfg = AirtimeCheck::GetApiClientCfg();
AirtimeCheck::GetDbConnection($airtimeIni); AirtimeCheck::GetDbConnection($airtimeIni);
AirtimeCheck::PythonLibrariesInstalled(); AirtimeCheck::PythonLibrariesInstalled();
@ -23,7 +23,7 @@ AirtimeCheck::CheckRabbitMqConnection($airtimeIni);
//AirtimeCheck::CheckApacheVHostFiles(); //AirtimeCheck::CheckApacheVHostFiles();
AirtimeCheck::GetAirtimeServerVersion($pypoCfg); AirtimeCheck::GetAirtimeServerVersion($apiClientCfg);
AirtimeCheck::CheckAirtimeDaemons(); AirtimeCheck::CheckAirtimeDaemons();
AirtimeCheck::CheckIcecastRunning(); AirtimeCheck::CheckIcecastRunning();
@ -205,12 +205,12 @@ class AirtimeCheck {
return $ini; return $ini;
} }
public static function GetPypoCfg() public static function GetApiClientCfg()
{ {
$ini = parse_ini_file("/etc/airtime/pypo.cfg", false); $ini = parse_ini_file("/etc/airtime/api_client.cfg", false);
if ($ini === false){ if ($ini === false){
echo "Error reading /etc/airtime/pypo.cfg.".PHP_EOL; echo "Error reading /etc/airtime/api_client.cfg.".PHP_EOL;
exit; exit;
} }
@ -335,17 +335,17 @@ class AirtimeCheck {
output_status("RABBITMQ_SERVER", $status); output_status("RABBITMQ_SERVER", $status);
} }
public static function GetAirtimeServerVersion($pypoCfg) public static function GetAirtimeServerVersion($apiClientCfg)
{ {
$baseUrl = $pypoCfg["base_url"]; $baseUrl = $apiClientCfg["base_url"];
$basePort = $pypoCfg["base_port"]; $basePort = $apiClientCfg["base_port"];
$apiKey = "%%api_key%%"; $apiKey = "%%api_key%%";
$url = "http://$baseUrl:$basePort/api/version/api_key/$apiKey"; $url = "http://$baseUrl:$basePort/api/version/api_key/$apiKey";
output_status("AIRTIME_VERSION_URL", $url); output_status("AIRTIME_VERSION_URL", $url);
$apiKey = $pypoCfg["api_key"]; $apiKey = $apiClientCfg["api_key"];
$url = "http://$baseUrl:$basePort/api/version/api_key/$apiKey"; $url = "http://$baseUrl:$basePort/api/version/api_key/$apiKey";
$rh = fopen($url, "r"); $rh = fopen($url, "r");