From 60f5df1a80c63d850cf8bf3c423644e672024ff7 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Fri, 29 Apr 2016 13:17:59 +0800 Subject: [PATCH 01/10] set cgo as the default DNS resovler --- Deploy/docker-compose.yml | 2 ++ Deploy/templates/ui/env | 1 + 2 files changed, 3 insertions(+) diff --git a/Deploy/docker-compose.yml b/Deploy/docker-compose.yml index 2e9147ee1..2dc09b620 100644 --- a/Deploy/docker-compose.yml +++ b/Deploy/docker-compose.yml @@ -11,6 +11,8 @@ services: volumes: - /data/registry:/storage - ./config/registry/:/etc/registry/ + environment: + - GODEBUG=netdns=cgo ports: - 5001:5001 command: diff --git a/Deploy/templates/ui/env b/Deploy/templates/ui/env index 383e5f15a..d21e8fafc 100644 --- a/Deploy/templates/ui/env +++ b/Deploy/templates/ui/env @@ -12,3 +12,4 @@ LDAP_URL=$ldap_url LDAP_BASE_DN=$ldap_basedn SELF_REGISTRATION=$self_registration LOG_LEVEL=debug +GODEBUG=netdns=cgo From 2a461ee53e9b8ea790008374ba98b3e21e1d6bea Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Mon, 2 May 2016 20:58:50 -0700 Subject: [PATCH 02/10] update API for creating user, updating password and comment post return. --- docs/swagger.yaml | 94 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 404a0b431..588565b55 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -109,7 +109,7 @@ paths: tags: - Products responses: - 200: + 201: description: Project created successfully. 400: description: Unsatisfied with constraints of the project creation. @@ -383,6 +383,56 @@ paths: description: User does not have permission of admin role. 500: description: Unexpected internal errors. + post: + summary: Creates a new user account. + description: | + This endpoint is to create a user if the user does not already exist. + parameters: + - name: username + in: body + type: string + format: string + required: true + description: The username of the new created user. Maximum of 20 + characters. + - name: password + in: body + type: string + format: string + required: true + description: The password of the new created user. Maximum of 20 + characters. + - name: email + in: body + type: string + format: string + required: true + description: Publicly visible email address of the new created user. + - name: realname + in: body + type: string + format: string + required: true + description: Full name associated with the new created user. + Maximum of 20 characters. + - name: comment + in: body + type: string + format: string + required: false + description: Comments associated with the new created user. + Maximum of 30 characters. + tags: + - Products + responses: + 201: + description: User created successfully. + 400: + description: Unsatisfied with constraints of the user creation. + 403: + description: User registration can only be used by admin role user when self-registration is off. + 500: + description: Unexpected internal errors. /users/{user_id}: put: summary: Update a registered user to change to be an administrator of Harbor. @@ -438,6 +488,48 @@ paths: description: User ID does not exist. 500: description: Unexpected internal errors. + /users/{user_id}/password: + put: + summary: Change the password on a user that already exists. + description: | + This endpoint is for user to update password. Users with the admin + role can change any user's password. Guest users can change only + their own password. + parameters: + - name: user_id + in: path + type: integer + format: int32 + required: true + description: Registered user ID. + parameters: + - name: old_password + in: body + type: string + format: string + required: true + description: The user's existing password. + parameters: + - name: new_password + in: body + type: string + format: string + required: true + description: New password for marking as to be updated. + tags: + - Products + responses: + 200: + description: Updated password successfully. + 400: + description: Invalid user ID; Old password is blank; New password + is blank. + 401: + description: Old password is not correct. + 403: + description: Guests can only change their own account. + 500: + description: Unexpected internal errors. /repositories: get: summary: Get repositories accompany with relevant project and repo name. From ff429234015fc440d98939f3f18ae5e6dab5a80c Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Mon, 2 May 2016 21:05:06 -0700 Subject: [PATCH 03/10] update API for creating user, updating password and comment post return. --- docs/swagger.yaml | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 588565b55..aeb95ea92 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -393,15 +393,13 @@ paths: type: string format: string required: true - description: The username of the new created user. Maximum of 20 - characters. + description: The username of the new created user. Maximum of 20 characters. - name: password in: body type: string format: string required: true - description: The password of the new created user. Maximum of 20 - characters. + description: The password of the new created user. Maximum of 20 characters. - name: email in: body type: string @@ -413,15 +411,13 @@ paths: type: string format: string required: true - description: Full name associated with the new created user. - Maximum of 20 characters. + description: Full name associated with the new created user. Maximum of 20 characters. - name: comment in: body type: string format: string required: false - description: Comments associated with the new created user. - Maximum of 30 characters. + description: Comments associated with the new created user. Maximum of 30 characters. tags: - Products responses: @@ -522,8 +518,7 @@ paths: 200: description: Updated password successfully. 400: - description: Invalid user ID; Old password is blank; New password - is blank. + description: Invalid user ID; Old password is blank; New password is blank. 401: description: Old password is not correct. 403: From 73fe2a30d6b50e87ec3792cbb9da9543c588e728 Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Mon, 2 May 2016 22:43:50 -0700 Subject: [PATCH 04/10] remove duplicate parameters lines. --- docs/swagger.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index aeb95ea92..8c648819f 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -498,14 +498,12 @@ paths: format: int32 required: true description: Registered user ID. - parameters: - name: old_password in: body type: string format: string required: true description: The user's existing password. - parameters: - name: new_password in: body type: string From 83ba19516647e7be55a560ed0034f3a587f04aed Mon Sep 17 00:00:00 2001 From: hmwenchen Date: Tue, 3 May 2016 16:54:01 +0800 Subject: [PATCH 05/10] Add unit test for AccessLog --- dao/accesslog.go | 8 +++++++ dao/dao_test.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/dao/accesslog.go b/dao/accesslog.go index dbf447353..908fb9280 100644 --- a/dao/accesslog.go +++ b/dao/accesslog.go @@ -62,6 +62,14 @@ func GetAccessLogs(accessLog models.AccessLog) ([]models.AccessLog, error) { sql += ` and u.username like ? ` queryParam = append(queryParam, accessLog.Username) } + if accessLog.RepoName != "" { + sql += ` and a.repo_name = ? ` + queryParam = append(queryParam, accessLog.RepoName) + } + if accessLog.RepoTag != "" { + sql += ` and a.repo_tag = ? ` + queryParam = append(queryParam, accessLog.RepoTag) + } if accessLog.Keywords != "" { sql += ` and a.operation in ( ` keywordList := strings.Split(accessLog.Keywords, "/") diff --git a/dao/dao_test.go b/dao/dao_test.go index da0ad6993..99ece3348 100644 --- a/dao/dao_test.go +++ b/dao/dao_test.go @@ -102,6 +102,8 @@ func clearUp(username string) { const username string = "Tester01" const projectName string = "test_project" +const repoTag string = "test1.1" +const repoTag2 string = "test1.2" const SysAdmin int = 1 const projectAdmin int = 2 const developer int = 3 @@ -419,6 +421,66 @@ func TestGetAccessLog(t *testing.T) { } } +func TestAddAccessLog(t *testing.T) { + var err error + var accessLogList []models.AccessLog + accessLog := models.AccessLog{ + UserID: currentUser.UserID, + ProjectID: currentProject.ProjectID, + RepoName: currentProject.Name + "/", + RepoTag: repoTag, + GUID: "N/A", + Operation: "create", + OpTime: time.Now(), + } + err = AddAccessLog(accessLog) + if err != nil { + t.Errorf("Error occurred in AddAccessLog: %v", err) + } + accessLogList, err = GetAccessLogs(accessLog) + if err != nil { + t.Errorf("Error occurred in GetAccessLog: %v", err) + } + if len(accessLogList) != 1 { + t.Errorf("The length of accesslog list should be 1, actual: %d", len(accessLogList)) + } + if accessLogList[0].RepoName != projectName+"/" { + t.Errorf("The project name does not match, expected: %s, actual: %s", projectName+"/", accessLogList[0].RepoName) + } + if accessLogList[0].RepoTag != repoTag { + t.Errorf("The repo tag does not match, expected: %s, actual: %s", repoTag, accessLogList[0].RepoTag) + } +} + +func TestAccessLog(t *testing.T) { + var err error + var accessLogList []models.AccessLog + accessLog := models.AccessLog{ + UserID: currentUser.UserID, + ProjectID: currentProject.ProjectID, + RepoName: currentProject.Name + "/", + RepoTag: repoTag2, + Operation: "create", + } + err = AccessLog(currentUser.Username, currentProject.Name, currentProject.Name+"/", repoTag2, "create") + if err != nil { + t.Errorf("Error occurred in AccessLog: %v", err) + } + accessLogList, err = GetAccessLogs(accessLog) + if err != nil { + t.Errorf("Error occurred in GetAccessLog: %v", err) + } + if len(accessLogList) != 1 { + t.Errorf("The length of accesslog list should be 1, actual: %d", len(accessLogList)) + } + if accessLogList[0].RepoName != projectName+"/" { + t.Errorf("The project name does not match, expected: %s, actual: %s", projectName+"/", accessLogList[0].RepoName) + } + if accessLogList[0].RepoTag != repoTag2 { + t.Errorf("The repo tag does not match, expected: %s, actual: %s", repoTag2, accessLogList[0].RepoTag) + } +} + func TestProjectExists(t *testing.T) { var exists bool var err error From c7da848dd592d421022ef58e1ff3eb59474d110c Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Tue, 3 May 2016 18:27:07 -0700 Subject: [PATCH 06/10] pass on the swagger editor check. --- docs/swagger.yaml | 61 +++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 8c648819f..88bbb78ec 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -388,36 +388,12 @@ paths: description: | This endpoint is to create a user if the user does not already exist. parameters: - - name: username + - name: user in: body - type: string - format: string + description: New created user. required: true - description: The username of the new created user. Maximum of 20 characters. - - name: password - in: body - type: string - format: string - required: true - description: The password of the new created user. Maximum of 20 characters. - - name: email - in: body - type: string - format: string - required: true - description: Publicly visible email address of the new created user. - - name: realname - in: body - type: string - format: string - required: true - description: Full name associated with the new created user. Maximum of 20 characters. - - name: comment - in: body - type: string - format: string - required: false - description: Comments associated with the new created user. Maximum of 30 characters. + schema: + $ref: '#/definitions/User' tags: - Products responses: @@ -488,9 +464,7 @@ paths: put: summary: Change the password on a user that already exists. description: | - This endpoint is for user to update password. Users with the admin - role can change any user's password. Guest users can change only - their own password. + This endpoint is for user to update password. Users with the admin role can change any user's password. Guest users can change only their own password. parameters: - name: user_id in: path @@ -498,18 +472,12 @@ paths: format: int32 required: true description: Registered user ID. - - name: old_password + - name: password in: body - type: string - format: string + description: New updated password. required: true - description: The user's existing password. - - name: new_password - in: body - type: string - format: string - required: true - description: New password for marking as to be updated. + schema: + $ref: '#/definitions/Password' tags: - Products responses: @@ -522,7 +490,7 @@ paths: 403: description: Guests can only change their own account. 500: - description: Unexpected internal errors. + description: Unexpected internal errors. /repositories: get: summary: Get repositories accompany with relevant project and repo name. @@ -725,6 +693,15 @@ definitions: deleted: type: integer format: int32 + Password: + type: object + properties: + old_password: + type: string + description: The user's existing password. + new_password: + type: string + description: New password for marking as to be updated. AccessLog: type: object properties: From f4f716ad31c3918a1f54593404612d56798951bd Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Tue, 3 May 2016 18:39:37 -0700 Subject: [PATCH 07/10] pass on the swagger editor check. --- docs/swagger.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 88bbb78ec..98bc392b1 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -474,7 +474,7 @@ paths: description: Registered user ID. - name: password in: body - description: New updated password. + description: Password for updating. required: true schema: $ref: '#/definitions/Password' From 36160ea64c441cd7ae7e7963275c242f1e7df4a0 Mon Sep 17 00:00:00 2001 From: Tan Jiang Date: Wed, 4 May 2016 14:18:52 +0800 Subject: [PATCH 08/10] bump to golang 1.6.2 image to fix compilation error --- Dockerfile.ui | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile.ui b/Dockerfile.ui index 459158279..c5b087bd3 100644 --- a/Dockerfile.ui +++ b/Dockerfile.ui @@ -1,4 +1,4 @@ -FROM golang:1.5.1 +FROM golang:1.6.2 MAINTAINER jiangd@vmware.com @@ -11,7 +11,6 @@ COPY . /go/src/github.com/vmware/harbor COPY ./vendor/golang.org /go/src/golang.org WORKDIR /go/src/github.com/vmware/harbor/ui -ENV GO15VENDOREXPERIMENT 1 RUN go get -d github.com/docker/distribution \ && go get -d github.com/docker/libtrust \ && go get -d github.com/go-sql-driver/mysql \ From a5cb8e16eb277af3d6f4431a3a1a9f161ddf4e1e Mon Sep 17 00:00:00 2001 From: Tan Jiang Date: Wed, 4 May 2016 14:25:54 +0800 Subject: [PATCH 09/10] bump up go version in travis.yml --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e536c507..aff9e1f81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,14 @@ language: go go: - - 1.5.3 + - 1.6.2 go_import_path: github.com/vmware/harbor service: - mysql -env: GO15VENDOREXPERIMENT=1 DB_HOST=127.0.0.1 DB_PORT=3306 DB_USR=root DB_PWD= +env: DB_HOST=127.0.0.1 DB_PORT=3306 DB_USR=root DB_PWD= install: - sudo apt-get update && sudo apt-get install -y libldap2-dev From b68f2e1d224102df041110d1db7eed03c8c31acb Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Tue, 3 May 2016 23:43:37 -0700 Subject: [PATCH 10/10] pass on the swagger parser check. --- docs/swagger.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 98bc392b1..20307cc49 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -474,7 +474,7 @@ paths: description: Registered user ID. - name: password in: body - description: Password for updating. + description: Password to be updated. required: true schema: $ref: '#/definitions/Password'