Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2020-07-13 10:31:14 +0300
committerJaime Martinez <jmartinez@gitlab.com>2020-07-24 07:49:29 +0300
commit017bb1b79c7a9d9ccd45f831ad656c6f230f7839 (patch)
treef236e269045dfe9e796a2bc1282a5fe4c2c6485b /internal/source/gitlab/client/client.go
parent7e2600ea4ad6a8ef2d19c07eadb8c7aa7b8c65e2 (diff)
Add Status to GitLab client
Diffstat (limited to 'internal/source/gitlab/client/client.go')
-rw-r--r--internal/source/gitlab/client/client.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/source/gitlab/client/client.go b/internal/source/gitlab/client/client.go
index 3a805ce9..51e7eca0 100644
--- a/internal/source/gitlab/client/client.go
+++ b/internal/source/gitlab/client/client.go
@@ -18,6 +18,11 @@ import (
"gitlab.com/gitlab-org/gitlab-pages/metrics"
)
+// ConnectionErrorMsg to be returned with `gc.Status` if Pages
+// fails to connect to the internal GitLab API, times out
+// or a 401 given that the credentials used are wrong
+const ConnectionErrorMsg = "failed to connect to internal Pages API"
+
// Client is a HTTP client to access Pages internal API
type Client struct {
secretKey []byte
@@ -100,6 +105,19 @@ func (gc *Client) GetLookup(ctx context.Context, host string) api.Lookup {
return lookup
}
+// Status checks that Pages can reach the rails internal Pages API
+// for source domain configuration.
+// Timeout is the same as -gitlab-client-http-timeout
+func (gc *Client) Status() error {
+ resp, err := gc.get(context.Background(), "/api/v4/internal/pages/status", url.Values{})
+ if err != nil {
+ return fmt.Errorf("%s: %v", ConnectionErrorMsg, err)
+ }
+ defer resp.Body.Close()
+
+ return nil
+}
+
func (gc *Client) get(ctx context.Context, path string, params url.Values) (*http.Response, error) {
endpoint, err := gc.endpoint(path, params)
if err != nil {