summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-08-29 23:59:24 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-12-19 14:11:07 +0100
commitf8d74597781f9ac9bfe2dbe6b1feacb512a52ae8 (patch)
treec56080bafd452344b875a2a55424fd384b491d4b
parent5969bd068d8aa9b19e69c96c8644f821602b4c6e (diff)
downloadgitlab-shell-f8d74597781f9ac9bfe2dbe6b1feacb512a52ae8.tar.gz
WIP: Port GitlabNet API calls to go
-rw-r--r--go/internal/config/config.go23
-rw-r--r--go/internal/config/config_test.go27
-rw-r--r--go/internal/config/testdata/config.yml.example51
-rw-r--r--go/internal/gitlabclient/client.go40
4 files changed, 137 insertions, 4 deletions
diff --git a/go/internal/config/config.go b/go/internal/config/config.go
index 435cb29..d325fd4 100644
--- a/go/internal/config/config.go
+++ b/go/internal/config/config.go
@@ -2,6 +2,7 @@ package config
import (
"io/ioutil"
+ "net/url"
"os"
"path"
@@ -19,10 +20,12 @@ type MigrationConfig struct {
}
type Config struct {
- RootDir string
- LogFile string `yaml:"log_file"`
- LogFormat string `yaml:"log_format"`
- Migration MigrationConfig `yaml:"migration"`
+ RootDir string
+ LogFile string `yaml:"log_file"`
+ LogFormat string `yaml:"log_format"`
+ Migration MigrationConfig `yaml:"migration"`
+ GitlabUrl string `yaml:"gitlab_url"`
+ InternalApiUrl string
}
func New() (*Config, error) {
@@ -71,5 +74,17 @@ func parseConfig(configBytes []byte, cfg *Config) error {
cfg.LogFormat = "text"
}
+ baseUrl, err := url.Parse(cfg.GitlabUrl)
+ if err != nil {
+ return err
+ }
+
+ path, err := url.Parse("api/v4/internal")
+ if err != nil {
+ return err
+ }
+
+ cfg.InternalApiUrl = baseUrl.ResolveReference(path).String()
+
return nil
}
diff --git a/go/internal/config/config_test.go b/go/internal/config/config_test.go
index 87a582f..da09f67 100644
--- a/go/internal/config/config_test.go
+++ b/go/internal/config/config_test.go
@@ -2,6 +2,7 @@ package config
import (
"fmt"
+ "io/ioutil"
"strings"
"testing"
)
@@ -51,3 +52,29 @@ func TestParseConfig(t *testing.T) {
})
}
}
+
+func TestExampleFile(t *testing.T) {
+ content, err := ioutil.ReadFile("./testdata/config.yml.example")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ cfg := Config{}
+
+ err = parseConfig(content, &cfg)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ expected := Config{
+ RootDir: "",
+ LogFile: "gitlab-shell.log",
+ LogFormat: "text",
+ GitlabUrl: "http://localhost:8080",
+ InternalApiUrl: "http://localhost:8080/api/v4/internal",
+ }
+
+ if cfg != expected {
+ t.Fatalf("expected %v got %v", expected, cfg)
+ }
+}
diff --git a/go/internal/config/testdata/config.yml.example b/go/internal/config/testdata/config.yml.example
new file mode 100644
index 0000000..23743fd
--- /dev/null
+++ b/go/internal/config/testdata/config.yml.example
@@ -0,0 +1,51 @@
+#
+# If you change this file in a Merge Request, please also create
+# a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests
+#
+
+# GitLab user. git by default
+user: git
+
+# URL to GitLab instance, used for API calls. Default: http://localhost:8080.
+# For relative URL support read http://doc.gitlab.com/ce/install/relative_url.html
+# You only have to change the default if you have configured Unicorn
+# to listen on a custom port, or if you have configured Unicorn to
+# only listen on a Unix domain socket. For Unix domain sockets use
+# "http+unix://<urlquoted-path-to-socket>", e.g.
+# "http+unix://%2Fpath%2Fto%2Fsocket"
+gitlab_url: "http://localhost:8080"
+
+# See installation.md#using-https for additional HTTPS configuration details.
+http_settings:
+# read_timeout: 300
+# user: someone
+# password: somepass
+# ca_file: /etc/ssl/cert.pem
+# ca_path: /etc/pki/tls/certs
+ self_signed_cert: false
+
+# File used as authorized_keys for gitlab user
+auth_file: "/home/git/.ssh/authorized_keys"
+
+# File that contains the secret key for verifying access to GitLab.
+# Default is .gitlab_shell_secret in the gitlab-shell directory.
+# secret_file: "/home/git/gitlab-shell/.gitlab_shell_secret"
+
+# Parent directory for global custom hook directories (pre-receive.d, update.d, post-receive.d)
+# Default is hooks in the gitlab-shell directory.
+# custom_hooks_dir: "/home/git/gitlab-shell/hooks"
+
+# Log file.
+# Default is gitlab-shell.log in the root directory.
+# log_file: "/home/git/gitlab-shell/gitlab-shell.log"
+
+# Log level. INFO by default
+log_level: INFO
+
+# Log format. 'text' by default
+# log_format: json
+
+# Audit usernames.
+# Set to true to see real usernames in the logs instead of key ids, which is easier to follow, but
+# incurs an extra API call on every gitlab-shell command.
+audit_usernames: false
diff --git a/go/internal/gitlabclient/client.go b/go/internal/gitlabclient/client.go
new file mode 100644
index 0000000..c186b6c
--- /dev/null
+++ b/go/internal/gitlabclient/client.go
@@ -0,0 +1,40 @@
+package gitlabclient
+
+import (
+ "net/http"
+ "time"
+
+ "gitlab.com/gitlab-org/go/internal/config"
+)
+
+type Client struct {
+ config *config.Config
+ httpClient *http.Client
+}
+
+type DiscoverResponse struct {
+}
+
+func New() (*Client, error) {
+ config, err := config.New()
+ if err != nil {
+ return nil, err
+ }
+
+ tr = &http.Transport{
+ MaxIdleConns: 10,
+ IdleConnTimeout: 30 * time.Second,
+ DisableCompression: true,
+ }
+ httpClient = &http.Client{Transport: tr}
+
+ return &Client{config: config, httpClient: httpClient}, nil
+}
+
+func (c *Client) Discover(gitlabId string) {
+
+}
+
+func (c *Client) get(path string) (*Response, error) {
+
+}