Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor backend #58

Merged
merged 28 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3ccf76c
removes duplicate logic, adds missing error handling in request hand…
Rampage1xx Feb 4, 2021
15505ff
fixes os.GetEnv regression
Rampage1xx Feb 4, 2021
2e1429c
fixes regression on token
Rampage1xx Feb 4, 2021
fb3f7bc
Merge remote-tracking branch 'origin/master' into refactor/go-backend
Rampage1xx Feb 4, 2021
119ddf7
user response refactoring
Rampage1xx Jun 1, 2021
eb6e6a8
standardizing error handling
Rampage1xx Jun 3, 2021
2255ba8
standardizing error handling
Rampage1xx Jun 3, 2021
e669191
moves logic to resources
Rampage1xx Jul 7, 2021
c3694ad
refactors handlers logic, improves AppContext
Rampage1xx Jul 9, 2021
dfdc469
improves server creation and ResourceService
Rampage1xx Jul 9, 2021
7b0df2e
adds a single point for validateAndBind of requests
Rampage1xx Jul 9, 2021
657a310
adds a single point for serving ok and error response logic
Rampage1xx Jul 9, 2021
24c188d
moves kubeapi communication logic inside resources package
Rampage1xx Jul 9, 2021
f5b3505
more resourceService methods, getAll renamed to list
Rampage1xx Jul 9, 2021
56fddb9
minor tweaks on ErrorResponse
Rampage1xx Jul 9, 2021
84859ec
more resourceService methods, getAll renamed to list
Rampage1xx Jul 9, 2021
4cd9e75
bugfixes rolebinding
Rampage1xx Jul 9, 2021
4e1cf1b
refactors kubeconfig generation, bugfixing user list
Rampage1xx Jul 9, 2021
f65e3c7
correctly handles context changes during request
Rampage1xx Jul 9, 2021
4b673b3
revers context changes
Rampage1xx Jul 9, 2021
fb93c40
svc account logic refactor
Rampage1xx Jul 9, 2021
4cacf94
refactors kubeclient
Rampage1xx Jul 9, 2021
8cea90b
moves kubeconfig creation logic inside svc account service
Rampage1xx Jul 10, 2021
e29448f
adds main inside resources package
Rampage1xx Jul 10, 2021
666f5af
removes boilerplate interfaces, improves struct names
Rampage1xx Aug 30, 2021
5c385f9
refactors backend side of permissionmanageruser crd
Rampage1xx Aug 30, 2021
cdd4594
FIX: Incorrect api endpoints and kube client methods
angelbarrera92 Sep 8, 2021
e1f4736
Merge pull request #77 from sighupio/fix-go-refactor
Rampage1xx Sep 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions cmd/run-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ package main

import (
"sighupio/permission-manager/internal/config"
"sighupio/permission-manager/internal/kubeclient"
"sighupio/permission-manager/internal/resources"
"sighupio/permission-manager/internal/server"
)

func main() {
cfg := config.New()
kc := kubeclient.New()
rs := resources.NewResourcesService(kc)

s := server.New(kc, cfg, rs)
addr := ":" + cfg.Port
s := server.New(*cfg)
addr := ":" + cfg.Backend.Port
s.Logger.Fatal(s.Start(addr))
}
129 changes: 129 additions & 0 deletions go.sum

Large diffs are not rendered by default.

40 changes: 24 additions & 16 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,42 @@ import (
"os"
)

type ClusterConfig struct {
Name string
ControlPlaneAddress string
}

type BackendConfig struct {
Port string
}

// Config contains PermissionManager cluster/server configuration
type Config struct {
ClusterName string
ClusterControlPlaceAddress string
Port string
Cluster ClusterConfig
Backend BackendConfig
}

func New() *Config {
cfg := &Config{}
cfg := &Config{
Cluster: ClusterConfig{
Name: os.Getenv("CLUSTER_NAME"),
ControlPlaneAddress: os.Getenv("CONTROL_PLANE_ADDRESS"),
},
Backend: BackendConfig{
Port: os.Getenv("PORT"),
},
}

port := os.Getenv("PORT")
if port == "" {
if cfg.Backend.Port == "" {
log.Fatal("PORT env cannot be empty")
} else {
cfg.Port = port
}

clusterName := os.Getenv("CLUSTER_NAME")
if clusterName == "" {
if cfg.Cluster.Name == "" {
log.Fatal("CLUSTER_NAME env cannot be empty")
} else {
cfg.ClusterName = clusterName
}

clusterControlPlaceAddress := os.Getenv("CONTROL_PLANE_ADDRESS")
if clusterControlPlaceAddress == "" {
if cfg.Cluster.ControlPlaneAddress == "" {
log.Fatal("CONTROL_PLANE_ADDRESS env cannot be empty")
} else {
cfg.ClusterControlPlaceAddress = clusterControlPlaceAddress
}

return cfg
Expand Down
6 changes: 3 additions & 3 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ func ExampleNew() {
os.Setenv("CONTROL_PLANE_ADDRESS", "https://192.168.64.33:8443")
cfg := config.New()

fmt.Println(cfg.Port)
fmt.Println(cfg.ClusterName)
fmt.Println(cfg.ClusterControlPlaceAddress)
fmt.Println(cfg.Backend.Port)
fmt.Println(cfg.Cluster.Name)
fmt.Println(cfg.Cluster.ControlPlaneAddress)

// Output:
// 4000
Expand Down
25 changes: 25 additions & 0 deletions internal/crd/v1alpha1/permissionmanageruser_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v1alpha1

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

const (
ResourceURL = "apis/permissionmanager.user/v1alpha1/permissionmanagerusers"
ResourcePrefix = "permissionmanagerusers.permissionmanager.user."
)

type PermissionManagerUserSpec struct {
Name string `json:"name"`
}

// PermissionManagerUser is the PermissionManager representation of an user of the managed K8s cluster
type PermissionManagerUser struct {
metav1.TypeMeta `json:",inline"`
Metadata metav1.ObjectMeta `json:"metadata,omitempty"`
Spec PermissionManagerUserSpec `json:"spec"`
}

type PermissionManagerUserList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []PermissionManagerUser `json:"items"`
}
26 changes: 0 additions & 26 deletions internal/kubeclient/kubeclient.go

This file was deleted.

169 changes: 0 additions & 169 deletions internal/kubeconfig/certificate.go

This file was deleted.

50 changes: 0 additions & 50 deletions internal/kubeconfig/create-kubeconfig.go

This file was deleted.

Loading