Skip to content

Commit c960236

Browse files
committed
[IAM] add component skeleton
1 parent 4b93a92 commit c960236

File tree

44 files changed

+7298
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+7298
-2
lines changed

components/BUILD.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ packages:
3737
- components/ee/db-sync:docker
3838
- components/ee/payment-endpoint:docker
3939
- components/gitpod-db:docker
40+
- components/iam:docker
4041
- components/ide/code-desktop:docker
4142
- components/ide/code-desktop:docker-insiders
4243
- components/ide/code:docker
@@ -109,6 +110,7 @@ packages:
109110
- name: all-apps
110111
type: generic
111112
deps:
113+
- components/iam:app
112114
- components/blobserve:app
113115
- components/content-service:app
114116
- components/dashboard:app

components/iam/BUILD.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
packages:
2+
- name: app
3+
type: go
4+
srcs:
5+
- "**/*.go"
6+
- "go.mod"
7+
- "go.sum"
8+
deps:
9+
- components/common-go:lib
10+
- components/gitpod-protocol/go:lib
11+
env:
12+
- CGO_ENABLED=0
13+
- GOOS=linux
14+
config:
15+
packaging: app
16+
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'github.com/gitpod-io/gitpod/iam/cmd.Version=commit-${__git_commit}'"]
17+
- name: docker
18+
type: docker
19+
deps:
20+
- :app
21+
argdeps:
22+
- imageRepoBase
23+
config:
24+
buildArgs:
25+
VERSION: ${version}
26+
dockerfile: leeway.Dockerfile
27+
metadata:
28+
helm-component: iam
29+
image:
30+
- ${imageRepoBase}/iam:${version}
31+
- ${imageRepoBase}/iam:commit-${__git_commit}
32+
- name: lib
33+
type: go
34+
srcs:
35+
- "**/*.go"
36+
- "go.mod"
37+
- "go.sum"
38+
deps:
39+
- components/common-go:lib
40+
- components/gitpod-protocol/go:lib
41+
env:
42+
- CGO_ENABLED=0
43+
- GOOS=linux
44+
config:
45+
packaging: library

components/iam/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## IAM
2+
3+
The `iam` components hosts OIDC client and other authN+authN related concerns.
4+
5+
TBD

components/iam/cmd/root.go

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package cmd
6+
7+
import (
8+
"bytes"
9+
"context"
10+
"encoding/json"
11+
"os"
12+
"path"
13+
14+
"github.com/gitpod-io/gitpod/iam/pkg/config"
15+
16+
"github.com/gitpod-io/gitpod/common-go/log"
17+
"github.com/spf13/cobra"
18+
)
19+
20+
var (
21+
// ServiceName is the name we use for tracing/logging
22+
ServiceName = "iam"
23+
// Version of this service - set during build
24+
Version = ""
25+
)
26+
27+
var rootOpts struct {
28+
CfgFile string
29+
JsonLog bool
30+
Verbose bool
31+
}
32+
33+
// rootCmd represents the base command when called without any subcommands
34+
var rootCmd = &cobra.Command{
35+
Use: ServiceName,
36+
Short: "Serves IAM services",
37+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
38+
log.Init(ServiceName, Version, rootOpts.JsonLog, rootOpts.Verbose)
39+
},
40+
}
41+
42+
func Execute() {
43+
if err := rootCmd.ExecuteContext(context.Background()); err != nil {
44+
log.WithError(err).Error("Failed to execute command.")
45+
os.Exit(1)
46+
}
47+
}
48+
49+
func init() {
50+
localConfig := path.Join(os.ExpandEnv("GOMOD"), "..", "config.json")
51+
rootCmd.PersistentFlags().StringVar(&rootOpts.CfgFile, "config", localConfig, "config file")
52+
rootCmd.PersistentFlags().BoolVar(&rootOpts.JsonLog, "json-log", true, "produce JSON log output on verbose level")
53+
rootCmd.PersistentFlags().BoolVar(&rootOpts.Verbose, "verbose", false, "Enable verbose JSON logging")
54+
}
55+
56+
func getConfig() *config.ServiceConfig {
57+
ctnt, err := os.ReadFile(rootOpts.CfgFile)
58+
if err != nil {
59+
log.WithError(err).Fatal("Cannot read configuration. Maybe missing --config?")
60+
}
61+
62+
var cfg config.ServiceConfig
63+
dec := json.NewDecoder(bytes.NewReader(ctnt))
64+
dec.DisallowUnknownFields()
65+
err = dec.Decode(&cfg)
66+
if err != nil {
67+
log.WithError(err).Fatal("Cannot decode configuration. Maybe missing --config?")
68+
}
69+
70+
return &cfg
71+
}

components/iam/cmd/run.go

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License-AGPL.txt in the project root for license information.
4+
5+
package cmd
6+
7+
import (
8+
"github.com/gitpod-io/gitpod/common-go/log"
9+
"github.com/gitpod-io/gitpod/iam/pkg/server"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
func init() {
14+
rootCmd.AddCommand(runCommand)
15+
}
16+
17+
var runCommand = &cobra.Command{
18+
Use: "run",
19+
Short: "Starts the service",
20+
Version: Version,
21+
Run: func(cmd *cobra.Command, args []string) {
22+
cfg := getConfig()
23+
24+
if err := server.Start(log.Log, Version, cfg); err != nil {
25+
log.WithError(err).Fatal("cannot start server")
26+
}
27+
},
28+
}

components/iam/config.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"server": {
3+
"services": {
4+
"grpc": {
5+
"address": ":9001"
6+
},
7+
"http": {
8+
"address": ":9002"
9+
}
10+
}
11+
}
12+
}

components/iam/go.mod

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module github.com/gitpod-io/gitpod/iam
2+
3+
go 1.19
4+
5+
require (
6+
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
7+
github.com/sirupsen/logrus v1.8.1
8+
github.com/spf13/cobra v1.4.0
9+
)
10+
11+
require (
12+
github.com/beorn7/perks v1.0.1 // indirect
13+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
14+
github.com/davecgh/go-spew v1.1.1 // indirect
15+
github.com/golang/protobuf v1.5.2 // indirect
16+
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
17+
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
18+
github.com/hashicorp/golang-lru v0.5.1 // indirect
19+
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb // indirect
20+
github.com/inconshreveable/mousetrap v1.0.1 // indirect
21+
github.com/kr/text v0.2.0 // indirect
22+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
23+
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
24+
github.com/opentracing/opentracing-go v1.2.0 // indirect
25+
github.com/pmezard/go-difflib v1.0.0 // indirect
26+
github.com/prometheus/client_golang v1.13.0 // indirect
27+
github.com/prometheus/client_model v0.2.0 // indirect
28+
github.com/prometheus/common v0.37.0 // indirect
29+
github.com/prometheus/procfs v0.8.0 // indirect
30+
github.com/slok/go-http-metrics v0.10.0 // indirect
31+
github.com/spf13/pflag v1.0.5 // indirect
32+
github.com/stretchr/testify v1.7.0 // indirect
33+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
34+
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
35+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
36+
golang.org/x/text v0.3.7 // indirect
37+
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
38+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
39+
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154 // indirect
40+
google.golang.org/grpc v1.49.0 // indirect
41+
google.golang.org/protobuf v1.28.1 // indirect
42+
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
43+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
44+
)
45+
46+
replace github.com/gitpod-io/gitpod/common-go => ../common-go // leeway
47+
48+
replace github.com/gitpod-io/gitpod/gitpod-protocol => ../gitpod-protocol/go // leeway

0 commit comments

Comments
 (0)