Skip to content

Commit

Permalink
feat: add replications trigger API
Browse files Browse the repository at this point in the history
  • Loading branch information
moooofly committed Oct 24, 2018
1 parent a665e0f commit 0753d6c
Showing 1 changed file with 63 additions and 0 deletions.
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)
}

0 comments on commit 0753d6c

Please sign in to comment.