Skip to content

Commit c7d7047

Browse files
author
Michel Casabianca
committed
Release 1.4.0: Added HTTPS support
2 parents 4f802b1 + e430c4b commit c7d7047

10 files changed

+82
-27
lines changed

Diff for: CHANGELOG.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Semantic changelog: https://github.com/c4s4/changelog
22

3+
- version: 1.4.0
4+
date: 2015-07-30
5+
summary: Added HTTPS support
6+
37
- version: 1.3.1
48
date: 2015-07-29
59
summary: Improved documentation

Diff for: README.md

+35-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ CheeseShop is a Python package repository. This is a local version of the well-k
99
To tell PIP where is your private CheeseShop, you must edit you *~/.pip/pip.conf* file:
1010

1111
[global]
12-
index-url = http://my.shop.host:8000/simple
12+
index-url = http://my.shop.host/simple
13+
trusted-host = my.shop.host
1314

1415
Where *my.shop.host* is the hostname of the machine running CheeseShop. PIP will call your CheeseShop to get packages. If CheeseShop doesn't host this package it will redirect PIP to standard Pypi.
1516

@@ -27,14 +28,16 @@ To tell *setup.py* where to upload your package, you must edit file *~/.pypirc*:
2728
[cheeseshop]
2829
username: spam
2930
password: foo
30-
repository: http://my.shop.host:8000/simple/
31+
repository: http://my.shop.host/simple/
3132

32-
*setup.py* will call your CheeseShop if you tell it to use *cheeseshop* connection with following command line:
33+
*setup.py* will call your CheeseShop if you name it on command line:
3334

3435
$ python setup.py sdist upload -r cheeseshop
3536

3637
Where `-r cheeseshop` is the option that indicates the connection you want to use. There must be a corresponding entry in your *~/.pypirc* configuration file. Don't forget to add *cheeseshop* in the *index-server* list at the beginning of the file.
3738

39+
CheeseShop is able to run on HTTP and/or HTTPS and performs basic authentication if necessary.
40+
3841
Installation
3942
------------
4043

@@ -67,14 +70,20 @@ You may also pass the path to the configuration file on the command line:
6770

6871
This configuration file should look like this:
6972

70-
# The port CheeseShop is listening
71-
port: 8000
72-
# The URL path
73-
path: simple
7473
# The root directory for packages
75-
root: repo
74+
root: /home/cheeseshop
75+
# Path to the server certificate
76+
cert: /etc/ssl/certs/cheeseshop-cert.pem
77+
# Path to the server key
78+
key: /etc/ssl/private/cheeseshop-key.pem
79+
# The HTTP port CheeseShop is listening
80+
http: 80
81+
# The HTTPS port CheeseShop is listening
82+
https: 443
83+
# The URL path
84+
path: simple
7685
# Redirection when not found
77-
shop: http://pypi.python.org/simple
86+
shop: http://pypi.python.org/simple
7887
# List of users and their MD5 hashed password
7988
# To get MD5 sum for password foo, type 'echo -n foo | md5sum'
8089
# To disable auth when uploading packages, set auth to ~
@@ -91,6 +100,22 @@ To compute MD5 sum for a given password, in order to fill the authentication fil
91100

92101
There is a sample configuration file in *etc* directory of the archive.
93102

103+
Of course, you must create an empty directory for the repository. Ensure that the user running CheeseShop has a right to write in this directory.
104+
105+
To disable HTTP or HTTPS, you must set port to *0*. If HTTPS is disabled, you don't have to set certificate and key paths. To disable basic authentication, you must set auth to `~` (which means none in YAML).
106+
107+
To generate a key, you can use openssl as follows:
108+
109+
$ openssl genrsa -out cheeseshop-key.pem 2048
110+
111+
To generate au self signed certificate, you can type:
112+
113+
$ openssl req -new -x509 -key cheeseshop-key.pem -out cheeseshop-cert.pem -days 3650
114+
115+
This command will ask you many fields, but the only that is necessary is the *FQDN* which is the hostname of the machine that is running CheeseShop.
116+
117+
You should copy the certificate in directory */etc/ssl/certs* and the key in */etc/ssl/private*.
118+
94119
Service
95120
-------
96121

@@ -125,7 +150,7 @@ To build CheeseShop, you must install [Goyaml](https://github.com/go-yaml/yaml) a
125150
$ go get github.com/mitchellh/gox
126151
$ gox -build-toolchain
127152

128-
Then you can use the make file to build the binary version for your platform:
153+
Then you can use the makefile to build the binary version for your platform:
129154

130155
$ make build
131156

Diff for: cheeseshop.go

+31-11
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ const (
2424
var DEFAULT_CONFIG = []string{"~/.cheeseshop.yml", "/etc/cheeseshop.yml"}
2525

2626
type Config struct {
27-
Port int
28-
Path string
29-
Root string
30-
Shop string
31-
Auth map[string]string
27+
Http int
28+
Https int
29+
Path string
30+
Root string
31+
Shop string
32+
Cert string
33+
Key string
34+
Auth map[string]string
3235
}
3336

3437
var config Config
@@ -206,17 +209,34 @@ func checkConfig() {
206209
if !strings.HasSuffix(config.Path, "/") {
207210
config.Path = config.Path + "/"
208211
}
209-
if config.Port > 65535 || config.Port < 0 {
210-
log.Fatalf("Bad port number %d", config.Port)
212+
if config.Http > 65535 || config.Http < 0 {
213+
log.Fatalf("Bad HTTP port number %d", config.Http)
214+
}
215+
if config.Https > 65535 || config.Https < 0 {
216+
log.Fatalf("Bad HTTPS port number %d", config.Https)
217+
}
218+
if config.Http == 0 && config.Https == 0 {
219+
log.Fatal("At least one of HTTP or HTTPS must be enabled")
211220
}
212221
}
213222

214223
func main() {
215224
loadConfig()
216225
checkConfig()
226+
log.Printf("Starting CheeseShop (ports: %d & %d, path: %s, root: %s, shop: %s)",
227+
config.Http, config.Https, config.Path, config.Root, config.Shop)
217228
http.HandleFunc(config.Path, handler)
218-
log.Printf("Starting CheeseShop (port: %d, path: %s, root: %s, shop: %s)",
219-
config.Port, config.Path, config.Root, config.Shop)
220-
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", config.Port), nil))
221-
log.Print("Stopping CheeseShop")
229+
if config.Http != 0 {
230+
go func() {
231+
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", config.Http), nil))
232+
}()
233+
}
234+
if config.Https != 0 {
235+
go func() {
236+
log.Fatal(http.ListenAndServeTLS(fmt.Sprintf(":%d", config.Https),
237+
normalizeFile(config.Cert), normalizeFile(config.Key), nil))
238+
}()
239+
}
240+
wait := make(chan bool, 1)
241+
<-wait
222242
}

Diff for: etc/cheeseshop.yml

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
# The port CheeseShop is listening
2-
port: 8000
3-
# The URL path
4-
path: simple
51
# The root directory for packages
6-
root: repo
2+
root: /home/cheeseshop
3+
# Path to the server certificate
4+
cert: /etc/ssl/certs/cheeseshop-cert.pem
5+
# Path to the server key
6+
key: /etc/ssl/private/cheeseshop-key.pem
7+
# The HTTP port CheeseShop is listening
8+
http: 80
9+
# The HTTPS port CheeseShop is listening
10+
https: 443
11+
# The URL path
12+
path: simple
713
# Redirection when not found
8-
shop: http://pypi.python.org/simple
14+
shop: http://pypi.python.org/simple
915
# List of users and their MD5 hashed password
1016
# To get MD5 sum for password foo, type 'echo -n foo | md5sum'
1117
# To disable auth when uploading packages, set auth to ~

Diff for: repo/eggs/eggs-1.0.0.tar.gz

-134 Bytes
Binary file not shown.

Diff for: repo/eggs/eggs-2.0.0.tar.gz

-134 Bytes
Binary file not shown.

Diff for: repo/eggs/eggs-3.0.0.tar.gz

-134 Bytes
Binary file not shown.

Diff for: repo/spam/spam-1.0.0.tar.gz

-134 Bytes
Binary file not shown.

Diff for: repo/spam/spam-2.0.0.tar.gz

-134 Bytes
Binary file not shown.

Diff for: repo/spam/spam-3.0.0.tar.gz

-134 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)