Skip to content

Commit

Permalink
Prevent addr and --local
Browse files Browse the repository at this point in the history
  • Loading branch information
ale8k committed Jul 12, 2023
1 parent 6b12154 commit 30488ff
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd/jimmctl/cmd/controllerinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ func (c *controllerInfoCommand) Run(ctxt *cmd.Context) error {
Username: account.User,
Password: account.Password,
}

info.PublicAddress = c.publicAddress
if c.local {
info.PublicAddress = controller.APIEndpoints[0]
info.CACertificate = controller.CACert
} else {
if c.publicAddress != "" {
info.PublicAddress = c.publicAddress
} else {
return errors.New("public address must be set")
}
}
if info.PublicAddress == "" {
return errors.New("public address must be set")
}
if c.local && len(c.publicAddress) > 0 {
return errors.New("please do not set both the address argument and the local flag")
}

data, err := yaml.Marshal(info)
Expand Down
45 changes: 45 additions & 0 deletions cmd/jimmctl/cmd/controllerinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,48 @@ func (s *controllerInfoSuite) TestControllerInfoMissingPublicAddressAndNoLocalFl
_, err = cmdtesting.RunCommand(c, cmd.NewControllerInfoCommandForTesting(store), "controller-1", fname)
c.Assert(err, gc.ErrorMatches, "public address must be set")
}

func (s *controllerInfoSuite) TestControllerInfoCannotProvideAddrAndLocalFlag(c *gc.C) {
store := s.ClientStore()
store.Controllers["controller-1"] = jujuclient.ControllerDetails{
APIEndpoints: []string{"127.0.0.1:17070"},
PublicDNSName: "controller1.example.com",
CACert: `-----BEGIN CERTIFICATE-----
MIID/jCCAmagAwIBAgIVANxsMrzsXrdpjjUoxWQm1RCkmWcqMA0GCSqGSIb3DQEB
CwUAMCYxDTALBgNVBAoTBEp1anUxFTATBgNVBAMTDGp1anUgdGVzdGluZzAeFw0y
MDA0MDgwNTI3NTBaFw0zMDA0MDgwNTMyNTBaMCYxDTALBgNVBAoTBEp1anUxFTAT
BgNVBAMTDGp1anUgdGVzdGlu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Vik
hZuWHpuOT120okoutwuUSU9448cXLGZfoCZjjdMKXmOj8EEec1diDP4mhegYGezD
LQRNNlaY2ajLt0paowf/Xxb8
-----END CERTIFICATE-----`,
}
store.Accounts["controller-1"] = jujuclient.AccountDetails{
User: "test-user",
Password: "super-secret-password",
}

dir, err := ioutil.TempDir("", "controller-info-test")
c.Assert(err, gc.Equals, nil)
defer os.RemoveAll(dir)

fname := path.Join(dir, "test.yaml")

_, err = cmdtesting.RunCommand(c, cmd.NewControllerInfoCommandForTesting(store), "controller-1", fname, "myaddress", "--local")
c.Assert(err, gc.ErrorMatches, "please do not set both the address argument and the local flag")
}

0 comments on commit 30488ff

Please sign in to comment.