Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit 2b34379

Browse files
mr-olivaShu Kutsuzawa
authored andcommitted
add args about hostname and domain (#1)
* add args about hostname and domain * change args in plug/commnd. made PushArgs structure
1 parent 64e00a7 commit 2b34379

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

main.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,18 @@ func (c *CfPushWithVault) Run(cliConnection plugin.CliConnection, args []string)
6060
Variables: variables,
6161
}
6262

63-
if err := command.Push(fc.String("file"), fc.Args()[1:]); err != nil {
63+
appName := ""
64+
if len(fc.Args()) == 2 {
65+
appName = fc.Args()[1]
66+
}
67+
pushArgs := plug.PushArgs{
68+
AppName: appName,
69+
ManifestFile: fc.String("file"),
70+
Hostname: fc.String("hostname"),
71+
Domain: fc.String("domain"),
72+
}
73+
74+
if err := command.Push(pushArgs); err != nil {
6475
fmt.Fprintf(os.Stdout, "failed to push with vault: %v", err)
6576
os.Exit(1)
6677
}
@@ -82,10 +93,12 @@ func (c *CfPushWithVault) GetMetadata() plugin.PluginMetadata {
8293
UsageDetails: plugin.Usage{
8394
Usage: "$ cf push-with-vault [APP_NAME]",
8495
Options: map[string]string{
85-
"-file": "Path to manifest (default: ./manifest.yml)",
86-
"-vault-addr": "Address of the Vault server expressed as a URL and port, for example: https://127.0.0.1:8200/. (default: \"VAULT_ADDR\" env)",
87-
"-vault-token": "Vault authentication token. (default: \"VAULT_TOKEN\" env)",
88-
"-path-prefix": "Path under which to namespace credential lookup",
96+
"-file, -f": "Path to manifest (default: ./manifest.yml)",
97+
"-vault-addr, -va": "Address of the Vault server expressed as a URL and port, for example: https://127.0.0.1:8200/. (default: \"VAULT_ADDR\" env)",
98+
"-vault-token, -vt": "Vault authentication token. (default: \"VAULT_TOKEN\" env)",
99+
"-path-prefix, -pp": "Path under which to namespace credential lookup",
100+
"-hostname, -n": "Hostname (e.g. my-subdomain)",
101+
"-domain, -d": "Specify a custom domain (e.g. private-domain.example.com, apps.internal.com) to use instead of the default domain",
89102
},
90103
},
91104
},
@@ -99,6 +112,8 @@ func (c *CfPushWithVault) parseArgs(args []string) (flags.FlagContext, error) {
99112
fc.NewStringFlagWithDefault("vault-addr", "va", "Address of the Vault server expressed as a URL and port", c.VaultAddr)
100113
fc.NewStringFlagWithDefault("vault-token", "vt", "Vault authentication token", c.VaultToken)
101114
fc.NewStringFlagWithDefault("path-prefix", "pp", "Path under which to namespace credential lookup", "")
115+
fc.NewStringFlagWithDefault("hostname", "n", "Hostname", "")
116+
fc.NewStringFlagWithDefault("domain", "d", "Specify a custom domain", "")
102117
err := fc.Parse(args...)
103118
return fc, err
104119
}

plug/command.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,32 @@ type Command struct {
1717
Variables vault.Variables
1818
}
1919

20+
// PushArgs is information for "cf push"
21+
type PushArgs struct {
22+
AppName string
23+
ManifestFile string
24+
Hostname string
25+
Domain string
26+
}
27+
28+
func (p *PushArgs) toStringArray() []string {
29+
args := []string{"push"}
30+
if p.AppName != "" {
31+
args = append(args, p.AppName)
32+
}
33+
if p.Hostname != "" {
34+
args = append(args, "-n", p.Hostname)
35+
}
36+
if p.Domain != "" {
37+
args = append(args, "-d", p.Domain)
38+
}
39+
return append(args, "-f", p.ManifestFile)
40+
}
41+
2042
// Push pushes cf app based on manifest
21-
func (c *Command) Push(file string, args []string) error {
43+
func (c *Command) Push(args PushArgs) error {
2244
// read file
23-
absFile, err := filepath.Abs(file)
45+
absFile, err := filepath.Abs(args.ManifestFile)
2446
if err != nil {
2547
return err
2648
}
@@ -41,10 +63,10 @@ func (c *Command) Push(file string, args []string) error {
4163
if err != nil {
4264
return err
4365
}
66+
args.ManifestFile = tmpFile.Name()
4467

45-
args = append([]string{"push", "-f", tmpFile.Name()}, args...)
4668
// cf push
47-
if _, err := c.CliConnection.CliCommand(args...); err != nil {
69+
if _, err := c.CliConnection.CliCommand(args.toStringArray()...); err != nil {
4870
return err
4971
}
5072

plug/command_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
. "github.com/onsi/ginkgo"
66
. "github.com/onsi/gomega"
77

8+
"github.com/cappyzawa/cf-push-with-vault/plug"
89
. "github.com/cappyzawa/cf-push-with-vault/plug"
910
"github.com/cappyzawa/cf-push-with-vault/vault/vaultfakes"
1011
)
@@ -27,14 +28,22 @@ var _ = Describe("Command", func() {
2728

2829
Describe("Push()", func() {
2930
Context("manifest file is missing", func() {
31+
pArgs := plug.PushArgs{
32+
AppName: "testApp",
33+
ManifestFile: "../testdata/missing.yml",
34+
}
3035
It("an error is occurred", func() {
31-
err := command.Push("../testdata/missing.yml", []string{"testApp"})
36+
err := command.Push(pArgs)
3237
Expect(err).To(HaveOccurred())
3338
})
3439
})
3540
Context("manifest file does not contain parameters", func() {
41+
pArgs := plug.PushArgs{
42+
AppName: "testApp",
43+
ManifestFile: "../testdata/no_contains_params.yml",
44+
}
3645
It("access to the vault does not occur", func() {
37-
err := command.Push("../testdata/no_contains_params.yml", []string{"testApp"})
46+
err := command.Push(pArgs)
3847
Expect(fakeVariables.GetCallCount()).To(BeZero())
3948
Expect(err).NotTo(HaveOccurred())
4049
})
@@ -44,8 +53,12 @@ var _ = Describe("Command", func() {
4453
fakeVariables.GetReturns(nil, true, nil)
4554
fakeVariables.GetReturns(nil, true, nil)
4655
})
56+
pArgs := plug.PushArgs{
57+
AppName: "testApp",
58+
ManifestFile: "../testdata/multi_params.yml",
59+
}
4760
It("access to the vault occurs multiple times", func() {
48-
err := command.Push("../testdata/multi_params.yml", []string{"testApp"})
61+
err := command.Push(pArgs)
4962
Expect(fakeVariables.GetCallCount()).To(Equal(2))
5063
Expect(err).NotTo(HaveOccurred())
5164
})

0 commit comments

Comments
 (0)