diff --git a/cmd/adhoc.go b/cmd/adhoc.go index 26645d401..4a90d8499 100644 --- a/cmd/adhoc.go +++ b/cmd/adhoc.go @@ -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) } diff --git a/server/neptune/adhoc/config/config.go b/server/neptune/adhoc/config/config.go index 11f7cc5fd..c017e37ec 100644 --- a/server/neptune/adhoc/config/config.go +++ b/server/neptune/adhoc/config/config.go @@ -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 } diff --git a/server/neptune/adhoc/server.go b/server/neptune/adhoc/server.go index 405311946..d2c229cb8 100644 --- a/server/neptune/adhoc/server.go +++ b/server/neptune/adhoc/server.go @@ -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" @@ -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" @@ -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) { @@ -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, @@ -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 }