Skip to content
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: 2 additions & 3 deletions cmd/command/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,11 @@ func (p *Plural) handleUp(c *cli.Context) error {
return err
}

ctx, err := up.Build(c.Bool("cloud"))
ctx.IgnorePreflights(c.Bool("ignore-preflights") || c.Bool("dry-run"))

ctx, err := up.Build(cloud)
if err != nil {
return err
}
ctx.IgnorePreflights(c.Bool("ignore-preflights") || dryRun)

byok := ctx.Provider.Name() == api.BYOK

Expand Down
15 changes: 9 additions & 6 deletions pkg/client/plural.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@ import (
"strings"

"github.com/pluralsh/console/go/polly/algorithms"
gitutils "github.com/pluralsh/plural-cli/pkg/utils/git"
"github.com/samber/lo"
apierrors "k8s.io/apimachinery/pkg/api/errors"

gitutils "github.com/pluralsh/plural-cli/pkg/utils/git"

"github.com/urfave/cli"

"github.com/pluralsh/plural-cli/pkg/common"
"github.com/pluralsh/plural-cli/pkg/scm"
"github.com/pluralsh/plural-cli/pkg/wkspace"

"sigs.k8s.io/yaml"

"github.com/pluralsh/plural-cli/pkg/api"
"github.com/pluralsh/plural-cli/pkg/config"
"github.com/pluralsh/plural-cli/pkg/console"
"github.com/pluralsh/plural-cli/pkg/kubernetes"
"github.com/pluralsh/plural-cli/pkg/manifest"
"github.com/pluralsh/plural-cli/pkg/utils"
"sigs.k8s.io/yaml"
)

type Plural struct {
Expand Down Expand Up @@ -106,13 +108,14 @@ func (p *Plural) HandleInit(c *cli.Context) error {
return err
}

func (p *Plural) HandleInitWithProject(c *cli.Context) (*manifest.ProjectManifest, error) {
func (p *Plural) HandleInitWithProject(c *cli.Context) (project *manifest.ProjectManifest, err error) {
gitCreated := false
repo := ""
dryRun := c.Bool("dry-run")
p.InitPluralClient()

git, err := wkspace.Preflight(c.Bool("dry-run"), c.Bool("ignore-preflights"))
if err != nil && (git || c.Bool("dry-run")) {
git, err := wkspace.Preflight(dryRun, c.Bool("ignore-preflights"))
if err != nil && (git || dryRun) {
return nil, err
}

Expand Down Expand Up @@ -156,7 +159,7 @@ func (p *Plural) HandleInitWithProject(c *cli.Context) (*manifest.ProjectManifes
return nil, err
}

project, err := manifest.FetchProject()
project, err = manifest.FetchProject()
if err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func mkAWS(conf config.Config, dryRun bool) (provider *AWSProvider, err error) {
ctx := context.Background()
provider = &AWSProvider{}
if dryRun {
projectManifest := manifest.ProjectManifest{
Provider: api.ProviderAWS,
Owner: &manifest.Owner{Email: conf.Email, Endpoint: conf.Endpoint},
}

provider.writer = func() error { return projectManifest.Write(manifest.ProjectManifestPath()) }
return provider, nil
}
iamSession, callerIdentity, err := GetAWSCallerIdentity(ctx)
Expand Down
7 changes: 6 additions & 1 deletion pkg/provider/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ type AzureProvider struct {
func mkAzure(conf config.Config, dryRun bool) (prov *AzureProvider, err error) {
prov = &AzureProvider{}
if dryRun {
projectManifest := manifest.ProjectManifest{
Provider: api.ProviderAzure,
Owner: &manifest.Owner{Email: conf.Email, Endpoint: conf.Endpoint},
}
prov.writer = func() error { return projectManifest.Write(manifest.ProjectManifestPath()) }
return prov, nil
}
subId, tenID, subName, err := GetAzureAccount()
Expand Down Expand Up @@ -155,7 +160,7 @@ func mkAzure(conf config.Config, dryRun bool) (prov *AzureProvider, err error) {
func AzureFromManifest(man *manifest.ProjectManifest, clientSet *ClientSet) (*AzureProvider, error) {
var err error
clients := clientSet
if clientSet == nil {
if clientSet == nil && utils.ToString(man.Context["SubscriptionId"]) != "" {
Comment thread
floreks marked this conversation as resolved.
clients, err = GetClientSet(utils.ToString(man.Context["SubscriptionId"]))
if err != nil {
return nil, err
Expand Down
11 changes: 9 additions & 2 deletions pkg/provider/byok.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (
"strings"

"github.com/AlecAivazis/survey/v2"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"

"github.com/pluralsh/plural-cli/pkg/api"
"github.com/pluralsh/plural-cli/pkg/config"
"github.com/pluralsh/plural-cli/pkg/kubernetes"
"github.com/pluralsh/plural-cli/pkg/manifest"
"github.com/pluralsh/plural-cli/pkg/provider/permissions"
"github.com/pluralsh/plural-cli/pkg/provider/preflights"
"github.com/pluralsh/plural-cli/pkg/utils"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)

const defaultValue = "default"
Expand All @@ -42,6 +43,12 @@ func mkBYOK(conf config.Config, name string, dryRun, cloud bool) (prov *ByokProv
ctx: map[string]interface{}{},
}
if dryRun {
projectManifest := manifest.ProjectManifest{
Provider: api.BYOK,
Owner: &manifest.Owner{Email: conf.Email, Endpoint: conf.Endpoint},
}

prov.writer = func() error { return projectManifest.Write(manifest.ProjectManifestPath()) }
return prov, nil
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/provider/gcp/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ type Option func(*Provider) error
func WithConfig(c config.Config, defaultCluster string, cloudEnabled, dryRun bool) Option {
return func(gcp *Provider) error {
if dryRun {
projectManifest := manifest.ProjectManifest{
Bucket: "dry-run",
Provider: api.ProviderGCP,
Owner: &manifest.Owner{Email: c.Email, Endpoint: c.Endpoint},
}
gcp.InputProvider = NewReadonlyInputProvider(defaultCluster, "", "")
gcp.bucket = projectManifest.Bucket
gcp.writer = func() error { return projectManifest.Write(manifest.ProjectManifestPath()) }
return nil
}
err := printUserInfo()
Expand Down
60 changes: 30 additions & 30 deletions pkg/up/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,70 +42,70 @@ type delims struct {
right string
}

func (ctx *Context) identifier() string {
if ctx.RepoUrl == "" {
func (c *Context) identifier() string {
if c.RepoUrl == "" {
return ""
}

if strings.HasPrefix(ctx.RepoUrl, "http") {
parsed, err := giturls.Parse(ctx.RepoUrl)
if strings.HasPrefix(c.RepoUrl, "http") {
parsed, err := giturls.Parse(c.RepoUrl)
if err == nil {
return strings.TrimSuffix(strings.TrimPrefix(parsed.Path, "/"), ".git")
}
}

split := strings.Split(ctx.RepoUrl, ":")
split := strings.Split(c.RepoUrl, ":")
return strings.TrimSuffix(split[len(split)-1], ".git")
}

func (ctx *Context) changeDelims() {
ctx.Delims = &delims{"[[", "]]"}
func (c *Context) changeDelims() {
c.Delims = &delims{"[[", "]]"}
}

func (ctx *Context) IgnorePreflights(ignore bool) {
ctx.ignorePreflights = ignore
func (c *Context) IgnorePreflights(ignore bool) {
c.ignorePreflights = ignore
}

func (ctx *Context) SetImportCluster(id string) {
ctx.ImportCluster = lo.ToPtr(id)
func (c *Context) SetImportCluster(id string) {
c.ImportCluster = lo.ToPtr(id)
}

func (ctx *Context) Backfill() error {
func (c *Context) Backfill() error {
context, err := manifest.FetchContext()
if err != nil {
return ctx.backfillConsoleContext(ctx.Manifest)
return c.backfillConsoleContext(c.Manifest)
}

console, ok := context.Configuration["console"]
if !ok {
return ctx.backfillConsoleContext(ctx.Manifest)
return c.backfillConsoleContext(c.Manifest)
}

_, hasSSH := console["private_key"]
_, hasHTTPS := console["git_password"]
if !hasSSH && !hasHTTPS {
return ctx.backfillConsoleContext(ctx.Manifest)
return c.backfillConsoleContext(c.Manifest)
}

if v, ok := console["repo_url"]; ok {
if r, ok := v.(string); ok {
ctx.RepoUrl = r
c.RepoUrl = r
}
}

if v, ok := console["git_username"]; ok {
if s, ok := v.(string); ok {
ctx.GitUsername = s
c.GitUsername = s
}
}

if v, ok := console["git_password"]; ok {
if s, ok := v.(string); ok {
ctx.GitPassword = s
c.GitPassword = s
}
}

if ctx.RepoUrl == "" {
if c.RepoUrl == "" {
return fmt.Errorf("you never configured a repoUrl for your workspace, check `context.yaml`")
}

Expand Down Expand Up @@ -133,7 +133,7 @@ func Build(cloud bool) (*Context, error) {
}, nil
}

func (context *Context) backfillConsoleContext(_ *manifest.ProjectManifest) error {
func (c *Context) backfillConsoleContext(_ *manifest.ProjectManifest) error {
path := manifest.ContextPath()
ctx, err := manifest.FetchContext()
if err != nil {
Expand All @@ -153,13 +153,13 @@ func (context *Context) backfillConsoleContext(_ *manifest.ProjectManifest) erro
}

if strings.HasPrefix(url, "http") {
return context.backfillHTTPS(url, console, ctx, path)
return c.backfillHTTPS(url, console, ctx, path)
}

return context.backfillSSH(url, console, ctx, path)
return c.backfillSSH(url, console, ctx, path)
}

func (context *Context) backfillSSH(url string, console map[string]interface{}, ctx *manifest.Context, path string) error {
func (c *Context) backfillSSH(url string, console map[string]interface{}, ctx *manifest.Context, path string) error {
utils.Highlight("If you want, you can use `plural crypto ssh-keygen` to generate a keypair to use as a deploy key as well\n\n")

files, err := filepath.Glob(filepath.Join(os.Getenv("HOME"), ".ssh", "*"))
Expand Down Expand Up @@ -188,7 +188,7 @@ func (context *Context) backfillSSH(url string, console map[string]interface{},
return err
}

if !context.ignorePreflights {
if !c.ignorePreflights {
if err := verifySSHKey(contents, url); err != nil {
return fmt.Errorf("ssh key not valid for url %s, error: %w. If you want to bypass this check, you can use the --ignore-preflights flag", url, err)
}
Expand All @@ -197,11 +197,11 @@ func (context *Context) backfillSSH(url string, console map[string]interface{},
console["repo_url"] = url
console["private_key"] = contents
ctx.Configuration["console"] = console
context.RepoUrl = url
c.RepoUrl = url
return ctx.Write(path)
}

func (context *Context) backfillHTTPS(url string, console map[string]interface{}, ctx *manifest.Context, path string) error {
func (c *Context) backfillHTTPS(url string, console map[string]interface{}, ctx *manifest.Context, path string) error {
utils.Highlight("If you want, you can also reclone with an SSH URL and re-run to use deploy-key authentication instead\n\n")

var username, token string
Expand All @@ -219,7 +219,7 @@ func (context *Context) backfillHTTPS(url string, console map[string]interface{}
return err
}

if !context.ignorePreflights {
if !c.ignorePreflights {
if err := verifyHTTPS(username, token, url); err != nil {
return fmt.Errorf("PAT not valid for url %s, error: %w. If you want to bypass this check, you can use the --ignore-preflights flag", url, err)
}
Expand All @@ -229,9 +229,9 @@ func (context *Context) backfillHTTPS(url string, console map[string]interface{}
console["git_username"] = username
console["git_password"] = token
ctx.Configuration["console"] = console
context.RepoUrl = url
context.GitUsername = username
context.GitPassword = token
c.RepoUrl = url
c.GitUsername = username
c.GitPassword = token
return ctx.Write(path)
}

Expand Down
Loading
Loading