Skip to content

Commit

Permalink
Merge pull request juju#17776 from Aflynn50/3.4-3.5
Browse files Browse the repository at this point in the history
juju#17776

There were no merge conflicts in this merge up. This merge contains the following PRs:
- juju#17772 from Aflynn50
- juju#17700 from Aflynn50
- juju#17756 from nvinuesa

Did some quick QA for the external users:
```
juju bootstrap lxd test-external-34 --config identity-url=https://api.jujucharms.com/identity --config allow-model-access=true
juju add-model default
juju grant aflynn50@external superuser
juju change-user-password
juju logout
juju login -u aflynn50@external
juju status
```
  • Loading branch information
jujubot authored Jul 19, 2024
2 parents be42383 + c2583f3 commit d530790
Show file tree
Hide file tree
Showing 11 changed files with 764 additions and 48 deletions.
35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,38 @@ with an environment variable:
JUJU_NOTEST_MONGOJS=1 go test github.com/juju/juju/...
```

Conventional commits
--------------------

Once you have written some code and have tested the changes, the next step is to
`git commit` it. For commit messages Juju follows [conventional commits guidelines](doc/conventional-commits.md).
In short the commits should be of the following form:
```
<type>(optional <scope>): <description>
[optional body]
[optional footer(s)]
```
- **Type:** The type describes the kind of change (e.g., feat, fix, docs, style,
refactor, test, chore).
- **Scope:** The scope indicates the part of the codebase affected (e.g., model,
api, cli).
- **Description:** The description briefly describes the change. It should not
end in any punctuation.
- **Body:** The body should be a detailed explanation of the change. It should
specify what has been changed and why and include descriptions of the
behaviour before and after.
- **Footer:** The footer includes information about breaking changes, issues
closed, etc.

The type, scope and description should all begin with a lower case letter. None
of the lines can exceed 100 characters in length.

There is a CI action on the Juju GitHub repository that will flag any syntactic
issues with your commit messages. The action is required to pass before code can
be merged so make sure to take a look once your PR is up.

Pushing
-------

Expand All @@ -318,6 +350,9 @@ Go to the web page (https://github.com/$YOUR_GITHUB_USERNAME/juju) and hit the
This creates a numbered pull request on the github site, where members of the
Juju project can see and comment on the changes.

The title of the PR should match the form of the title of a conventional commit.
This can be the title of the most significant commit in the PR.

Make sure to add a clear description of why and what has been changed, and
include the Launchpad bug number if one exists.

Expand Down
16 changes: 6 additions & 10 deletions cmd/modelcmd/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,12 @@ func processAccountDetails(accountDetails *jujuclient.AccountDetails) *jujuclien
} else {
u := names.NewUserTag(accountDetails.User)
if !u.IsLocal() {
if len(accountDetails.Macaroons) == 0 {
accountDetails = &jujuclient.AccountDetails{}
} else {
// If the account has macaroon set, use those to login
// to avoid an unnecessary auth round trip.
// Used for embedded commands.
accountDetails = &jujuclient.AccountDetails{
User: u.Id(),
Macaroons: accountDetails.Macaroons,
}
// If the account has macaroon set, use those to login
// to avoid an unnecessary auth round trip.
// Used for embedded commands.
accountDetails = &jujuclient.AccountDetails{
User: u.Id(),
Macaroons: accountDetails.Macaroons,
}
}
}
Expand Down
42 changes: 41 additions & 1 deletion cmd/modelcmd/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
cookiejar "github.com/juju/persistent-cookiejar"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
"go.uber.org/mock/gomock"
gc "gopkg.in/check.v1"
"gopkg.in/macaroon-bakery.v2/httpbakery"
"gopkg.in/macaroon.v2"
Expand All @@ -25,6 +26,7 @@ import (
apitesting "github.com/juju/juju/api/testing"
"github.com/juju/juju/cloud"
"github.com/juju/juju/cmd/modelcmd"
"github.com/juju/juju/cmd/modelcmd/mocks"
"github.com/juju/juju/core/model"
"github.com/juju/juju/core/network"
"github.com/juju/juju/environs"
Expand Down Expand Up @@ -190,6 +192,42 @@ To access it run 'juju switch bar:admin/badmodel'.`,
}
}

func (s *BaseCommandSuite) setupMocks(c *gc.C) *gomock.Controller {
ctrl := gomock.NewController(c)
return ctrl
}

func (s *BaseCommandSuite) TestNewAPIRootExternalUser(c *gc.C) {
ctrl := s.setupMocks(c)
conn := mocks.NewMockConnection(ctrl)
apiOpen := func(info *api.Info, opts api.DialOpts) (api.Connection, error) {
return conn, nil
}
externalName := "alastair@external"
conn.EXPECT().AuthTag().Return(names.NewUserTag(externalName)).MinTimes(1)
conn.EXPECT().APIHostPorts()
conn.EXPECT().ServerVersion()
conn.EXPECT().Addr()
conn.EXPECT().IPAddr()
conn.EXPECT().PublicDNSName()
conn.EXPECT().ControllerAccess().MinTimes(1)

s.store.Accounts["foo"] = jujuclient.AccountDetails{
User: externalName,
}

baseCmd := new(modelcmd.ModelCommandBase)
baseCmd.SetClientStore(s.store)
baseCmd.SetAPIOpen(apiOpen)
modelcmd.InitContexts(&cmd.Context{Stderr: io.Discard}, baseCmd)
modelcmd.SetRunStarted(baseCmd)

c.Assert(baseCmd.SetModelIdentifier("foo:admin/badmodel", false), jc.ErrorIsNil)

_, err := baseCmd.NewAPIRoot()
c.Assert(err, jc.ErrorIsNil)
}

type NewGetBootstrapConfigParamsFuncSuite struct {
testing.IsolationSuite
}
Expand Down Expand Up @@ -462,7 +500,9 @@ func (s *BaseCommandSuite) TestProcessAccountDetails(c *gc.C) {
input: jujuclient.AccountDetails{
User: names.NewUserTag("[email protected]").String(),
},
expectedOutput: jujuclient.AccountDetails{},
expectedOutput: jujuclient.AccountDetails{
User: names.NewUserTag("[email protected]").String(),
},
}}
for i, test := range tests {
c.Logf("running test case %d", i)
Expand Down
Loading

0 comments on commit d530790

Please sign in to comment.