github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/apiserver/facades/client/charms/interface.go (about)

     1  // Copyright 2020 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package charms
     5  
     6  import (
     7  	"github.com/juju/charm/v12"
     8  	"github.com/juju/errors"
     9  
    10  	"github.com/juju/juju/apiserver/facades/client/charms/interfaces"
    11  	"github.com/juju/juju/apiserver/facades/client/charms/services"
    12  	"github.com/juju/juju/state"
    13  )
    14  
    15  type stateShim struct {
    16  	*state.State
    17  }
    18  
    19  func newStateShim(st *state.State) interfaces.BackendState {
    20  	return stateShim{
    21  		State: st,
    22  	}
    23  }
    24  
    25  func (s stateShim) UpdateUploadedCharm(charmInfo state.CharmInfo) (services.UploadedCharm, error) {
    26  	ch, err := s.State.UpdateUploadedCharm(charmInfo)
    27  	if err != nil {
    28  		return nil, errors.Trace(err)
    29  	}
    30  	return stateCharmShim{Charm: ch}, nil
    31  }
    32  
    33  func (s stateShim) PrepareCharmUpload(curl string) (services.UploadedCharm, error) {
    34  	ch, err := s.State.PrepareCharmUpload(curl)
    35  	if err != nil {
    36  		return nil, errors.Trace(err)
    37  	}
    38  	return stateCharmShim{Charm: ch}, nil
    39  }
    40  
    41  func (s stateShim) Application(name string) (interfaces.Application, error) {
    42  	app, err := s.State.Application(name)
    43  	if err != nil {
    44  		return nil, errors.Trace(err)
    45  	}
    46  	return stateApplicationShim{Application: app}, nil
    47  }
    48  
    49  func (s stateShim) Machine(machineID string) (interfaces.Machine, error) {
    50  	machine, err := s.State.Machine(machineID)
    51  	return machine, errors.Trace(err)
    52  }
    53  
    54  type stateApplicationShim struct {
    55  	*state.Application
    56  }
    57  
    58  func (s stateApplicationShim) AllUnits() ([]interfaces.Unit, error) {
    59  	units, err := s.Application.AllUnits()
    60  	if err != nil {
    61  		return nil, errors.Trace(err)
    62  	}
    63  	results := make([]interfaces.Unit, len(units))
    64  	for i, unit := range units {
    65  		results[i] = unit
    66  	}
    67  	return results, nil
    68  }
    69  
    70  type stateCharmShim struct {
    71  	*state.Charm
    72  }
    73  
    74  func (s stateCharmShim) IsUploaded() bool {
    75  	return s.Charm.IsUploaded()
    76  }
    77  
    78  // StoreCharm represents a store charm.
    79  type StoreCharm interface {
    80  	charm.Charm
    81  	charm.LXDProfiler
    82  	Version() string
    83  }