Skip to content

Commit 8341dd3

Browse files
author
Michel Casabianca
committed
Release 1.4.2: Added configuration field overwrite
2 parents 7e01a66 + 06c5eeb commit 8341dd3

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

Diff for: CHANGELOG.yml

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

3+
- version: 1.4.2
4+
date: 2015-07-31
5+
summary: Added configuration field overwrite
6+
fixed:
7+
- "Added configuration field *overwrite* to tell if we can overwrite an
8+
existing package."
9+
310
- version: 1.4.1
411
date: 2015-07-30
512
summary: Improved documentation

Diff for: README.md

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ The configuration file should look like this:
8787
path: simple
8888
# Redirection when not found
8989
shop: http://pypi.python.org/simple
90+
# Tells if we can overwrite an existing package
91+
overwrite: false
9092
# List of users and their MD5 hashed password
9193
# To get MD5 sum for password foo, type 'echo -n foo | md5sum'
9294
# To disable auth when uploading packages, set auth to ~
@@ -149,6 +151,10 @@ This is the URL path that the server will listen. Default value is *simple*, thu
149151

150152
This is the URL of the public package repository, aka <http://pypi.python.org/simple>. This should not be changed.
151153

154+
### overwrite
155+
156+
Tells if we can overwrite an existing package while uploading (with `setup.py upload`). If set to *false* (the default value), you must upload the package manually on the server to amend a release (which is **not** advisable), and an attempt will result in a status code *400*. If set to true, it is possible to overwrite a package.
157+
152158
### auth
153159

154160
This is the basic authentication configuration. If you don't want authentication, set this value to *~*. This is a list of usernames and MD5 hash of their password. To get the MD5 hash of a given password, you can type following command:

Diff for: cheeseshop.go

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

2626
type Config struct {
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
27+
Http int
28+
Https int
29+
Path string
30+
Root string
31+
Shop string
32+
Cert string
33+
Key string
34+
Overwrite bool
35+
Auth map[string]string
3536
}
3637

3738
var config Config
@@ -107,6 +108,12 @@ func copyFile(w http.ResponseWriter, r *http.Request) {
107108
name := file.Filename
108109
pack := name[:strings.LastIndex(name, "-")]
109110
dir := filepath.Join(config.Root, pack)
111+
path := filepath.Join(config.Root, pack, name)
112+
if _, err := os.Stat(path); err == nil && !config.Overwrite {
113+
log.Printf("Failed attempt to overwrite package %s", name)
114+
http.Error(w, fmt.Sprintf("Package %s already exists", name), http.StatusBadRequest)
115+
return
116+
}
110117
if _, err := os.Stat(dir); os.IsNotExist(err) {
111118
err = os.Mkdir(dir, 0777)
112119
if err != nil {
@@ -123,7 +130,7 @@ func copyFile(w http.ResponseWriter, r *http.Request) {
123130
http.Error(w, err.Error(), http.StatusInternalServerError)
124131
return
125132
}
126-
dst, err := os.Create(filepath.Join(config.Root, pack, name))
133+
dst, err := os.Create(path)
127134
defer dst.Close()
128135
if err != nil {
129136
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -223,8 +230,8 @@ func checkConfig() {
223230
func main() {
224231
loadConfig()
225232
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)
233+
log.Printf("Starting CheeseShop (ports: %d & %d, path: %s, root: %s, shop: %s, cert: %s, key: %s, overwrite: %t)",
234+
config.Http, config.Https, config.Path, config.Root, config.Shop, config.Cert, config.Key, config.Overwrite)
228235
http.HandleFunc(config.Path, handler)
229236
if config.Http != 0 {
230237
go func() {

Diff for: etc/cheeseshop.yml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ https: 443
1212
path: simple
1313
# Redirection when not found
1414
shop: http://pypi.python.org/simple
15+
# Tells if we can overwrite an existing package
16+
overwrite: false
1517
# List of users and their MD5 hashed password
1618
# To get MD5 sum for password foo, type 'echo -n foo | md5sum'
1719
# To disable auth when uploading packages, set auth to ~

0 commit comments

Comments
 (0)