Skip to content

Commit

Permalink
(chocolatey-communityGH-10) Add support for custom package folder
Browse files Browse the repository at this point in the history
Add additional parameters to modify the chocolatey repository package
folder and set custom permissions. Update readme.
  • Loading branch information
ripclawffb committed Apr 22, 2018
1 parent 53e8df2 commit b2c17ad
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 7 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ class {'chocolatey_server':
}
~~~

### Use a alternate package folder

~~~puppet
class { 'chocolatey_server':
packages_folder => 'C:\Chocolatey',
port => '8080',
}
~~~

### Set different permissions on the packages folder

~~~puppet
class { 'chocolatey_server':
packages_folder_permissions = [
{ identity => 'IIS APPPOOL\\chocolatey.server', rights => ['modify'] },
{ identity => 'IIS_IUSRS', rights => ['modify'] },
{ identity => 'Users', rights => ['read'] },
]
}
~~~

## Reference

### Classes
Expand All @@ -106,6 +127,24 @@ Host your own Chocolatey package repository

#### Parameters

##### `chocolatey_server_app_pool_name`
Set apppool name used by the chocolatey.server website. Defaults to
'chocolatey.server'.

##### `packages_folder`
An alternate folder can be defined for the .nupkg files. This is where the
nuget packages are actually stored that will be served by the chocolatey server.

Note: This is different from 'server_package_source' as that defines where
the chocolatey.server package is located.

##### `packages_folder_permissions`
Set permissions on packages folder. Defaults to:
* IIS APPOOL\${chocolatey_server_app_pool_name} - modify
* IIS_IUSRS - modify

The permissions should be passed as an array of identity and permissions.

##### `port`
The port for the server website. Defaults to '80'.

Expand Down
9 changes: 9 additions & 0 deletions examples/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# setting up a chocolatey server on port 8080 with an alternate packages folder
# without disabling the default web site
class { 'chocolatey_server':
packages_folder => 'C:\Chocolatey',
port => '8080',
}

# installs chocolatey server with default parameters
include chocolatey_server
70 changes: 64 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,28 @@
# }
#
# @param [String] port The port for the server website. Defaults to '80'.
#
# @param [String] server_package_source The chocolatey source that contains
# the `chocolatey.server` package. Defaults to
# 'https://chocolatey.org/api/v2/'.
#
# @param [String] server_install_location The location to that the chocolatey
# server will be installed. This is can be used if you are controlling
# the location that chocolatey packages are being installed via some other
# means. e.g. environment variable ChocolateyBinRoot. Defaults to
# 'C:\tools\chocolatey.server'
class chocolatey_server (
$chocolatey_server_app_pool_name = $::chocolatey_server::params::chocolatey_server_app_pool_name,
$packages_folder = $::chocolatey_server::params::packages_folder,
$packages_folder_permissions = $::chocolatey_server::params::packages_folder_permissions,
$port = $::chocolatey_server::params::service_port,
$server_package_source = $::chocolatey_server::params::server_package_source,
$server_install_location = $::chocolatey_server::params::server_install_location,
) inherits ::chocolatey_server::params {
require chocolatey

$_chocolatey_server_location = $server_install_location
$_chocolatey_server_app_pool_name = 'chocolateyserver'
$_chocolatey_server_app_pool_name = $chocolatey_server_app_pool_name
$_chocolatey_server_app_port = $port
$_server_package_url = $server_package_source
$_is_windows_2008 = $::kernelmajversion ? {
Expand Down Expand Up @@ -108,10 +113,14 @@
purge => true,
inherit_parent_permissions => false,
permissions => [
{ identity => 'Administrators', rights => ['full'] },
{ identity => 'IIS_IUSRS', rights => ['read'] },
{ identity => 'IUSR', rights => ['read'] },
{ identity => "IIS APPPOOL\\${_chocolatey_server_app_pool_name}", rights => ['read'] }
{ identity => 'Administrators',
rights => ['full'] },
{ identity => 'IIS_IUSRS',
rights => ['read'] },
{ identity => 'IUSR',
rights => ['read'] },
{ identity => "IIS APPPOOL\\${_chocolatey_server_app_pool_name}",
rights => ['read'] }
],
require => Package['chocolatey.server'],
}
Expand All @@ -122,5 +131,54 @@
],
require => Package['chocolatey.server'],
}
# technically you may only need IIS_IUSRS but I have not tested this yet.

# only set permissions if an alternate package folder is undefined
unless $packages_folder {
# ensure app_data folder is created
file { "${_chocolatey_server_location}/App_Data":
ensure => directory,
}

# ensure packages folder is created
file { "${_chocolatey_server_location}/App_Data/Packages":
ensure => directory,
require => File["${_chocolatey_server_location}/App_Data"],
}

acl { "${_chocolatey_server_location}/App_Data":
permissions => $packages_folder_permissions,
require => [Iis::Manage_app_pool["${_chocolatey_server_app_pool_name}"],
File["${_chocolatey_server_location}/App_Data"]],
}
# technically you may only need IIS_IUSRS but I have not tested this yet.
}

# if a different folder for packages is specified, create a symlink
if $packages_folder {
# ensure app_data folder is created
file { "${_chocolatey_server_location}/App_Data":
ensure => directory,
}

# ensure packages folder is created
file { "${packages_folder}":
ensure => directory,
}

# create a symlink to the new packages folder, replacing the existing
# app_data folder
file { "${_chocolatey_server_location}/App_Data/Packages":
ensure => link,
force => true,
target => $packages_folder,
require => File["${packages_folder}"],
}

# set permissions on the new packages folder
acl { "${packages_folder}":
permissions => $packages_folder_permissions,
require => File["${packages_folder}"],
}
}

}
8 changes: 7 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
class chocolatey_server::params {
case $::osfamily {
'windows': {
$service_port = '80'
$chocolatey_server_app_pool_name = 'chocolatey.server'
$packages_folder = undef
$packages_folder_permissions = [
{ identity => "IIS APPPOOL\\${chocolatey_server_app_pool_name}", rights => ['modify'] },
{ identity => 'IIS_IUSRS', rights => ['modify'] }
]
$service_port = '80'
$server_package_source = 'https://chocolatey.org/api/v2/'
$server_install_location = 'C:\tools\chocolatey.server'
}
Expand Down

0 comments on commit b2c17ad

Please sign in to comment.