Пример #1
0
func RegisterRunner(url, token, description, tags string) *RegisterRunnerResponse {
	// TODO: pass executor
	request := RegisterRunnerRequest{
		Info:        GetRunnerVersion(RunnerConfig{}),
		Token:       token,
		Description: description,
		Tags:        tags,
	}

	var response RegisterRunnerResponse
	result, statusText := postJSON(getURL(url, "runners/register.json"), 201, &request, &response)
	shortToken := helpers.ShortenToken(token)

	switch result {
	case 201:
		log.Println(shortToken, "Registering runner...", "succeeded")
		return &response
	case 403:
		log.Errorln(shortToken, "Registering runner...", "forbidden (check registration token)")
		return nil
	default:
		log.Errorln(shortToken, "Registering runner...", "failed", statusText)
		return nil
	}
}
Пример #2
0
func (n *GitLabClient) RegisterRunner(runner RunnerCredentials, description, tags string) *RegisterRunnerResponse {
	// TODO: pass executor
	request := RegisterRunnerRequest{
		Info:        n.getRunnerVersion(RunnerConfig{}),
		Token:       runner.Token,
		Description: description,
		Tags:        tags,
	}

	var response RegisterRunnerResponse
	result, statusText := n.do(runner, "POST", "runners/register.json", 201, &request, &response)
	shortToken := helpers.ShortenToken(runner.Token)

	switch result {
	case 201:
		logrus.Println(shortToken, "Registering runner...", "succeeded")
		return &response
	case 403:
		logrus.Errorln(shortToken, "Registering runner...", "forbidden (check registration token)")
		return nil
	case clientError:
		logrus.Errorln(shortToken, "Registering runner...", "error", statusText)
		return nil
	default:
		logrus.Errorln(shortToken, "Registering runner...", "failed", statusText)
		return nil
	}
}
Пример #3
0
func (n *GitLabClient) VerifyRunner(runner RunnerCredentials) bool {
	request := VerifyRunnerRequest{
		Token: runner.Token,
	}

	// HACK: we use non-existing build id to check if receive forbidden or not found
	result, statusText := n.do(runner, "PUT", fmt.Sprintf("builds/%d", -1), 200, &request, nil)
	shortToken := helpers.ShortenToken(runner.Token)

	switch result {
	case 404:
		// this is expected due to fact that we ask for non-existing job
		logrus.Println(shortToken, "Veryfing runner...", "is alive")
		return true
	case 403:
		logrus.Errorln(shortToken, "Veryfing runner...", "is removed")
		return false
	case clientError:
		logrus.Errorln(shortToken, "Veryfing runner...", "error", statusText)
		return false
	default:
		logrus.Errorln(shortToken, "Veryfing runner...", "failed", statusText)
		return true
	}
}
Пример #4
0
func DeleteRunner(url, token string) bool {
	result, statusText := deleteJSON(getURL(url, "runners/delete?token=%v", token), 200, nil)
	shortToken := helpers.ShortenToken(token)

	switch result {
	case 200:
		log.Println(shortToken, "Deleting runner...", "succeeded")
		return true
	case 403:
		log.Errorln(shortToken, "Deleting runner...", "forbidden")
		return false
	default:
		log.Errorln(shortToken, "Deleting runner...", "failed", statusText)
		return false
	}
}
Пример #5
0
func VerifyRunner(url, token string) bool {
	result, statusText := putJSON(getURL(url, "builds/%v?token=%v", -1, token), 200, nil, nil)
	shortToken := helpers.ShortenToken(token)

	switch result {
	case 404:
		// this is expected due to fact that we ask for non-existing job
		log.Println(shortToken, "Veryfing runner...", "is alive")
		return true
	case 403:
		log.Errorln(shortToken, "Veryfing runner...", "is removed")
		return false
	default:
		log.Errorln(shortToken, "Veryfing runner...", "failed", statusText)
		return true
	}
}
Пример #6
0
func (n *GitLabClient) DeleteRunner(runner RunnerCredentials) bool {
	request := DeleteRunnerRequest{
		Token: runner.Token,
	}

	result, statusText := n.do(runner, "DELETE", "runners/delete", 200, &request, nil)
	shortToken := helpers.ShortenToken(runner.Token)

	switch result {
	case 200:
		logrus.Println(shortToken, "Deleting runner...", "succeeded")
		return true
	case 403:
		logrus.Errorln(shortToken, "Deleting runner...", "forbidden")
		return false
	case clientError:
		logrus.Errorln(shortToken, "Deleting runner...", "error", statusText)
		return false
	default:
		logrus.Errorln(shortToken, "Deleting runner...", "failed", statusText)
		return false
	}
}
func (c *RunnerConfig) ShortDescription() string {
	return helpers.ShortenToken(c.Token)
}