Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ggatward committed Dec 11, 2017
1 parent 2b5e8a9 commit 4e7ec11
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Incorrect mapping of days in auto_content.py
- Support for username:token authentication to Artifactory Puppet Forge server


## [1.2.0] - 2017-12-10
### Added
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ puppet-forge-server:
servertype: puppet-forge-server
hostname: puppetforge.example.org
modulepath: /opt/puppet-forge/modules
username: someuser
token: ArtifactoryAPIToken
```

```
Expand All @@ -326,6 +328,8 @@ optional arguments:
path to puppet-forge-server modules
-u USER, --user USER Username to push modules to server as (default is user
running script)
-p PASSWORD --password PASSWORD
Token for Artifactory API authentication
```

### Examples
Expand Down
26 changes: 19 additions & 7 deletions auto_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def dates():

print "Day %s of week %s" % (dayofweek, weekofmonth)

return(dayofweek,weekofmonth)
# Define dictionary mapping 'human readable' days to thier numeric value
days = {'Mon' : 0, 'Tue' : 1, 'Wed' : 2, 'Thu' : 3, 'Fri' : 4, 'Sat' : 5, 'Sun' : 6}

return(dayofweek,weekofmonth,days)


def run_imports(dryrun):
Expand Down Expand Up @@ -98,6 +101,10 @@ def promote_cv(dryrun, lifecycle):


def push_puppet(dryrun):
"""
Performs a push of puppet modules using the DEFAULT puppet-forge-server defined in the
config.yml
"""
print "Pushing puppet modules to puppet-forge server..."

# Set the initial state
Expand Down Expand Up @@ -130,8 +137,9 @@ def clean_cv(dryrun):


def main(args):

### Run import/publish on scheduled day
"""
Performs import/publish/promote/cleanup on scheduled days
"""

# Check for sane input
parser = argparse.ArgumentParser(
Expand All @@ -153,11 +161,12 @@ def main(args):
run_promote = True

# Determine the day of week and week of month for use in our scheduling
(dayofweek, weekofmonth) = dates()
(dayofweek, weekofmonth, days) = dates()


# MONDAYS
# Run promotion first - this ensures content consistency (QA->Prod, Library->QA)
if dayofweek == 0:
if dayofweek == days['Mon']:
if weekofmonth == 4:
run_promote = promote_cv(dryrun, 'Production')

Expand All @@ -167,7 +176,8 @@ def main(args):
run_promote = promote_cv(dryrun, 'Quality')


# Every day, check if there are any imports in our input dir and import them.
# EVERY DAY
# Check if there are any imports in our input dir and import them.
# run_publish will be returned as 'True' if any successful imports were performed.
# If no imports are performed, or they fail, publish can't be triggered.
run_publish = run_imports(dryrun)
Expand All @@ -179,8 +189,10 @@ def main(args):
if args.puppet:
push_puppet(dryrun)


# THURSDAYS
# Run content view cleanup once a month, after we have done all promotions for the month.
if dayofweek == 3:
if dayofweek == days['Thu']:
if weekofmonth == 4:
clean_cv(dryrun)

Expand Down
21 changes: 13 additions & 8 deletions man/push_puppetforge.8
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ push_puppetforge \- Export puppet forge modules and push to puppet-forge-server
.B push_puppetforge
is a script to push puppet forge modules that have been synchronised using Satellite 6
to an offline puppet forge server that uses the puppet-forge-server rubygem instance:
.br
.br
.I https://github.com/unibet/puppet-forge-server
.LP
The puppet-forge-server instance requires a specific format for the module filesystem that
differst from that used by Satellite 6. To make use of this script, the connected Satellite
must sync the puppet-forge repository, and have that repo included for the
different from that used by Satellite 6. To make use of this script, the connected Satellite
must sync the puppet-forge repository, and have that repo included for the
.BR sat_export (8)
script. The disconnected Satellite must import the puppet modules into an identically named
puppet repository.
.LP
.BR push_puppetforge " will"
export the puppet modules from the disconnected Satellite and use rsync to transfer them to
export the puppet modules from the disconnected Satellite and use rsync to transfer them to
the offline puppet-forge-server instance.

.SH OPTIONS
Expand All @@ -51,7 +51,7 @@ Label of the puppet-forge repository in Satellite to use as the sync source.
.RS 3
Hostname of the puppet-forge-server instance.
.br
The default value is configured in the
The default value is configured in the
.I config.yml
file
.RE
Expand All @@ -65,12 +65,18 @@ Location of the puppet modules on the puppet-forge-server instance. (Default is
.BR "-u", " --user"
.I USER
.RS 3
Username to login to the puppet-forge-server as. Default is the user running the
Username to login to the puppet-forge-server as. Default is the user running the
.B push_puppetforge
script, from the
script, from the
.I SUDO_USER
environment variable.
.RE
.PP
.BR "-p", " --password"
.I PASSWORD
.RS 3
API Token for user to post modules to Artifactory. Ignored if servertype is puppet-forge-server.
.RE

.SH FILES
.B Main Configuration
Expand All @@ -89,4 +95,3 @@ environment variable.

.SH AUTHOR
Geoff Gatward <[email protected]>

6 changes: 2 additions & 4 deletions push_puppetforge.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ def postModule(moduleTar, moduleInputDir, pfserver, pfmodpath, pfuser, pftoken):
fileName = moduleInputDir + "/" + moduleTar

# Put the files using curl (need to clean this up)
# subprocess.call(['curl', '-XPUT', url, '-T', fileName])

authtoken = pfuser + ":" + pftoken
subprocess.call(['curl', '-u', authtoken, '-XPUT', url, '-T', fileName])

Expand Down Expand Up @@ -163,7 +161,7 @@ def main(args):
required=False)
parser.add_argument('-u', '--user', help='Username to push modules to server as (default is user running script)',
required=False)
parser.add_argument('-p', '--password', help='Password for username to push modules',
parser.add_argument('-p', '--password', help='Password (token) for username to push modules to Artifactory',
required=False)
args = parser.parse_args()

Expand Down Expand Up @@ -209,7 +207,7 @@ def main(args):
else:
pfuser = helpers.PFUSER

# Read in the token for Artifiactory
# Read in the token for Artifiactory
if args.password:
pftoken = args.password
else:
Expand Down

0 comments on commit 4e7ec11

Please sign in to comment.