java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
| 32 +
java/code/src/com/redhat/rhn/frontend/xmlrpc/channel/software/ChannelSoftwareHandler.java
| 195 ++++++++++
java/spacewalk-java.spec
| 6
rel-eng/packages/spacewalk-java
| 2
spacecmd/src/lib/repo.py
| 144 +++++++
5 files changed, 377 insertions(+), 2 deletions(-)
New commits:
commit 802b6d248036621bdb8ae56a239e269811d761f5
Author: Aron Parsons <aronparsons(a)gmail.com>
Date: Sat Sep 29 18:11:31 2012 -0400
Automatic commit of package [spacewalk-java] release [1.8.152-1].
diff --git a/java/spacewalk-java.spec b/java/spacewalk-java.spec
index 17935f0..a234f96 100644
--- a/java/spacewalk-java.spec
+++ b/java/spacewalk-java.spec
@@ -23,7 +23,7 @@ Name: spacewalk-java
Summary: Spacewalk Java site packages
Group: Applications/Internet
License: GPLv2
-Version: 1.8.151
+Version: 1.8.152
Release: 1%{?dist}
URL:
https://fedorahosted.org/spacewalk
Source0:
https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -616,6 +616,10 @@ fi
%{jardir}/postgresql-jdbc.jar
%changelog
+* Sat Sep 29 2012 Aron Parsons <aronparsons(a)gmail.com> 1.8.152-1
+- add API calls to manage repo filters
+- add methods to add/remove ContentSourceFilter objects
+
* Tue Sep 25 2012 Tomas Lestach <tlestach(a)redhat.com> 1.8.151-1
- getting timestamp from PackageCapabilityIterator in a correct way
diff --git a/rel-eng/packages/spacewalk-java b/rel-eng/packages/spacewalk-java
index 179bc6d..a666cc8 100644
--- a/rel-eng/packages/spacewalk-java
+++ b/rel-eng/packages/spacewalk-java
@@ -1 +1 @@
-1.8.151-1 java/
+1.8.152-1 java/
commit 4d04d31f78cbc9508ee20099b3b11c42724b0c66
Author: Aron Parsons <aronparsons(a)gmail.com>
Date: Sat Sep 29 18:03:51 2012 -0400
spacecmd: add functions to manage repo filters
diff --git a/spacecmd/src/lib/repo.py b/spacecmd/src/lib/repo.py
index ff9d116..b6a3d00 100644
--- a/spacecmd/src/lib/repo.py
+++ b/spacecmd/src/lib/repo.py
@@ -22,6 +22,8 @@
from spacecmd.utils import *
+import shlex
+
def help_repo_list(self):
print 'repo_list: List all available user repos'
print 'usage: repo_list'
@@ -67,3 +69,145 @@ def do_repo_details(self, args):
print 'Repository Label: %s' % details.get('label')
print 'Repository URL: %s' % details.get('sourceUrl')
print 'Repository Type: %s' % details.get('type')
+
+####################
+
+def help_repo_listfilters(self):
+ print 'repo_listfilters: Show the filters for a user repo'
+ print 'usage: repo_listfilters repo'
+
+def complete_repo_listfilters(self, text, line, beg, end):
+ return tab_completer(self.do_repo_list('', True), text)
+
+def do_repo_listfilters(self, args):
+ (args, options) = parse_arguments(args)
+
+ if not len(args):
+ self.help_repo_listfilters()
+ return
+
+ filters = \
+ self.client.channel.software.listRepoFilters(self.session, args[0])
+
+ for filter in filters:
+ print "%s%s" % (filter.get('flag'),
filter.get('filter'))
+
+####################
+
+def help_repo_addfilters(self):
+ print 'repo_addfilters: Add filters for a user repo'
+ print 'usage: repo_addfilters repo <filter ...>'
+
+def complete_repo_addfilters(self, text, line, beg, end):
+ return tab_completer(self.do_repo_add('', True), text)
+
+def do_repo_addfilters(self, args):
+ # arguments can start with -, so don't parse arguments in the normal way
+ args = shlex.split(args)
+
+ if not len(args):
+ self.help_repo_addfilters()
+ return
+
+ repo = args[0]
+
+ filters = []
+
+ for arg in args[1:]:
+ flag = arg[0]
+ filter = arg[1:]
+
+ if not (flag == '+' or flag == '-'):
+ logging.error('Each filter must start with + or -')
+ return
+
+ self.client.channel.software.addRepoFilter(self.session,
+ repo,
+ {'filter' : filter,
+ 'flag' : flag})
+
+####################
+
+def help_repo_removefilters(self):
+ print 'repo_removefilters: Add filters for a user repo'
+ print 'usage: repo_removefilters repo <filter ...>'
+
+def complete_repo_removefilters(self, text, line, beg, end):
+ return tab_completer(self.do_repo_remove('', True), text)
+
+def do_repo_removefilters(self, args):
+ # arguments can start with -, so don't parse arguments in the normal way
+ args = shlex.split(args)
+
+ if not len(args):
+ self.help_repo_removefilters()
+ return
+
+ repo = args[0]
+
+ filters = []
+
+ for arg in args[1:]:
+ flag = arg[0]
+ filter = arg[1:]
+
+ if not (flag == '+' or flag == '-'):
+ logging.error('Each filter must start with + or -')
+ return
+
+ self.client.channel.software.removeRepoFilter(self.session,
+ repo,
+ {'filter' : filter,
+ 'flag' : flag})
+
+####################
+
+def help_repo_setfilters(self):
+ print 'repo_setfilters: Set the filters for a user repo'
+ print 'usage: repo_setfilters repo <filter ...>'
+
+def complete_repo_setfilters(self, text, line, beg, end):
+ return tab_completer(self.do_repo_set('', True), text)
+
+def do_repo_setfilters(self, args):
+ # arguments can start with -, so don't parse arguments in the normal way
+ args = shlex.split(args)
+
+ if not len(args):
+ self.help_repo_setfilters()
+ return
+
+ repo = args[0]
+
+ filters = []
+
+ for arg in args[1:]:
+ flag = arg[0]
+ filter = arg[1:]
+
+ if not (flag == '+' or flag == '-'):
+ logging.error('Each filter must start with + or -')
+ return
+
+ filters.append({'filter' : filter, 'flag' : flag})
+
+ self.client.channel.software.setRepoFilters(self.session, repo, filters)
+
+####################
+
+def help_repo_clearfilters(self):
+ print 'repo_clearfilters: Clears the filters for a user repo'
+ print 'usage: repo_clearfilters repo'
+
+def complete_repo_clearfilters(self, text, line, beg, end):
+ return tab_completer(self.do_repo_clear('', True), text)
+
+def do_repo_clearfilters(self, args):
+ (args, options) = parse_arguments(args)
+
+ if not len(args):
+ self.help_repo_clearfilters()
+ return
+
+ if self.user_confirm('Remove these filters [y/N]:'):
+ self.client.channel.software.clearRepoFilters(self.session, args[0])
commit b1a90af4645d203cf271d7ef935c9f9cfe60f096
Author: Aron Parsons <aronparsons(a)gmail.com>
Date: Sat Sep 29 18:03:45 2012 -0400
add API calls to manage repo filters
diff --git
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/channel/software/ChannelSoftwareHandler.java
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/channel/software/ChannelSoftwareHandler.java
index 3e76fe1..f31e854 100644
---
a/java/code/src/com/redhat/rhn/frontend/xmlrpc/channel/software/ChannelSoftwareHandler.java
+++
b/java/code/src/com/redhat/rhn/frontend/xmlrpc/channel/software/ChannelSoftwareHandler.java
@@ -2746,6 +2746,201 @@ public class ChannelSoftwareHandler extends BaseHandler {
return result;
}
+ /**
+ * adds a filter for a given repo.
+ * @param sessionKey the sessionkey needed for authentication
+ * @param label of the repo to use
+ * @param filterIn list of filters
+ * @return sort order for the new filter
+ *
+ * @xmlrpc.doc Adds a filter for a given repo.
+ * @xmlrpc.param #param("string", "sessionKey ")
+ * @xmlrpc.param #param_desc("string", "label", "repository
label")
+ * @xmlrpc.param
+ * #struct("filter_map")
+ * #prop_desc("string", "filter", "string to filter
on")
+ * #prop_desc("string", "flag", "+ for include, -
for exclude")
+ * #struct_end()
+ * @xmlrpc.returntype int sort order for new filter
+ */
+ public int addRepoFilter(String sessionKey, String label, Map filterIn) {
+ User user = getLoggedInUser(sessionKey);
+
+ Role orgAdminRole = RoleFactory.lookupByLabel("org_admin");
+
+ if (!user.hasRole(orgAdminRole)) {
+ throw new PermissionException("Only Org Admins can add repo
filters.");
+ }
+
+ ContentSource cs = lookupContentSourceByLabel(label, user.getOrg());
+
+ String flag = (String) filterIn.get("flag");
+ String filter = (String) filterIn.get("filter");
+
+ if (!(flag.equals("+") || flag.equals("-"))) {
+ throw new InvalidParameterException("flag must be + or -");
+ }
+
+ // determine the highest sort order of existing filters
+ int sortOrder = 0;
+ for (ContentSourceFilter f : listRepoFilters(sessionKey, label)) {
+ sortOrder = Math.max(sortOrder, f.getSortOrder());
+ }
+
+ ContentSourceFilter newFilter = new ContentSourceFilter();
+ newFilter.setSourceId(cs.getId());
+ newFilter.setFlag(flag);
+ newFilter.setFilter(filter);
+ newFilter.setSortOrder(sortOrder + 1);
+
+ ChannelFactory.save(newFilter);
+
+ return sortOrder;
+ }
+
+ /**
+ * removes a filter for a given repo.
+ * @param sessionKey the sessionkey needed for authentication
+ * @param label of the repo to use
+ * @param filterIn list of filters
+ * @return 1 on success
+ *
+ * @xmlrpc.doc removes a filter for a given repo.
+ * @xmlrpc.param #param("string", "sessionKey ")
+ * @xmlrpc.param #param_desc("string", "label", "repository
label")
+ * @xmlrpc.param
+ * #struct("filter_map")
+ * #prop_desc("string", "filter", "string to filter
on")
+ * #prop_desc("string", "flag", "+ for include, -
for exclude")
+ * #struct_end()
+ * @xmlrpc.returntype #return_int_success()
+ */
+ public int removeRepoFilter(String sessionKey, String label, Map filterIn) {
+ User user = getLoggedInUser(sessionKey);
+
+ Role orgAdminRole = RoleFactory.lookupByLabel("org_admin");
+
+ if (!user.hasRole(orgAdminRole)) {
+ throw new PermissionException("Only Org Admins can remove repo
filters.");
+ }
+
+ ContentSource cs = lookupContentSourceByLabel(label, user.getOrg());
+
+ String flag = (String) filterIn.get("flag");
+ String filter = (String) filterIn.get("filter");
+
+ if (!(flag.equals("+") || flag.equals("-"))) {
+ throw new InvalidParameterException("flag must be + or -");
+ }
+
+ // find the existing filter
+ ContentSourceFilter oldFilter = null;
+ for (ContentSourceFilter f : listRepoFilters(sessionKey, label)) {
+ if (flag.equals(f.getFlag()) && filter.equals(f.getFilter())) {
+ oldFilter = f;
+ break;
+ }
+ }
+
+ if (oldFilter == null) {
+ throw new InvalidParameterException("filter does not exist");
+ }
+
+ ChannelFactory.remove(oldFilter);
+
+ return 1;
+ }
+
+ /**
+ * replaces the existing set of filters for a given repo.
+ * filters are ranked by their order in the array.
+ * @param sessionKey the sessionkey needed for authentication
+ * @param label of the repo to use
+ * @param filtersIn list of filters
+ * @return 1 on success
+ *
+ * @xmlrpc.doc Replaces the existing set of filters for a given repo.
+ * Filters are ranked by their order in the array.
+ * @xmlrpc.param #param("string", "sessionKey ")
+ * @xmlrpc.param #param_desc("string", "label", "repository
label")
+ * @xmlrpc.param
+ * #array()
+ * #struct("filter_map")
+ * #prop_desc("string", "filter", "string to filter
on")
+ * #prop_desc("string", "flag", "+ for include, -
for exclude")
+ * #struct_end()
+ * #array_end()
+ * @xmlrpc.returntype #return_int_success()
+ */
+ public int setRepoFilters(String sessionKey, String label, List<Map> filtersIn)
{
+ User user = getLoggedInUser(sessionKey);
+
+ Role orgAdminRole = RoleFactory.lookupByLabel("org_admin");
+
+ if (!user.hasRole(orgAdminRole)) {
+ throw new PermissionException("Only Org Admins can set repo
filters.");
+ }
+
+ ContentSource cs = lookupContentSourceByLabel(label, user.getOrg());
+
+ List<ContentSourceFilter> filters = new ArrayList();
+
+ int i = 1;
+ for (Map filterIn : filtersIn) {
+ String flag = (String) filterIn.get("flag");
+ String filter = (String) filterIn.get("filter");
+
+ if (!(flag.equals("+") || flag.equals("-"))) {
+ throw new InvalidParameterException("flag must be + or -");
+ }
+
+ ContentSourceFilter f = new ContentSourceFilter();
+ f.setSourceId(cs.getId());
+ f.setFlag(flag);
+ f.setFilter(filter);
+ f.setSortOrder(i);
+
+ filters.add(f);
+
+ i++;
+ }
+
+ ChannelFactory.clearContentSourceFilters(cs.getId());
+
+ for (ContentSourceFilter filter : filters) {
+ ChannelFactory.save(filter);
+ }
+
+ return 1;
+ }
+
+ /**
+ * Clears the filters for a repo
+ * @param sessionKey Session containing user information.
+ * @param label of the repo to use
+ * @return 1 on success
+ *
+ * @xmlrpc.doc Removes the filters for a repo
+ * @xmlrpc.param #session_key()
+ * @xmlrpc.param #param_desc("string", "label", "repository
label")
+ * @xmlrpc.returntype #return_int_success()
+ **/
+ public int clearRepoFilters(String sessionKey, String label) {
+ User user = getLoggedInUser(sessionKey);
+
+ Role orgAdminRole = RoleFactory.lookupByLabel("org_admin");
+
+ if (!user.hasRole(orgAdminRole)) {
+ throw new PermissionException("Only Org Admins can remove repo
filters.");
+ }
+
+ ContentSource cs = lookupContentSourceByLabel(label, user.getOrg());
+
+ ChannelFactory.clearContentSourceFilters(cs.getId());
+
+ return 1;
+ }
+
private ContentSource lookupContentSourceById(Long repoId, Org org) {
ContentSource cs = ChannelFactory.lookupContentSource(repoId, org);
if (cs == null) {
commit 4009dcf9a102c6fdd4613045c83a4dd6aa5e5392
Author: Aron Parsons <aronparsons(a)gmail.com>
Date: Sat Sep 29 18:03:38 2012 -0400
add methods to add/remove ContentSourceFilter objects
diff --git a/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
b/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
index c2d02b6..106b750 100644
--- a/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
+++ b/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java
@@ -237,6 +237,14 @@ public class ChannelFactory extends HibernateFactory {
}
/**
+ * Insert or Update a content source filter.
+ * @param f content source filter to be stored in database.
+ */
+ public static void save(ContentSourceFilter f) {
+ singleton.saveObject(f);
+ }
+
+ /**
* Remove a Channel from the DB
* @param c Action to be removed from database.
*/
@@ -272,6 +280,14 @@ public class ChannelFactory extends HibernateFactory {
}
/**
+ * Remove a ContentSourceFilter from the DB
+ * @param filter to be removed from database
+ */
+ public static void remove(ContentSourceFilter filter) {
+ singleton.removeObject(filter);
+ }
+
+ /**
* Returns the base channel for the given server id.
* @param sid Server id whose base channel we want.
* @return Base Channel for the given server id.
@@ -1012,4 +1028,20 @@ public class ChannelFactory extends HibernateFactory {
criteria.add(Restrictions.eq("channel", ch));
return (Integer)criteria.uniqueResult() > 0;
}
+
+ /**
+ * Clear a content source's filters
+ * @param id source id
+ */
+ public static void clearContentSourceFilters(Long id) {
+ List<ContentSourceFilter> filters = lookupContentSourceFiltersById(id);
+
+ for (ContentSourceFilter filter : filters) {
+ remove(filter);
+ }
+
+ // flush so that if we're creating new filters we don't get constraint
+ // violations for rhn_csf_sid_so_uq
+ HibernateFactory.getSession().flush();
+ }
}