Skip to content

Commit

Permalink
Add 1.2 support, add 'none' auth type.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamentis committed Aug 30, 2017
1 parent c723383 commit 4111009
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
0.3.0 (XXXX-XX-XX)
------------------
- add new auth_type: acctmgr
- add new auth_type: none (for sites accepting anonymous tickets/comments)
- bump compatibility to 1.2.x

0.2.3 (2015-12-27)
------------------
Expand Down
12 changes: 5 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ command-line argument. Within each section, the following settings are
available:

- ``base_url`` - required, defines the URL of your Trac system
- ``username`` - required
- ``password`` - required
- ``auth_type`` - forces an authentication type, currently available: ``basic``
(default), ``digest``.
- ``username`` - required if ``auth_type`` is not ``none``
- ``password`` - required if ``auth_type`` is not ``none``
- ``verify_ssl_cert`` - ignore self-signed or invalid SSL certificates if set
to false.
- ``editor`` - override the editor defined the ``$EDITOR`` environment
Expand Down Expand Up @@ -198,25 +198,23 @@ Requirements

Compatibility
-------------
- Tested on Trac 0.12.5 and 1.0.1
- Tested on Trac 0.12.5 and 1.2.x
- Probably still works on 0.11, but untested.


Hacking
-------
- The following command will create one virtualenv and sandbox for each latest
0.12 and 1.0 releases of Trac::
0.12, 1.0 and 1.2 releases of Trac::

$ ./tools/mkenv.sh

- You can then serve one or the other using, the default admin user/pass is
sandbox/sandbox::

$ ./tools/serve-0.12.sh

-OR-

$ ./tools/serve-1.0.sh
$ ./tools/serve-1.2.sh

- Follow PEP-8, existing style then the following notes.
- For dictionaries, lists: keep commas after each items, closing bracket
Expand Down
34 changes: 25 additions & 9 deletions cartman/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2011-2016 Bertrand Janin <b@janin.com>
# Copyright (c) 2011-2017 Bertrand Janin <b@janin.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
Expand Down Expand Up @@ -36,12 +36,15 @@
]

MIN_TRAC_VERSION = (0, 11)
MAX_TRAC_VERSION = (1, 0)
MAX_TRAC_VERSION = (1, 2)

# List of all our accepted authentication types. The values are authentication
# classes used by the requests module.
AUTH_TYPES = {
"basic": requests.auth.HTTPBasicAuth,
"digest": requests.auth.HTTPDigestAuth,
"acctmgr": lambda a, b: None,
"acctmgr": None,
"none": None,
}

DEFAULT_TEMPLATE = """To:
Expand Down Expand Up @@ -92,7 +95,8 @@ def run(self, args):
self.session = requests.session()

auth_class = AUTH_TYPES[self.auth_type]
self.session.auth = auth_class(self.username, self.password)
if auth_class:
self.session.auth = auth_class(self.username, self.password)
self.session.verify = self.verify_ssl_cert

func_name = "run_" + args.command
Expand Down Expand Up @@ -146,8 +150,6 @@ def read_config(self):
"a base_url.".format(self.site))

self.base_url = cp.get(self.site, "base_url").rstrip("/")
self.username = cp.get(self.site, "username")
self.password = cp.get(self.site, "password")
self.verify_ssl_cert = cp.getboolean(self.site, "verify_ssl_cert")

# load auth
Expand All @@ -160,6 +162,19 @@ def read_config(self):
raise exceptions.ConfigError(msg)
self.auth_type = auth_type

# On anonymous Trac systems, you may still specify a username, but you
# you are able to do some operations as anonymous. For all other
# authentication types, username and password are mandatory.
if auth_type in ("none", "acctmgr"):
self.logged_in = True
try:
self.username = cp.get(self.site, "username")
except configparser.NoOptionError:
self.username = "anonymous"
else:
self.username = cp.get(self.site, "username")
self.password = cp.get(self.site, "password")

if cp.has_option(self.site, "editor"):
self.config_editor = cp.get(self.site, "editor")
else:
Expand Down Expand Up @@ -475,10 +490,11 @@ def extract_status_from_ticket_page(self, raw_html):
#

def run_change(self, ticket_id, *values):
"""Make change to the given ticket_id. This command does not return
anything if successful.
"""Make change to the given ticket_id.
This command does not return anything if successful.
TODO: support spanning an editor to change field values.
TODO: support spawning an editor to change field values.
usage: cm change ticket_id field=value [field=value...]
Expand Down
6 changes: 6 additions & 0 deletions tools/mkenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ virtualenv venv-1.0
./venv-1.0/bin/pip install "trac<1.0.999"
./venv-1.0/bin/trac-admin sandbox-1.0 initenv "Sandbox for Trac 1.0" sqlite:db/trac.db
./venv-1.0/bin/trac-admin sandbox-1.0 permission add sandbox TRAC_ADMIN

virtualenv venv-1.2
./venv-1.2/bin/pip install "trac<1.2.999"
./venv-1.2/bin/trac-admin sandbox-1.2 initenv "Sandbox for Trac 1.2" sqlite:db/trac.db
./venv-1.2/bin/trac-admin sandbox-1.2 permission add sandbox TRAC_ADMIN

htpasswd -b -c -m htpasswd sandbox sandbox
13 changes: 13 additions & 0 deletions tools/serve-1.2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
#
# Serve the Trac 1.2 sandbox. This assumes you have run ./tools/mkenv.sh
# beforehand.
#

if [ ! -d "venv-1.2" ] || [ ! -d "sandbox-1.2" ]; then
echo "error: you need to run ./tools/mkenv.sh first"
exit 1
fi


./venv-1.2/bin/tracd sandbox-1.2 -p 8082 --basic-auth=sandbox\-1.2,htpasswd,sandbox

0 comments on commit 4111009

Please sign in to comment.