Skip to content

Commit

Permalink
using rootconfig builder from gateway in adhoc flow (#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero authored Mar 27, 2024
1 parent 9fa4d36 commit 4b99dfc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/adhoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func (a *Adhoc) NewServer(userConfig legacy.UserConfig, config legacy.Config) (S
TerraformRoot: terraform.Root{},
GithubRepo: github.Repo{},
},
GithubHostname: userConfig.GithubHostname,
GithubAppID: userConfig.GithubAppID,
GithubAppKeyFile: userConfig.GithubAppKeyFile,
GithubAppSlug: userConfig.GithubAppSlug,
GlobalCfg: globalCfg,
}
return adhoc.NewServer(cfg)
}
7 changes: 7 additions & 0 deletions server/neptune/adhoc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ type Config struct {
CtxLogger logging.Logger
App githubapp.Config
AdhocExecutionParams adhoc.AdhocTerraformWorkflowExecutionParams

GithubAppID int64
GithubAppKeyFile string
GithubAppSlug string
GithubHostname string

GlobalCfg valid.GlobalCfg
}
45 changes: 45 additions & 0 deletions server/neptune/adhoc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/palantir/go-githubapp/githubapp"
"github.com/runatlantis/atlantis/server/legacy/events/vcs"
"github.com/runatlantis/atlantis/server/neptune/lyft/feature"
"github.com/runatlantis/atlantis/server/neptune/sync/crons"
ghClient "github.com/runatlantis/atlantis/server/neptune/workflows/activities/github"
Expand All @@ -26,6 +27,9 @@ import (
"github.com/runatlantis/atlantis/server/metrics"
adhoc "github.com/runatlantis/atlantis/server/neptune/adhoc/adhocexecutionhelpers"
adhocconfig "github.com/runatlantis/atlantis/server/neptune/adhoc/config"
root_config "github.com/runatlantis/atlantis/server/neptune/gateway/config"
"github.com/runatlantis/atlantis/server/neptune/gateway/deploy"
"github.com/runatlantis/atlantis/server/neptune/gateway/event/preworkflow"
neptune_http "github.com/runatlantis/atlantis/server/neptune/http"
internalSync "github.com/runatlantis/atlantis/server/neptune/sync"
"github.com/runatlantis/atlantis/server/neptune/temporal"
Expand All @@ -52,6 +56,7 @@ type Server struct {
GithubActivities *activities.Github
AdhocExecutionParams adhoc.AdhocTerraformWorkflowExecutionParams
TerraformTaskQueue string
RootConfigBuilder *root_config.Builder
}

func NewServer(config *adhocconfig.Config) (*Server, error) {
Expand Down Expand Up @@ -152,6 +157,45 @@ func NewServer(config *adhocconfig.Config) (*Server, error) {

cronScheduler := internalSync.NewCronScheduler(config.CtxLogger)

privateKey, err := os.ReadFile(config.GithubAppKeyFile)
if err != nil {
return nil, err
}
githubCredentials := &vcs.GithubAppCredentials{
AppID: config.GithubAppID,
Key: privateKey,
Hostname: config.GithubHostname,
AppSlug: config.GithubAppSlug,
}

repoFetcher := &github.RepoFetcher{
DataDir: config.DataDir,
GithubCredentials: githubCredentials,
GithubHostname: config.GithubHostname,
Logger: config.CtxLogger,
Scope: scope.SubScope("repo.fetch"),
}

hooksRunner := &preworkflow.HooksRunner{
GlobalCfg: config.GlobalCfg,
HookExecutor: &preworkflow.HookExecutor{
Logger: config.CtxLogger,
},
}

rootConfigBuilder := &root_config.Builder{
RepoFetcher: repoFetcher,
HooksRunner: hooksRunner,
ParserValidator: &root_config.ParserValidator{GlobalCfg: config.GlobalCfg},
Strategy: &root_config.ModifiedRootsStrategy{
RootFinder: &deploy.RepoRootFinder{Logger: config.CtxLogger},
FileFetcher: &github.RemoteFileFetcher{ClientCreator: clientCreator},
},
GlobalCfg: config.GlobalCfg,
Logger: config.CtxLogger,
Scope: scope.SubScope("event.filters.root"),
}

server := Server{
Logger: config.CtxLogger,
CronScheduler: cronScheduler,
Expand All @@ -170,6 +214,7 @@ func NewServer(config *adhocconfig.Config) (*Server, error) {
TerraformTaskQueue: config.TemporalCfg.TerraformTaskQueue,
GithubActivities: githubActivities,
AdhocExecutionParams: config.AdhocExecutionParams,
RootConfigBuilder: rootConfigBuilder,
}
return &server, nil
}
Expand Down

0 comments on commit 4b99dfc

Please sign in to comment.