-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from mittwald/feature/system_client_gc
add system client
- Loading branch information
Showing
13 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package harbor | |
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/parnurzeal/gorequest" | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package harbor | |
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/parnurzeal/gorequest" | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters