github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/worker/uniter/runner/jujuc/restricted.go (about)

     1  // Copyright 2012-2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package jujuc
     5  
     6  import (
     7  	"time"
     8  
     9  	"github.com/juju/charm/v12"
    10  	"github.com/juju/errors"
    11  	"github.com/juju/names/v5"
    12  
    13  	"github.com/juju/juju/core/application"
    14  	"github.com/juju/juju/core/network"
    15  	"github.com/juju/juju/core/payloads"
    16  	"github.com/juju/juju/core/secrets"
    17  	"github.com/juju/juju/rpc/params"
    18  )
    19  
    20  // ErrRestrictedContext indicates a method is not implemented in the given context.
    21  var ErrRestrictedContext = errors.NotImplementedf("not implemented for restricted context")
    22  
    23  // RestrictedContext is a base implementation for restricted contexts to embed,
    24  // so that an error is returned for methods that are not explicitly
    25  // implemented.
    26  type RestrictedContext struct{}
    27  
    28  // ConfigSettings implements hooks.Context.
    29  func (*RestrictedContext) ConfigSettings() (charm.Settings, error) { return nil, ErrRestrictedContext }
    30  
    31  // GoalState implements hooks.Context.
    32  func (*RestrictedContext) GoalState() (*application.GoalState, error) {
    33  	return &application.GoalState{}, ErrRestrictedContext
    34  }
    35  
    36  // GetCharmState implements jujuc.unitCharmStateContext.
    37  func (*RestrictedContext) GetCharmState() (map[string]string, error) {
    38  	return nil, ErrRestrictedContext
    39  }
    40  
    41  // GetCharmStateValue implements jujuc.unitCharmStateContext.
    42  func (*RestrictedContext) GetCharmStateValue(string) (string, error) {
    43  	return "", ErrRestrictedContext
    44  }
    45  
    46  // DeleteCharmStateValue implements jujuc.unitCharmStateContext.
    47  func (*RestrictedContext) DeleteCharmStateValue(string) error {
    48  	return ErrRestrictedContext
    49  }
    50  
    51  // SetCharmStateValue implements jujuc.unitCharmStateContext.
    52  func (*RestrictedContext) SetCharmStateValue(string, string) error {
    53  	return ErrRestrictedContext
    54  }
    55  
    56  // UnitStatus implements hooks.Context.
    57  func (*RestrictedContext) UnitStatus() (*StatusInfo, error) {
    58  	return nil, ErrRestrictedContext
    59  }
    60  
    61  // SetPodSpec implements hooks.Context.
    62  func (c *RestrictedContext) SetPodSpec(specYaml string) error {
    63  	return ErrRestrictedContext
    64  }
    65  
    66  // GetPodSpec implements hooks.Context.
    67  func (c *RestrictedContext) GetPodSpec() (string, error) {
    68  	return "", ErrRestrictedContext
    69  }
    70  
    71  // SetRawK8sSpec implements hooks.Context.
    72  func (c *RestrictedContext) SetRawK8sSpec(specYaml string) error {
    73  	return ErrRestrictedContext
    74  }
    75  
    76  // GetRawK8sSpec implements hooks.Context.
    77  func (c *RestrictedContext) GetRawK8sSpec() (string, error) {
    78  	return "", ErrRestrictedContext
    79  }
    80  
    81  // CloudSpec implements hooks.Context.
    82  func (c *RestrictedContext) CloudSpec() (*params.CloudSpec, error) {
    83  	return nil, ErrRestrictedContext
    84  }
    85  
    86  // SetUnitStatus implements hooks.Context.
    87  func (*RestrictedContext) SetUnitStatus(StatusInfo) error { return ErrRestrictedContext }
    88  
    89  // ApplicationStatus implements hooks.Context.
    90  func (*RestrictedContext) ApplicationStatus() (ApplicationStatusInfo, error) {
    91  	return ApplicationStatusInfo{}, ErrRestrictedContext
    92  }
    93  
    94  // SetApplicationStatus implements hooks.Context.
    95  func (*RestrictedContext) SetApplicationStatus(StatusInfo) error {
    96  	return ErrRestrictedContext
    97  }
    98  
    99  // AvailabilityZone implements hooks.Context.
   100  func (*RestrictedContext) AvailabilityZone() (string, error) { return "", ErrRestrictedContext }
   101  
   102  // RequestReboot implements hooks.Context.
   103  func (*RestrictedContext) RequestReboot(prio RebootPriority) error {
   104  	return ErrRestrictedContext
   105  }
   106  
   107  // PublicAddress implements hooks.Context.
   108  func (*RestrictedContext) PublicAddress() (string, error) { return "", ErrRestrictedContext }
   109  
   110  // PrivateAddress implements hooks.Context.
   111  func (*RestrictedContext) PrivateAddress() (string, error) { return "", ErrRestrictedContext }
   112  
   113  // OpenPortRange implements hooks.Context.
   114  func (*RestrictedContext) OpenPortRange(string, network.PortRange) error {
   115  	return ErrRestrictedContext
   116  }
   117  
   118  // ClosePortRange implements hooks.Context.
   119  func (*RestrictedContext) ClosePortRange(string, network.PortRange) error {
   120  	return ErrRestrictedContext
   121  }
   122  
   123  // OpenedPortRanges implements hooks.Context.
   124  func (*RestrictedContext) OpenedPortRanges() network.GroupedPortRanges { return nil }
   125  
   126  // NetworkInfo implements hooks.Context.
   127  func (*RestrictedContext) NetworkInfo(bindingNames []string, relationId int) (map[string]params.NetworkInfoResult, error) {
   128  	return map[string]params.NetworkInfoResult{}, ErrRestrictedContext
   129  }
   130  
   131  // IsLeader implements hooks.Context.
   132  func (*RestrictedContext) IsLeader() (bool, error) { return false, ErrRestrictedContext }
   133  
   134  // LeaderSettings implements hooks.Context.
   135  func (*RestrictedContext) LeaderSettings() (map[string]string, error) {
   136  	return nil, ErrRestrictedContext
   137  }
   138  
   139  // WriteLeaderSettings implements hooks.Context.
   140  func (*RestrictedContext) WriteLeaderSettings(map[string]string) error { return ErrRestrictedContext }
   141  
   142  // AddMetric implements hooks.Context.
   143  func (*RestrictedContext) AddMetric(string, string, time.Time) error { return ErrRestrictedContext }
   144  
   145  // AddMetricLabels implements hooks.Context.
   146  func (*RestrictedContext) AddMetricLabels(string, string, time.Time, map[string]string) error {
   147  	return ErrRestrictedContext
   148  }
   149  
   150  // StorageTags implements hooks.Context.
   151  func (*RestrictedContext) StorageTags() ([]names.StorageTag, error) { return nil, ErrRestrictedContext }
   152  
   153  // Storage implements hooks.Context.
   154  func (*RestrictedContext) Storage(names.StorageTag) (ContextStorageAttachment, error) {
   155  	return nil, ErrRestrictedContext
   156  }
   157  
   158  // HookStorage implements hooks.Context.
   159  func (*RestrictedContext) HookStorage() (ContextStorageAttachment, error) {
   160  	return nil, ErrRestrictedContext
   161  }
   162  
   163  // AddUnitStorage implements hooks.Context.
   164  func (*RestrictedContext) AddUnitStorage(map[string]params.StorageConstraints) error {
   165  	return ErrRestrictedContext
   166  }
   167  
   168  // DownloadResource implements hooks.Context.
   169  func (ctx *RestrictedContext) DownloadResource(name string) (filePath string, _ error) {
   170  	return "", ErrRestrictedContext
   171  }
   172  
   173  // GetPayload implements hooks.Context.
   174  func (ctx *RestrictedContext) GetPayload(class, id string) (*payloads.Payload, error) {
   175  	return nil, ErrRestrictedContext
   176  }
   177  
   178  // TrackPayload implements hooks.Context.
   179  func (ctx *RestrictedContext) TrackPayload(payload payloads.Payload) error {
   180  	return ErrRestrictedContext
   181  }
   182  
   183  // UntrackPayload implements hooks.Context.
   184  func (ctx *RestrictedContext) UntrackPayload(class, id string) error {
   185  	return ErrRestrictedContext
   186  }
   187  
   188  // SetPayloadStatus implements hooks.Context.
   189  func (ctx *RestrictedContext) SetPayloadStatus(class, id, status string) error {
   190  	return ErrRestrictedContext
   191  }
   192  
   193  // ListPayloads implements hooks.Context.
   194  func (ctx *RestrictedContext) ListPayloads() ([]string, error) {
   195  	return nil, ErrRestrictedContext
   196  }
   197  
   198  // FlushPayloads pushes the hook context data out to state.
   199  func (ctx *RestrictedContext) FlushPayloads() error {
   200  	return ErrRestrictedContext
   201  }
   202  
   203  // Relation implements hooks.Context.
   204  func (*RestrictedContext) Relation(id int) (ContextRelation, error) {
   205  	return nil, ErrRestrictedContext
   206  }
   207  
   208  // RelationIds implements hooks.Context.
   209  func (*RestrictedContext) RelationIds() ([]int, error) { return nil, ErrRestrictedContext }
   210  
   211  // HookRelation implements hooks.Context.
   212  func (*RestrictedContext) HookRelation() (ContextRelation, error) {
   213  	return nil, ErrRestrictedContext
   214  }
   215  
   216  // RemoteUnitName implements hooks.Context.
   217  func (*RestrictedContext) RemoteUnitName() (string, error) { return "", ErrRestrictedContext }
   218  
   219  // RemoteApplicationName implements hooks.Context.
   220  func (*RestrictedContext) RemoteApplicationName() (string, error) { return "", ErrRestrictedContext }
   221  
   222  // ActionParams implements hooks.Context.
   223  func (*RestrictedContext) ActionParams() (map[string]interface{}, error) {
   224  	return nil, ErrRestrictedContext
   225  }
   226  
   227  // UpdateActionResults implements hooks.Context.
   228  func (*RestrictedContext) UpdateActionResults(keys []string, value interface{}) error {
   229  	return ErrRestrictedContext
   230  }
   231  
   232  // LogActionMessage implements hooks.Context.
   233  func (*RestrictedContext) LogActionMessage(string) error { return ErrRestrictedContext }
   234  
   235  // SetActionMessage implements hooks.Context.
   236  func (*RestrictedContext) SetActionMessage(string) error { return ErrRestrictedContext }
   237  
   238  // SetActionFailed implements hooks.Context.
   239  func (*RestrictedContext) SetActionFailed() error { return ErrRestrictedContext }
   240  
   241  // UnitWorkloadVersion implements hooks.Context.
   242  func (*RestrictedContext) UnitWorkloadVersion() (string, error) {
   243  	return "", ErrRestrictedContext
   244  }
   245  
   246  // SetUnitWorkloadVersion implements hooks.Context.
   247  func (*RestrictedContext) SetUnitWorkloadVersion(string) error {
   248  	return ErrRestrictedContext
   249  }
   250  
   251  // WorkloadName implements hooks.Context.
   252  func (*RestrictedContext) WorkloadName() (string, error) {
   253  	return "", ErrRestrictedContext
   254  }
   255  
   256  // GetSecret implements runner.Context.
   257  func (ctx *RestrictedContext) GetSecret(*secrets.URI, string, bool, bool) (secrets.SecretValue, error) {
   258  	return nil, ErrRestrictedContext
   259  }
   260  
   261  // CreateSecret implements runner.Context.
   262  func (ctx *RestrictedContext) CreateSecret(args *SecretCreateArgs) (*secrets.URI, error) {
   263  	return nil, ErrRestrictedContext
   264  }
   265  
   266  // UpdateSecret implements runner.Context.
   267  func (ctx *RestrictedContext) UpdateSecret(*secrets.URI, *SecretUpdateArgs) error {
   268  	return ErrRestrictedContext
   269  }
   270  
   271  func (ctx *RestrictedContext) RemoveSecret(*secrets.URI, *int) error {
   272  	return ErrRestrictedContext
   273  }
   274  
   275  func (ctx *RestrictedContext) SecretMetadata() (map[string]SecretMetadata, error) {
   276  	return nil, ErrRestrictedContext
   277  }
   278  
   279  // GrantSecret implements runner.Context.
   280  func (c *RestrictedContext) GrantSecret(*secrets.URI, *SecretGrantRevokeArgs) error {
   281  	return ErrRestrictedContext
   282  }
   283  
   284  // RevokeSecret implements runner.Context.
   285  func (c *RestrictedContext) RevokeSecret(*secrets.URI, *SecretGrantRevokeArgs) error {
   286  	return ErrRestrictedContext
   287  }