Skip to content

Commit

Permalink
Merge pull request #17675 from wallyworld/merge-3.5-20240708
Browse files Browse the repository at this point in the history
#17675

Merge 3.5

#17647 [from ycliuhw/fix-misleading-error4strictly-…](7489150)
#17644 [from Aflynn50/fix-refresh-command-docs](39772ee)
#17641 [from hpidcock/fix-secretexpire-worker-tests](c7a6f6f)
#17615 [from kian99/revert-move-session-token-login…](acecfaa)
#17665 [from gfouillet/doc/use_endpoint_instead_of_…](3f404f4)
#17662 [from wallyworld/fix-lxd-profile](a3617b6)
  • Loading branch information
jujubot committed Jul 8, 2024
2 parents 8ec4c30 + 2958d8d commit d5c3726
Show file tree
Hide file tree
Showing 39 changed files with 503 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/terraform-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

smoke:
name: Terraform Smoke
runs-on: [self-hosted, linux, x64, aws, xlarge]
runs-on: [self-hosted, linux, x64, aws, xxlarge]
if: github.event.pull_request.draft == false
steps:

Expand Down
3 changes: 3 additions & 0 deletions api/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var (
SlideAddressToFront = slideAddressToFront
FacadeVersions = &facadeVersions

LoginDeviceAPICall = &loginDeviceAPICall
GetDeviceSessionTokenAPICall = &getDeviceSessionTokenAPICall
LoginWithSessionTokenAPICall = &loginWithSessionTokenAPICall
LoginWithClientCredentialsAPICall = &loginWithClientCredentialsAPICall
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// for login normally used by the CLI.
// These are contrasted with login providers defined elsewhere which may not
// require interactive login.
package loginprovider
package api

import (
"context"
Expand All @@ -14,7 +14,6 @@ import (

"github.com/juju/errors"

"github.com/juju/juju/api"
"github.com/juju/juju/api/base"
"github.com/juju/juju/rpc/params"
)
Expand Down Expand Up @@ -59,7 +58,7 @@ type sessionTokenLoginProvider struct {
//
// It authenticates as the entity using the specified session token.
// Subsequent requests on the state will act as that entity.
func (p *sessionTokenLoginProvider) Login(ctx context.Context, caller base.APICaller) (*api.LoginResultParams, error) {
func (p *sessionTokenLoginProvider) Login(ctx context.Context, caller base.APICaller) (*LoginResultParams, error) {
// First we try to log in using the session token we have.
result, err := p.login(ctx, caller)
if err == nil {
Expand Down Expand Up @@ -128,7 +127,7 @@ func (p *sessionTokenLoginProvider) initiateDeviceLogin(ctx context.Context, cal
return p.updateAccountDetailsFunc(sessionTokenResult.SessionToken)
}

func (p *sessionTokenLoginProvider) login(ctx context.Context, caller base.APICaller) (*api.LoginResultParams, error) {
func (p *sessionTokenLoginProvider) login(ctx context.Context, caller base.APICaller) (*LoginResultParams, error) {
var result params.LoginResult
request := struct {
SessionToken string `json:"session-token"`
Expand All @@ -141,5 +140,5 @@ func (p *sessionTokenLoginProvider) login(ctx context.Context, caller base.APICa
return nil, errors.Trace(err)
}

return api.NewLoginResultParams(result)
return NewLoginResultParams(result)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2024 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package loginprovider_test
package api_test

import (
"bytes"
Expand All @@ -14,7 +14,6 @@ import (

"github.com/juju/juju/api"
"github.com/juju/juju/api/base"
"github.com/juju/juju/cmd/internal/loginprovider"
jujutesting "github.com/juju/juju/juju/testing"
"github.com/juju/juju/rpc/params"
)
Expand All @@ -34,7 +33,7 @@ func (s *sessionTokenLoginProviderProviderSuite) Test(c *gc.C) {

var obtainedSessionToken string

s.PatchValue(loginprovider.LoginDeviceAPICall, func(_ base.APICaller, request interface{}, response interface{}) error {
s.PatchValue(api.LoginDeviceAPICall, func(_ base.APICaller, request interface{}, response interface{}) error {
lr := struct {
UserCode string `json:"user-code"`
VerificationURI string `json:"verification-uri"`
Expand All @@ -51,7 +50,7 @@ func (s *sessionTokenLoginProviderProviderSuite) Test(c *gc.C) {
return json.Unmarshal(data, response)
})

s.PatchValue(loginprovider.GetDeviceSessionTokenAPICall, func(_ base.APICaller, request interface{}, response interface{}) error {
s.PatchValue(api.GetDeviceSessionTokenAPICall, func(_ base.APICaller, request interface{}, response interface{}) error {
lr := struct {
SessionToken string `json:"session-token"`
}{
Expand All @@ -66,7 +65,7 @@ func (s *sessionTokenLoginProviderProviderSuite) Test(c *gc.C) {
return json.Unmarshal(data, response)
})

s.PatchValue(loginprovider.LoginWithSessionTokenAPICall, func(_ base.APICaller, request interface{}, response interface{}) error {
s.PatchValue(api.LoginWithSessionTokenAPICall, func(_ base.APICaller, request interface{}, response interface{}) error {
data, err := json.Marshal(request)
if err != nil {
return errors.Trace(err)
Expand Down Expand Up @@ -108,7 +107,7 @@ func (s *sessionTokenLoginProviderProviderSuite) Test(c *gc.C) {
ControllerUUID: info.ControllerUUID,
CACert: info.CACert,
}, api.DialOpts{
LoginProvider: loginprovider.NewSessionTokenLoginProvider(
LoginProvider: api.NewSessionTokenLoginProvider(
"expired-token",
&output,
func(sessionToken string) error {
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions apiserver/common/charms/appcharminfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
facademocks "github.com/juju/juju/apiserver/facade/mocks"
"github.com/juju/juju/core/permission"
"github.com/juju/juju/rpc/params"
"github.com/juju/juju/state"
)

type appCharmInfoSuite struct{}
Expand Down Expand Up @@ -47,7 +46,7 @@ func (s *appCharmInfoSuite) TestBasic(c *gc.C) {
ch.EXPECT().Actions().Return(&charm.Actions{})
ch.EXPECT().Metrics().Return(&charm.Metrics{})
ch.EXPECT().Manifest().Return(&charm.Manifest{})
ch.EXPECT().LXDProfile().Return(&state.LXDProfile{})
ch.EXPECT().LXDProfile().Return(&charm.LXDProfile{})

authorizer := facademocks.NewMockAuthorizer(ctrl)
authorizer.EXPECT().AuthController().Return(true)
Expand Down Expand Up @@ -134,7 +133,7 @@ func (s *appCharmInfoSuite) TestSidecarCharm(c *gc.C) {
ch.EXPECT().Actions().Return(&charm.Actions{})
ch.EXPECT().Metrics().Return(&charm.Metrics{})
ch.EXPECT().Manifest().Return(&charm.Manifest{})
ch.EXPECT().LXDProfile().Return(&state.LXDProfile{})
ch.EXPECT().LXDProfile().Return(&charm.LXDProfile{})

authorizer := facademocks.NewMockAuthorizer(ctrl)
authorizer.EXPECT().AuthController().Return(true)
Expand Down
3 changes: 1 addition & 2 deletions apiserver/common/charms/charminfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
facademocks "github.com/juju/juju/apiserver/facade/mocks"
"github.com/juju/juju/core/permission"
"github.com/juju/juju/rpc/params"
"github.com/juju/juju/state"
)

type charmInfoSuite struct{}
Expand All @@ -41,7 +40,7 @@ func (s *charmInfoSuite) TestBasic(c *gc.C) {
ch.EXPECT().Actions().Return(&charm.Actions{})
ch.EXPECT().Metrics().Return(&charm.Metrics{})
ch.EXPECT().Manifest().Return(&charm.Manifest{})
ch.EXPECT().LXDProfile().Return(&state.LXDProfile{})
ch.EXPECT().LXDProfile().Return(&charm.LXDProfile{})
ch.EXPECT().URL().Return("ch:foo-1")

authorizer := facademocks.NewMockAuthorizer(ctrl)
Expand Down
4 changes: 2 additions & 2 deletions apiserver/common/charms/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Charm interface {
Manifest() *charm.Manifest
Metrics() *charm.Metrics
Actions() *charm.Actions
LXDProfile() *state.LXDProfile
LXDProfile() *charm.LXDProfile
}

type Model interface {
Expand Down Expand Up @@ -335,7 +335,7 @@ func convertCharmExtraBindingMap(bindings map[string]charm.ExtraBinding) map[str
return result
}

func convertCharmLXDProfile(profile *state.LXDProfile) *params.CharmLXDProfile {
func convertCharmLXDProfile(profile *charm.LXDProfile) *params.CharmLXDProfile {
return &params.CharmLXDProfile{
Description: profile.Description,
Config: convertCharmLXDProfileConfig(profile.Config),
Expand Down
5 changes: 2 additions & 3 deletions apiserver/common/charms/mocks/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apiserver/facades/client/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (s *applicationSuite) TestApplicationDeployToMachineWithLXDProfile(c *gc.C)
c.Assert(expected.Config(), gc.DeepEquals, ch.Config())

expectedProfile := ch.(charm.LXDProfiler).LXDProfile()
c.Assert(expected.LXDProfile(), gc.DeepEquals, &state.LXDProfile{
c.Assert(expected.LXDProfile(), gc.DeepEquals, &charm.LXDProfile{
Description: expectedProfile.Description,
Config: expectedProfile.Config,
Devices: expectedProfile.Devices,
Expand Down Expand Up @@ -357,7 +357,7 @@ func (s *applicationSuite) TestApplicationDeployToMachineWithInvalidLXDProfileAn
c.Assert(expected.Config(), gc.DeepEquals, ch.Config())

expectedProfile := ch.(charm.LXDProfiler).LXDProfile()
c.Assert(expected.LXDProfile(), gc.DeepEquals, &state.LXDProfile{
c.Assert(expected.LXDProfile(), gc.DeepEquals, &charm.LXDProfile{
Description: expectedProfile.Description,
Config: expectedProfile.Config,
Devices: expectedProfile.Devices,
Expand Down
10 changes: 0 additions & 10 deletions cmd/internal/loginprovider/export_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/internal/loginprovider/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package loginprovider
import (
"testing"

coretesting "github.com/juju/juju/testing"
gc "gopkg.in/check.v1"
)

func TestPackage(t *testing.T) {
coretesting.MgoTestPackage(t)
gc.TestingT(t)
}
1 change: 1 addition & 0 deletions cmd/internal/loginprovider/tryinorderloginprovider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2024 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

// Contains login providers required only by the Juju CLI.
package loginprovider

import (
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/application/integrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (c *addRelationCommand) Info() *cmd.Info {
addCmd := &cmd.Info{
Name: "integrate",
Aliases: []string{"relate"},
Args: "<application>[:<relation>] <application>[:<relation>]",
Args: "<application>[:<endpoint>] <application>[:<endpoint>]",
Purpose: "Integrate two applications.",
Doc: integrateDoc,
Examples: integrateExamples,
Expand Down
4 changes: 2 additions & 2 deletions cmd/juju/application/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ is determined by the contents of the charm at the specified path.
--switch and --revision are mutually exclusive.
Use of the --force-units option is not generally recommended; units upgraded
while in an error state will not have refreshed hooks executed, and may cause
unexpected behavior.
while in an error state will not have upgrade-charm hooks executed, and may
cause unexpected behavior.
--force option for LXD Profiles is not generally recommended when upgrading an
application; overriding profiles on the container may cause unexpected
Expand Down
26 changes: 10 additions & 16 deletions cmd/juju/caas/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,34 +876,28 @@ func (c *AddCAASCommand) getClusterMetadataFunc(ctx *cmd.Context) provider.GetCl
}

func (c *AddCAASCommand) verifyName(name string) error {
public, _, err := c.cloudMetadataStore.PublicCloudMetadata()
if err != nil {
return err
if name == k8s.K8sCloudMicrok8s {
return fmt.Errorf(`%q is the name of a built-in cloud.
If you want to use Juju with microk8s, the recommended way is to install the strictly confined microk8s snap.
Using the strictly confined microk8s snap means that Juju and microk8s will work together out of the box.`, name)
}
msg, err := nameExists(name, public)

public, _, err := c.cloudMetadataStore.PublicCloudMetadata()
if err != nil {
return errors.Trace(err)
}
if msg != "" {
return errors.Errorf(msg)
}
return nil
}

// nameExists returns either an empty string if the name does not exist, or a
// non-empty string with an error message if it does exist.
func nameExists(name string, public map[string]jujucloud.Cloud) (string, error) {
if _, ok := public[name]; ok {
return fmt.Sprintf("%q is the name of a public cloud", name), nil
return fmt.Errorf("%q is the name of a public cloud", name)
}
builtin, err := common.BuiltInClouds()
if err != nil {
return "", errors.Trace(err)
return errors.Trace(err)
}
if _, ok := builtin[name]; ok {
return fmt.Sprintf("%q is the name of a built-in cloud", name), nil
return fmt.Errorf("%q is the name of a built-in cloud", name)
}
return "", nil
return nil
}

func addCloudToLocal(cloudMetadataStore CloudMetadataStore, newCloud jujucloud.Cloud) error {
Expand Down
9 changes: 9 additions & 0 deletions cmd/juju/caas/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,15 @@ func (s *addCAASSuite) TestMissingName(c *gc.C) {
c.Assert(err, gc.ErrorMatches, `missing k8s name.`)
}

func (s *addCAASSuite) TestInvalidName(c *gc.C) {
command := s.makeCommand(c, true, true, true)
_, err := s.runCommand(c, nil, command, "microk8s")
c.Assert(err, gc.ErrorMatches, `
"microk8s" is the name of a built-in cloud.
If you want to use Juju with microk8s, the recommended way is to install the strictly confined microk8s snap.
Using the strictly confined microk8s snap means that Juju and microk8s will work together out of the box.`[1:])
}

func (s *addCAASSuite) TestMissingArgs(c *gc.C) {
command := s.makeCommand(c, true, true, true)
_, err := s.runCommand(c, nil, command)
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/commands/upgradecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Upgrades Juju on a controller.`[1:]
var usageUpgradeControllerDetails = `
This command upgrades the Juju agent for a controller.
A controller's agent version can be shown with `[1:] + "`juju model-config -m controller agent-\nversion`" + `.
A controller's agent version can be shown with `[1:] + "`juju model-config -m controller agent-version`" + `.
A version is denoted by: major.minor.patch
You can upgrade the controller to a new patch version by specifying
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/commands/upgrademodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var usageUpgradeJujuDetails = `
Juju provides agent software to every machine it creates. This command
upgrades that software across an entire model, which is, by default, the
current model.
A model's agent version can be shown with `[1:] + "`juju model-config agent-\nversion`" + `.
A model's agent version can be shown with `[1:] + "`juju model-config agent-version`" + `.
A version is denoted by: major.minor.patch
If '--agent-version' is not specified, then the upgrade candidate is
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/controller/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (c *registerCommand) publicControllerDetails(ctx *cmd.Context, host, contro
// user-pass or macaroons.
dialOpts.LoginProvider = loginprovider.NewTryInOrderLoginProvider(
loggo.GetLogger("juju.cmd.loginprovider"),
loginprovider.NewSessionTokenLoginProvider(
api.NewSessionTokenLoginProvider(
"",
ctx.Stderr,
func(sessionToken string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/user/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (c *loginCommand) publicControllerLogin(

dialOpts.LoginProvider = loginprovider.NewTryInOrderLoginProvider(
loggo.GetLogger("juju.cmd.loginprovider"),
loginprovider.NewSessionTokenLoginProvider(
api.NewSessionTokenLoginProvider(
sessionToken,
ctx.Stderr,
func(sessionToken string) error {
Expand Down
3 changes: 1 addition & 2 deletions cmd/modelcmd/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/juju/juju/api/client/modelmanager"
k8sproxy "github.com/juju/juju/caas/kubernetes/provider/proxy"
"github.com/juju/juju/cloud"
"github.com/juju/juju/cmd/internal/loginprovider"
"github.com/juju/juju/core/network"
"github.com/juju/juju/environs"
environscloudspec "github.com/juju/juju/environs/cloudspec"
Expand Down Expand Up @@ -593,7 +592,7 @@ func newAPIConnectionParams(
dialOpts.BakeryClient = bakery

if accountDetails.Type == jujuclient.OAuth2DeviceFlowAccountDetailsType {
dialOpts.LoginProvider = loginprovider.NewSessionTokenLoginProvider(
dialOpts.LoginProvider = api.NewSessionTokenLoginProvider(
accountDetails.SessionToken,
cmdOut,
func(sessionToken string) error {
Expand Down
Loading

0 comments on commit d5c3726

Please sign in to comment.