Merge pull request #50 from giolekva/rest_user_service

Add rest router
diff --git a/.bazelrc b/.bazelrc
deleted file mode 100644
index 34d0b43..0000000
--- a/.bazelrc
+++ /dev/null
@@ -1,2 +0,0 @@
-build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64
-# build --sandbox_block_path=
diff --git a/.gitignore b/.gitignore
index 63ed09b..1e95a12 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,5 @@
 priv/
 bazel-*
 gazelle*
+coverage.txt
 
diff --git a/BUILD b/BUILD
deleted file mode 100644
index 9f3900a..0000000
--- a/BUILD
+++ /dev/null
@@ -1,10 +0,0 @@
-load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
-load("@bazel_gazelle//:def.bzl", "gazelle")
-
-buildifier(
-    name = "buildifier",
-)
-
-gazelle(
-    name = "gazelle",
-)
diff --git a/WORKSPACE b/WORKSPACE
deleted file mode 100644
index 3bbc45f..0000000
--- a/WORKSPACE
+++ /dev/null
@@ -1,119 +0,0 @@
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-## Packaging
-
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-http_archive(
-    name = "rules_pkg",
-    sha256 = "6b5969a7acd7b60c02f816773b06fcf32fbe8ba0c7919ccdc2df4f8fb923804a",
-    urls = [
-        "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.3.0/rules_pkg-0.3.0.tar.gz",
-        "https://github.com/bazelbuild/rules_pkg/releases/download/0.3.0/rules_pkg-0.3.0.tar.gz",
-    ],
-)
-
-load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
-
-rules_pkg_dependencies()
-
-## Golang
-
-http_archive(
-    name = "io_bazel_rules_go",
-    sha256 = "6f111c57fd50baf5b8ee9d63024874dd2a014b069426156c55adbf6d3d22cb7b",
-    urls = [
-        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.25.0/rules_go-v0.25.0.tar.gz",
-        "https://github.com/bazelbuild/rules_go/releases/download/v0.25.0/rules_go-v0.25.0.tar.gz",
-    ],
-)
-
-http_archive(
-    name = "bazel_gazelle",
-    sha256 = "b85f48fa105c4403326e9525ad2b2cc437babaa6e15a3fc0b1dbab0ab064bc7c",
-    urls = [
-        "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz",
-        "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz",
-    ],
-)
-
-load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
-load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
-
-go_rules_dependencies()
-
-go_register_toolchains(version = "1.15.5")
-
-gazelle_dependencies()
-
-## Docker
-
-http_archive(
-    name = "io_bazel_rules_docker",
-    sha256 = "1698624e878b0607052ae6131aa216d45ebb63871ec497f26c67455b34119c80",
-    strip_prefix = "rules_docker-0.15.0",
-    urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.15.0/rules_docker-v0.15.0.tar.gz"],
-)
-
-load(
-    "@io_bazel_rules_docker//repositories:repositories.bzl",
-    container_repositories = "repositories",
-)
-
-container_repositories()
-
-load(
-    "@io_bazel_rules_docker//go:image.bzl",
-    _go_image_repos = "repositories",
-)
-
-_go_image_repos()
-
-## Buildifier
-
-http_archive(
-    name = "com_google_protobuf",
-    strip_prefix = "protobuf-master",
-    urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
-)
-
-load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
-
-protobuf_deps()
-
-http_archive(
-    name = "com_github_bazelbuild_buildtools",
-    strip_prefix = "buildtools-master",
-    url = "https://github.com/bazelbuild/buildtools/archive/master.zip",
-)
-
-## Containier Base Images
-
-load("@io_bazel_rules_docker//container:container.bzl", "container_pull")
-
-container_pull(
-    name = "alpine_base",
-    digest = "sha256:4e01ddea8def856ba9fee17668fa0b2e45a8bc78127b7ab6cf921f6d6fd86ac9",
-    registry = "docker.io",
-    repository = "alpine",
-)
-
-## External Dependencies
-
-go_repository(
-    name = "com_github_itaysk_regogo",
-    commit = "e9433c1fe5a7c871ce62509fd6376ee114de677a",
-    importpath = "github.com/itaysk/regogo",
-)
-
-go_repository(
-    name = "com_github_open_policy_agent_opa",
-    importpath = "github.com/open-policy-agent/opa",
-    tag = "v0.25.1",
-)
-
-go_repository(
-    name = "com_github_golang_glog",
-    commit = "23def4e6c14b4da8ac2ed8007337bc5eb5007998",
-    importpath = "github.com/golang/glog",
-)
diff --git a/apps/face_detection/BUILD b/apps/face_detection/BUILD
deleted file mode 100644
index ebeb5b5..0000000
--- a/apps/face_detection/BUILD
+++ /dev/null
@@ -1,22 +0,0 @@
-load("//:bazel_tools/docker.bzl", "docker_image")
-load("@rules_pkg//:pkg.bzl", "pkg_tar")
-
-# TODO(lekva): figure out how to build py_binary with pip dependencies and
-# migrate off docker_image rule
-docker_image(
-    name = "push_to_dev",
-    srcs = glob(["*.py"]) + [
-        "haarcascade_frontalface_default.xml",
-    ],
-    dockerfile = "Dockerfile",
-    image = "giolekva/face-detector",
-    registry = "localhost:30500",
-    tag = "latest",
-)
-
-pkg_tar(
-    name = "chart",
-    srcs = glob(["chart/**"]),
-    extension = "tar.gz",
-    strip_prefix = "./chart",
-)
diff --git a/apps/minio/BUILD b/apps/minio/BUILD
deleted file mode 100644
index ad6af19..0000000
--- a/apps/minio/BUILD
+++ /dev/null
@@ -1,8 +0,0 @@
-load("@rules_pkg//:pkg.bzl", "pkg_tar")
-
-pkg_tar(
-    name = "chart",
-    srcs = glob(["chart/**"]),
-    extension = "tar.gz",
-    strip_prefix = "./chart",
-)
diff --git a/apps/minio/importer/BUILD b/apps/minio/importer/BUILD
deleted file mode 100644
index 09d5da2..0000000
--- a/apps/minio/importer/BUILD
+++ /dev/null
@@ -1,44 +0,0 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
-load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push")
-load("@rules_pkg//:pkg.bzl", "pkg_tar")
-
-go_library(
-    name = "lib",
-    srcs = ["importer.go"],
-    importpath = "github.com/giolekva/pcloud/apps/minio/importer",
-    deps = [
-        "@com_github_golang_glog//:go_default_library",
-        "@com_github_itaysk_regogo//:go_default_library",
-    ],
-)
-
-go_binary(
-    name = "importer",
-    srcs = ["main.go"],
-    deps = [
-        ":lib",
-    ],
-)
-
-container_image(
-    name = "container",
-    base = "@alpine_base//image",
-    cmd = ["importer"],
-    files = [":importer"],
-)
-
-container_push(
-    name = "push_to_dev",
-    format = "Docker",
-    image = ":container",
-    registry = "localhost:30500",
-    repository = "giolekva/minio-importer",
-    tag = "latest",
-)
-
-pkg_tar(
-    name = "chart",
-    srcs = glob(["chart/**"]),
-    extension = "tar.gz",
-    strip_prefix = "./chart",
-)
diff --git a/apps/photos-ui/BUILD b/apps/photos-ui/BUILD
deleted file mode 100644
index 1601870..0000000
--- a/apps/photos-ui/BUILD
+++ /dev/null
@@ -1,55 +0,0 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_binary")
-load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push")
-load("@rules_pkg//:pkg.bzl", "pkg_tar")
-
-filegroup(
-    name = "data",
-    srcs = glob([
-        "static/**",
-        "*.html",
-    ]),
-)
-
-go_binary(
-    name = "photos_ui",
-    srcs = ["main.go"],
-    data = [":data"],
-    deps = [
-        "@io_bazel_rules_go//go/tools/bazel",
-    ],
-)
-
-container_image(
-    name = "container",
-    base = "@alpine_base//image",
-    cmd = ["/photos_ui"],
-    data_path = "/",
-    env = {
-        "RUNFILES_DIR": "/",
-        "RUNFILES_MANIFEST_FILE": "/photos_ui.runfiles_manifest",
-    },
-    files = [
-        "photos_ui.runfiles_manifest",
-        ":data",
-        ":photos_ui",
-    ],
-    symlinks = {
-        "/photos_ui": "/apps/photos-ui/photos_ui_/photos_ui",
-    },
-)
-
-container_push(
-    name = "push_to_dev",
-    format = "Docker",
-    image = ":container",
-    registry = "localhost:30500",
-    repository = "giolekva/photos-ui",
-    tag = "latest",
-)
-
-pkg_tar(
-    name = "chart",
-    srcs = glob(["chart/**"]),
-    extension = "tar.gz",
-    strip_prefix = "./chart",
-)
diff --git a/apps/rpuppy/BUILD b/apps/rpuppy/BUILD
deleted file mode 100644
index 2e29fc8..0000000
--- a/apps/rpuppy/BUILD
+++ /dev/null
@@ -1,35 +0,0 @@
-load("@io_bazel_rules_go//go:def.bzl", "go_binary")
-load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_push")
-load("@rules_pkg//:pkg.bzl", "pkg_tar")
-
-go_binary(
-    name = "rpuppy",
-    srcs = ["main.go"],
-    deps = [
-        "@com_github_itaysk_regogo//:go_default_library",
-    ],
-)
-
-container_image(
-    name = "container",
-    # References container_pull from WORKSPACE (above)
-    base = "@alpine_base//image",
-    cmd = ["rpuppy"],
-    files = [":rpuppy"],
-)
-
-container_push(
-    name = "push_to_dev",
-    format = "Docker",
-    image = ":container",
-    registry = "localhost:30500",
-    repository = "giolekva/rpuppy",
-    tag = "latest",
-)
-
-pkg_tar(
-    name = "chart",
-    srcs = glob(["chart/**"]),
-    extension = "tar.gz",
-    strip_prefix = "./chart",
-)
diff --git a/core/api/BUILD b/core/api/BUILD
deleted file mode 100644
index ff865ca..0000000
--- a/core/api/BUILD
+++ /dev/null
@@ -1,41 +0,0 @@
-load("//:bazel_tools/docker.bzl", "docker_image")
-load("//:bazel_tools/helm.bzl", "helm_install", "helm_uninstall")
-load("@rules_pkg//:pkg.bzl", "pkg_tar")
-
-# TODO(lekva): figure out how to build py_binary with pip dependencies and
-# migrate off docker_image rule
-docker_image(
-    name = "push_to_dev",
-    srcs = glob(
-        ["**"],
-        exclude = ["Dockerfile"],
-    ),
-    dockerfile = "Dockerfile",
-    image = "giolekva/pcloud-api-server",
-    registry = "localhost:30500",
-    tag = "latest",
-)
-
-pkg_tar(
-    name = "chart",
-    srcs = glob(["chart/**"]),
-    extension = "tar.gz",
-    strip_prefix = "./chart",
-)
-
-helm_install(
-    name = "install",
-    args = {
-        "image.name": "localhost:30500/giolekva/pcloud-api-server",
-        "image.pullPolicy": "Always",
-    },
-    chart = ":chart",
-    namespace = "pcloud",
-    release_name = "init",
-)
-
-helm_uninstall(
-    name = "uninstall",
-    namespace = "pcloud",
-    release_name = "init",
-)
diff --git a/core/appmanager/BUILD b/core/appmanager/BUILD
deleted file mode 100644
index 1cc903a..0000000
--- a/core/appmanager/BUILD
+++ /dev/null
@@ -1,41 +0,0 @@
-load("//:bazel_tools/docker.bzl", "docker_image")
-load("//:bazel_tools/helm.bzl", "helm_install", "helm_uninstall")
-load("@rules_pkg//:pkg.bzl", "pkg_tar")
-
-# TODO(lekva): figure out how to build py_binary with pip dependencies and
-# migrate off docker_image rule
-docker_image(
-    name = "push_to_dev",
-    srcs = glob(
-        ["**"],
-        exclude = ["Dockerfile"],
-    ),
-    dockerfile = "Dockerfile",
-    image = "giolekva/pcloud-app-manager",
-    registry = "localhost:30500",
-    tag = "latest",
-)
-
-pkg_tar(
-    name = "chart",
-    srcs = glob(["chart/**"]),
-    extension = "tar.gz",
-    strip_prefix = "./chart",
-)
-
-helm_install(
-    name = "install",
-    args = {
-        "image.name": "localhost:30500/giolekva/pcloud-app-manager",
-        "image.pullPolicy": "Always",
-    },
-    chart = ":chart",
-    namespace = "pcloud-app-manager",
-    release_name = "init",
-)
-
-helm_uninstall(
-    name = "uninstall",
-    namespace = "pcloud-app-manager",
-    release_name = "init",
-)
diff --git a/core/events/BUILD b/core/events/BUILD
deleted file mode 100644
index 78a9aee..0000000
--- a/core/events/BUILD
+++ /dev/null
@@ -1,41 +0,0 @@
-load("//:bazel_tools/docker.bzl", "docker_image")
-load("//:bazel_tools/helm.bzl", "helm_install", "helm_uninstall")
-load("@rules_pkg//:pkg.bzl", "pkg_tar")
-
-# TODO(lekva): figure out how to build py_binary with pip dependencies and
-# migrate off docker_image rule
-docker_image(
-    name = "push_to_dev",
-    srcs = glob(
-        ["**"],
-        exclude = ["Dockerfile"],
-    ),
-    dockerfile = "Dockerfile",
-    image = "giolekva/pcloud-event-processor",
-    registry = "localhost:30500",
-    tag = "latest",
-)
-
-pkg_tar(
-    name = "chart",
-    srcs = glob(["chart/**"]),
-    extension = "tar.gz",
-    strip_prefix = "./chart",
-)
-
-helm_install(
-    name = "install",
-    args = {
-        "image.name": "localhost:30500/giolekva/pcloud-event-processor",
-        "image.pullPolicy": "Always",
-    },
-    chart = ":chart",
-    namespace = "pcloud-event-processor",
-    release_name = "init",
-)
-
-helm_uninstall(
-    name = "uninstall",
-    namespace = "pcloud-event-processor",
-    release_name = "init",
-)
diff --git a/core/kg/Makefile b/core/kg/Makefile
new file mode 100644
index 0000000..c962617
--- /dev/null
+++ b/core/kg/Makefile
@@ -0,0 +1,67 @@
+GO ?= $(shell command -v go 2> /dev/null)
+GO_TEST_FLAGS ?= -race
+
+export GO111MODULE=on
+
+MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
+MINIMUM_SUPPORTED_GO_MINOR_VERSION = 14
+GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
+GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
+GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)
+
+BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)"
+
+## Define the default target (make all)
+.PHONY: default
+default: all
+
+## Checks the code style, tests, runs the code.
+.PHONY: all
+all: check-style test run
+
+## Runs eslint and golangci-lint
+.PHONY: check-style
+check-style:
+	@if ! [ -x "$$(command -v golangci-lint)" ]; then \
+		echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
+		exit 1; \
+	fi; \
+
+	@echo Running golangci-lint
+	golangci-lint run ./...
+
+## Runs unit tests.
+.PHONY: test
+test:
+	@echo Running unit tests
+	$(GO) test -v $(GO_TEST_FLAGS) ./...
+
+## Creates a coverage report
+.PHONY: coverage
+coverage:
+	$(GO) test $(GO_TEST_FLAGS) -coverprofile=coverage.txt ./...
+	$(GO) tool cover -html=coverage.txt
+
+## Clean removes all artifacts.
+.PHONY: clean
+clean:
+	rm -fr coverage.txt
+	rm -fr server.log
+
+.PHONY: run
+run: validate-go-version
+	@echo Running Knowledge Graph services
+
+	$(GO) run ./cmd/
+
+.PHONY: validate-go-version
+validate-go-version: ## Validates the installed version of go against minimum requirement.
+	@if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
+		exit 0 ;\
+	elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
+		echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
+		exit 1; \
+	elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
+		echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
+		exit 1; \
+	fi
\ No newline at end of file
diff --git a/core/kg/model/user.go b/core/kg/model/user.go
index e68bb63..04357d1 100644
--- a/core/kg/model/user.go
+++ b/core/kg/model/user.go
@@ -8,9 +8,8 @@
 )
 
 const (
-	userNameMaxLength  = 64
-	userNameMinLength  = 1
-	userEmailMaxLength = 128
+	userNameMaxLength = 64
+	userNameMinLength = 1
 )
 
 // User contains the details about the user.
@@ -99,9 +98,6 @@
 	}
 
 	validUsernameChars := regexp.MustCompile(`^[a-z0-9\.\-_]+$`)
-	if !validUsernameChars.MatchString(s) {
-		return false
-	}
 
-	return true
+	return validUsernameChars.MatchString(s)
 }
diff --git a/core/kg/server/servers_mock.go b/core/kg/server/servers_mock.go
index 03ff60d..ab20e55 100644
--- a/core/kg/server/servers_mock.go
+++ b/core/kg/server/servers_mock.go
@@ -30,8 +30,8 @@
 		Servers: []Server{grpcServer, httpServer},
 		Config:  config,
 	}
-	go grpcServer.Start()
-	go httpServer.Start()
+	go grpcServer.Start() // nolint:errcheck
+	go httpServer.Start() // nolint:errcheck
 	time.Sleep(1 * time.Second)
 	return ts
 }
@@ -40,7 +40,7 @@
 	done := make(chan bool)
 	go func() {
 		for _, server := range ts.Servers {
-			server.Shutdown()
+			server.Shutdown() // nolint:errcheck
 		}
 		close(done)
 	}()