Skip to content

Commit

Permalink
feat: support argocd server path (#272)
Browse files Browse the repository at this point in the history
* feat: support argocd server path

* feat: add prefix to root path if it is not exist
  • Loading branch information
pasha-codefresh authored Dec 26, 2023
1 parent 54a2358 commit de91ea9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
19 changes: 11 additions & 8 deletions cmd/event-reporter-server/commands/event_reporter_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ func init() {
failureRetryPeriodMilliSeconds = env.ParseNumFromEnv(failureRetryPeriodMilliSecondsEnv, failureRetryPeriodMilliSeconds, 0, 1000)
}

func getApplicationClient(useGrpc bool, address, token string) appclient.ApplicationClient {
func getApplicationClient(useGrpc bool, address, token string, path string) appclient.ApplicationClient {
if useGrpc {
applicationClientSet, err := apiclient.NewClient(&apiclient.ClientOptions{
ServerAddr: address,
Insecure: true,
GRPCWeb: true,
PlainText: true,
AuthToken: token,
ServerAddr: address,
Insecure: true,
GRPCWeb: true,
PlainText: true,
AuthToken: token,
GRPCWebRootPath: path,
})

errors.CheckError(err)
Expand All @@ -64,7 +65,7 @@ func getApplicationClient(useGrpc bool, address, token string) appclient.Applica

return applicationClient
}
return appclient.NewHttpApplicationClient(token, address)
return appclient.NewHttpApplicationClient(token, address, path)
}

// NewCommand returns a new instance of an event reporter command
Expand All @@ -90,6 +91,7 @@ func NewCommand() *cobra.Command {
codefreshUrl string
codefreshToken string
shardingAlgorithm string
rootpath string
useGrpc bool
)
var command = &cobra.Command{
Expand Down Expand Up @@ -165,7 +167,7 @@ func NewCommand() *cobra.Command {
Cache: cache,
RedisClient: redisClient,
ApplicationNamespaces: applicationNamespaces,
ApplicationServiceClient: getApplicationClient(useGrpc, applicationServerAddress, argocdToken),
ApplicationServiceClient: getApplicationClient(useGrpc, applicationServerAddress, argocdToken, rootpath),
CodefreshConfig: &codefresh.CodefreshConfig{
BaseURL: codefreshUrl,
AuthToken: codefreshToken,
Expand Down Expand Up @@ -194,6 +196,7 @@ func NewCommand() *cobra.Command {
}

clientConfig = cli.AddKubectlFlagsToCmd(command)
command.Flags().StringVar(&rootpath, "argocd-server-path", env.StringFromEnv("ARGOCD_SERVER_ROOTPATH", ""), "Used if Argo CD is running behind reverse proxy under subpath different from /")
command.Flags().BoolVar(&insecure, "insecure", env.ParseBoolFromEnv("EVENT_REPORTER_INSECURE", false), "Run server without TLS")
command.Flags().StringVar(&cmdutil.LogFormat, "logformat", env.StringFromEnv("EVENT_REPORTER_LOGFORMAT", "text"), "Set the logging format. One of: text|json")
command.Flags().StringVar(&cmdutil.LogLevel, "loglevel", env.StringFromEnv("EVENT_REPORTER_LOG_LEVEL", "info"), "Set the logging level. One of: debug|info|warn|error")
Expand Down
16 changes: 13 additions & 3 deletions event_reporter/application/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,29 @@ type httpApplicationClient struct {
httpClient *http.Client
baseUrl string
token string
rootpath string
}

func NewHttpApplicationClient(token string, address string) ApplicationClient {
func NewHttpApplicationClient(token string, address string, rootpath string) ApplicationClient {
if rootpath != "" && !strings.HasPrefix(rootpath, "/") {
rootpath = "/" + rootpath
}

if !strings.Contains(address, "http") {
address = "http://" + address
}

if rootpath != "" {
address = address + rootpath
}

return &httpApplicationClient{
httpClient: &http.Client{
Timeout: 30 * time.Second,
},
baseUrl: address,
token: token,
baseUrl: address,
token: token,
rootpath: rootpath,
}
}

Expand Down

0 comments on commit de91ea9

Please sign in to comment.