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

using rootconfig builder from gateway in adhoc flow #738

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
smonero marked this conversation as resolved.
Show resolved Hide resolved
}
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
Loading