Skip to content

Commit

Permalink
Merge branch 'release/v1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
moooofly committed Oct 24, 2018
2 parents 9c400e9 + cb6fc99 commit 3d851c2
Show file tree
Hide file tree
Showing 13 changed files with 596 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# customize

.cookie.yaml
harbor-go-client
harborctl*
*.tar.gz


Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<a name="1.0.0"></a>
# [1.0.0](https://github.com/moooofly/harbor-go-client/compare/v0.9.6...v1.0.0) (2018-10-24)


### Features

* add replications trigger API ([0753d6c](https://github.com/moooofly/harbor-go-client/commit/0753d6c))
* add syncregistry and email_ping APIs ([2b18258](https://github.com/moooofly/harbor-go-client/commit/2b18258))
* add usergroups APIs ([47ef550](https://github.com/moooofly/harbor-go-client/commit/47ef550))
* support both linux and darwin platform compilation ([a665e0f](https://github.com/moooofly/harbor-go-client/commit/a665e0f))
* support darwin platform, fix [#1](https://github.com/moooofly/harbor-go-client/issues/1) ([c671c20](https://github.com/moooofly/harbor-go-client/commit/c671c20))



<a name="0.9.6"></a>
# [0.9.6](https://github.com/moooofly/harbor-go-client/compare/v0.9.5...v0.9.6) (2018-10-17)

Expand Down
34 changes: 23 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ ifeq "$(GOPATH)" ""
$(error Please set the environment variable GOPATH before running `make`)
endif

GO := go
PKGS := $(shell $(GO) list ./... | grep -v vendor)
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
PKGS := $(shell go list ./... | grep -v vendor)


# NOTE: '-race' requires cgo; enable cgo by setting CGO_ENABLED=1
#BUILD_FLAG := -race
GOBUILD := CGO_ENABLED=0 $(GO) build $(BUILD_FLAG)
GOBUILD := CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build $(BUILD_FLAG)

LDFLAGS += -X "github.com/moooofly/harbor-go-client/utils.ClientVersion=$(shell cat VERSION)"
LDFLAGS += -X "github.com/moooofly/harbor-go-client/utils.GoVersion=$(shell go version)"
Expand All @@ -24,12 +27,12 @@ all: lint build test

build:
@echo "==> Building ..."
$(GOBUILD) -ldflags '$(LDFLAGS)' ./
$(GOBUILD) -o harborctl_${GOOS}_${GOARCH} -ldflags '$(LDFLAGS)' ./
@echo ""

install:
@echo "==> Installing ..."
$(GO) install -x ${SRC}
go install -x ${SRC}
@echo ""

lint:
Expand All @@ -43,19 +46,27 @@ lint:

test:
@echo "==> Testing ..."
$(GO) test -short -race $(PKGS)
go test -short -race $(PKGS)
@echo ""

pack: build
build_linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(BUILD_FLAG) -o harborctl_linux_amd64 -ldflags '$(LDFLAGS)' ./

build_darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAG) -o harborctl_darwin_amd64 -ldflags '$(LDFLAGS)' ./

pack: build_linux build_darwin
@echo "==> Packing ..."
@tar czvf $(shell cat VERSION)-bin.tar.gz harbor-go-client conf/*.yaml
@tar czvf harborctl-$(shell cat VERSION).linux-amd64.tar.gz harborctl_linux_amd64 conf/*.yaml
@echo ""
@rm harbor-go-client
@tar czvf harborctl-$(shell cat VERSION).darwin-amd64.tar.gz harborctl_darwin_amd64 conf/*.yaml
@echo ""
@rm harborctl_linux_amd64
@rm harborctl_darwin_amd64

docker:
@echo "==> Creating docker image ..."
docker build -t harbor-go-client:$(shell git rev-parse --short HEAD) .
docker build -t harborctl:$(shell git rev-parse --short HEAD) .
@echo ""

misspell:
Expand All @@ -73,7 +84,8 @@ shellcheck:

clean:
@echo "==> Cleaning ..."
$(GO) clean -x -i ${SRC}
go clean -x -i ${SRC}
rm -f harborctl_*
rm -rf *.out
rm -rf *.tar.gz
@echo ""
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Current Harbor API support status:
- [x] GET /api/labels/{id}
- [x] PUT /api/labels/{id}
- replications
- [ ] POST /api/replications
- [x] POST /api/replications
- targets
- [x] GET /api/targets
- [x] POST /api/targets
Expand All @@ -104,7 +104,7 @@ Current Harbor API support status:
- [x] PUT /api/targets/{id}
- [x] GET /api/targets/{id}/policies/
- internal
- [ ] POST /api/internal/syncregistry
- [x] POST /api/internal/syncregistry
- systeminfo
- [x] GET /api/systeminfo
- [x] GET /api/systeminfo/volumes
Expand All @@ -115,17 +115,17 @@ Current Harbor API support status:
- [ ] GET /api/ldap/users/search
- [ ] POST /api/ldap/users/import
- usergroups
- [ ] GET /api/usergroups
- [ ] POST /api/usergroups
- [ ] DELETE /api/usergroups/{group_id}
- [ ] GET /api/usergroups/{group_id}
- [ ] PUT /api/usergroups/{group_id}
- [x] GET /api/usergroups
- [x] POST /api/usergroups
- [x] DELETE /api/usergroups/{group_id}
- [x] GET /api/usergroups/{group_id}
- [x] PUT /api/usergroups/{group_id}
- configurations
- [x] GET /api/configurations
- [x] PUT /api/configurations
- [x] POST /api/configurations/reset
- email
- [ ] POST /api/email/ping
- [x] POST /api/email/ping


Additional features supported:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.9.6
1.0.0
118 changes: 116 additions & 2 deletions api/others.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,118 @@
package api

// POST /email/ping
// POST /internal/syncregistry
import (
"encoding/json"
"fmt"

"github.com/moooofly/harbor-go-client/utils"
)

func init() {
utils.Parser.AddCommand("syncregistry",
"Sync repositories from registry to DB.",
"This endpoint is for syncing all repositories of registry with database.",
&syncregistry)
utils.Parser.AddCommand("email_ping",
"Test connection and authentication with email server.",
"Test connection and authentication with email server.",
&emailping)
}

type syncRegistry struct {
}

var syncregistry syncRegistry

func (x *syncRegistry) Execute(args []string) error {
PostSyncRegistry(utils.URLGen("/api/internal/syncregistry"))
return nil
}

// PostSyncRegistry is for syncing all repositories of registry with database.
//
// params:
//
// format:
// POST /internal/syncregistry
//
// e.g. curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/plain' 'https://localhost/api/internal/syncregistry'
func PostSyncRegistry(baseURL string) {
targetURL := baseURL
fmt.Println("==> POST", targetURL)

// Read beegosessionID from .cookie.yaml
c, err := utils.CookieLoad()
if err != nil {
fmt.Println("Error:", err)
return
}

utils.Request.Post(targetURL).
Set("Cookie", "harbor-lang=zh-cn; beegosessionID="+c.BeegosessionID).
End(utils.PrintStatus)
}

type emailPing struct {
EmailHost string `short:"h" long:"email_host" description:"The host of email server." default:"smtp.mydomain.com" json:"email_host"`
EmailPort int `short:"t" long:"email_port" description:"The port of email server." default:"25" json:"email_port"`
EmailUsername string `short:"u" long:"email_username" description:"The username of email server." default:"sample_admin@mydomain.com" json:"email_username"`
EmailPassword string `short:"p" long:"email_password" description:"The password of email server." default:"" json:"email_password"`
EmailSsl bool `short:"s" long:"email_ssl" description:"Use ssl/tls or not." json:"email_ssl"`
EmailIdentity string `short:"i" long:"email_identity" description:"The identity of email server." default:"" json:"email_identity"`
}

var emailping emailPing

func (x *emailPing) Execute(args []string) error {
PostEmailPing(utils.URLGen("/api/email/ping"))
return nil
}

// PostEmailPing tests connection and authentication with email server.
//
// params:
// email_host - The host of email server.
// email_port - The port of email server.
// email_username - The username of email server.
// email_password - The password of email server.
// email_ssl - Use ssl/tls or not.
// email_identity - The dentity of email server.
//
// format:
// POST /email/ping
//
// e.g.
/*
curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/plain' -d '{ \
"email_host": "string", \
"email_port": 0, \
"email_username": "string", \
"email_password": "string", \
"email_ssl": true, \
"email_identity": "string" \
}' 'https://localhost/api/email/ping'
)*/
func PostEmailPing(baseURL string) {
targetURL := baseURL
fmt.Println("==> POST", targetURL)

// Read beegosessionID from .cookie.yaml
c, err := utils.CookieLoad()
if err != nil {
fmt.Println("Error:", err)
return
}

t, err := json.Marshal(&emailping)
if err != nil {
fmt.Println("error:", err)
return
}

fmt.Println("==> email ping:", string(t))

utils.Request.Post(targetURL).
Set("Cookie", "harbor-lang=zh-cn; beegosessionID="+c.BeegosessionID).
Send(string(t)).
End(utils.PrintStatus)
}
63 changes: 63 additions & 0 deletions api/replications.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package api

import (
"encoding/json"
"fmt"

"github.com/moooofly/harbor-go-client/utils"
)

func init() {
utils.Parser.AddCommand("replication_trigger_by_id",
"Trigger the replication according to the specified policy.",
"This endpoint is used to trigger a replication.",
&replTriByID)
}

type replicationTriByID struct {
PolicyID int `short:"i" long:"policy_id" description:"(REQUIRED) The ID of replication policy" required:"yes" json:"policy_id"`
}

var replTriByID replicationTriByID

func (x *replicationTriByID) Execute(args []string) error {
PostReplTriByID(utils.URLGen("/api/replications"))
return nil
}

// PostReplTriByID is used to trigger a replication.
//
// params:
// policy_id - (REQUIRED) The ID of replication policy
//
// format:
// POST /replications
//
// e.g.
/*
curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/plain' -d '{ \
"policy_id": 1 \
}' 'https://localhost/api/replications'
*/
func PostReplTriByID(baseURL string) {
targetURL := baseURL
fmt.Println("==> POST", targetURL)

// Read beegosessionID from .cookie.yaml
c, err := utils.CookieLoad()
if err != nil {
fmt.Println("Error:", err)
return
}

t, err := json.Marshal(&replTriByID)
if err != nil {
fmt.Println("error:", err)
return
}

utils.Request.Post(targetURL).
Set("Cookie", "harbor-lang=zh-cn; beegosessionID="+c.BeegosessionID).
Send(string(t)).
End(utils.PrintStatus)
}
Loading

0 comments on commit 3d851c2

Please sign in to comment.