Skip to content

Commit

Permalink
Merge pull request #18 from mittwald/feature/system_client_gc
Browse files Browse the repository at this point in the history
add system client
  • Loading branch information
jkmw authored May 14, 2020
2 parents f8cfc2a + a541bee commit ec64667
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 9 deletions.
7 changes: 6 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package harbor

import (
"fmt"
"github.com/parnurzeal/gorequest"
"net/url"
"strings"

"github.com/parnurzeal/gorequest"
)

const (
Expand Down Expand Up @@ -130,3 +131,7 @@ func (c *Client) Registries() *RegistryClient {
func (c *Client) Replications() *ReplicationClient {
return &ReplicationClient{c.withURLSuffix("replication")}
}

func (c *Client) System() *SystemClient {
return &SystemClient{c.withURLSuffix("system")}
}
3 changes: 2 additions & 1 deletion harbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package harbor

import (
"fmt"
"github.com/parnurzeal/gorequest"
"strconv"

"github.com/parnurzeal/gorequest"
)

type StatusCodeError struct {
Expand Down
3 changes: 2 additions & 1 deletion project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package harbor

import (
"fmt"
"github.com/parnurzeal/gorequest"
"net/url"

"github.com/parnurzeal/gorequest"
)

// ProjectClient handles communication with the project related methods of the Harbor API.
Expand Down
2 changes: 1 addition & 1 deletion project_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "time"

// To ensure type-safe queries to the harbor API,
// the following typings include typings from the upstream sources:
// https://github.com/goharbor/harbor/src/common/models/
// https://github.com/goharbor/harbor/tree/v1.10.2/src/common/models

// AccessLog holds the information of log entries
type AccessLog struct {
Expand Down
1 change: 1 addition & 0 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package harbor

import (
"fmt"

"github.com/parnurzeal/gorequest"
)

Expand Down
2 changes: 1 addition & 1 deletion registry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "time"

// To ensure type-safe queries to the harbor API,
// the following typings include typings from the upstream sources:
// https://github.com/goharbor/harbor/src/replication/dao/models/
// https://github.com/goharbor/harbor/tree/v1.10.2/src/replication/dao/models/

// const definition
const (
Expand Down
2 changes: 1 addition & 1 deletion replication_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "time"

// To ensure type-safe queries to the harbor API,
// the following typings include typings from the upstream sources:
// https://github.com/goharbor/harbor/src/replication/dao/models/
// https://github.com/goharbor/harbor/tree/v1.10.2/src/replication/dao/models/

// ReplicationExecution holds information about one replication execution.
type ReplicationExecution struct {
Expand Down
3 changes: 2 additions & 1 deletion repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package harbor

import (
"fmt"
"github.com/parnurzeal/gorequest"
"net/url"

"github.com/parnurzeal/gorequest"
)

// RepositoryClient handles communication with the repository related methods of the Harbor API
Expand Down
2 changes: 1 addition & 1 deletion repository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

// To ensure type-safe queries to the harbor API,
// the following typings include typings from the upstream sources:
// https://github.com/goharbor/harbor/src/common/models/
// https://github.com/goharbor/harbor/tree/v1.10.2/src/common/models

// Label holds information used for a label
type Label struct {
Expand Down
35 changes: 35 additions & 0 deletions system.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package harbor

import "github.com/parnurzeal/gorequest"

// SystemClient handles communication with the system related methods of the Harbor API
type SystemClient struct {
*Client
}

// GetSystemGarbageCollection
// Get the system's configured garbage collection schedule
func (s *SystemClient) GetSystemGarbageCollectionSchedule() (AdminJobReq, error) {
var gc AdminJobReq
resp, _, errs := s.NewRequest(gorequest.GET, "/gc/schedule").
EndStruct(&gc)
return gc, CheckResponse(errs, resp, 200)
}

// CreateSystemGarbageCollectionSchedule
// Create a garbage collection schedule for the system
func (s *SystemClient) CreateSystemGarbageCollectionSchedule(gc AdminJobReq) error {
resp, _, errs := s.NewRequest(gorequest.POST, "/gc/schedule").
Send(gc).
End()
return CheckResponse(errs, resp, 201)
}

// UpdateSystemGarbageCollectionSchedule
// Update the system's configured garbage collection schedule
func (s *SystemClient) UpdateSystemGarbageCollectionSchedule(gc AdminJobReq) error {
resp, _, errs := s.NewRequest(gorequest.PUT, "/gc/schedule").
Send(gc).
End()
return CheckResponse(errs, resp, 200)
}
39 changes: 39 additions & 0 deletions system_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package harbor

// To ensure type-safe queries to the harbor API,
// the following typings include typings from the upstream sources:
// https://github.com/goharbor/harbor/tree/v1.10.2/src/core/api/models

type ScheduleType string

const (
ScheduleTypeHourly ScheduleType = "Hourly"
ScheduleTypeDaily = "Daily"
ScheduleTypeWeekly = "Weekly"
ScheduleTypeCustom = "Custom"
ScheduleTypeManual = "Manual"
ScheduleTypeNone = "None"
)

// AdminJobReq holds request information for admin job
type AdminJobReq struct {
AdminJobSchedule
Name string `json:"name"`
Status string `json:"status"`
ID int64 `json:"id"`
Parameters map[string]interface{} `json:"parameters"`
}

// AdminJobSchedule holds the information of an admin job schedule
type AdminJobSchedule struct {
Schedule *ScheduleParam `json:"schedule"`
}

// ScheduleParam defines the parameters of a schedule trigger
type ScheduleParam struct {
// Daily, Hourly, Weekly, Custom, Manual, None
// Note: When creating pre-defined schedule types (e.g. 'Hourly'), the Cron string has to be provided.
Type ScheduleType `json:"type"`
// The cron string of scheduled job
Cron string `json:"cron"`
}
1 change: 1 addition & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package harbor

import (
"fmt"

"github.com/parnurzeal/gorequest"
)

Expand Down
2 changes: 1 addition & 1 deletion user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "time"

// To ensure type-safe queries to the harbor API,
// the following typings include typings from the upstream sources:
// https://github.com/goharbor/harbor/src/common/models/
// https://github.com/goharbor/harbor/tree/v1.10.2/src/common/models

// User holds the details of a user.
type User struct {
Expand Down

0 comments on commit ec64667

Please sign in to comment.