id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
153,700
juju/juju
state/refcounts_ns.go
RemoveOp
func (ns nsRefcounts_) RemoveOp(coll mongo.Collection, key string, value int) (txn.Op, error) { refcount, err := ns.read(coll, key) if err != nil { return txn.Op{}, errors.Trace(err) } if refcount != value { logger.Tracef("reference of %s(%q) had %d refs, expected %d", coll.Name(), key, refcount, value) return txn.Op{}, errRefcountChanged } return ns.JustRemoveOp(coll.Name(), key, value), nil }
go
func (ns nsRefcounts_) RemoveOp(coll mongo.Collection, key string, value int) (txn.Op, error) { refcount, err := ns.read(coll, key) if err != nil { return txn.Op{}, errors.Trace(err) } if refcount != value { logger.Tracef("reference of %s(%q) had %d refs, expected %d", coll.Name(), key, refcount, value) return txn.Op{}, errRefcountChanged } return ns.JustRemoveOp(coll.Name(), key, value), nil }
[ "func", "(", "ns", "nsRefcounts_", ")", "RemoveOp", "(", "coll", "mongo", ".", "Collection", ",", "key", "string", ",", "value", "int", ")", "(", "txn", ".", "Op", ",", "error", ")", "{", "refcount", ",", "err", ":=", "ns", ".", "read", "(", "coll", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "txn", ".", "Op", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "refcount", "!=", "value", "{", "logger", ".", "Tracef", "(", "\"", "\"", ",", "coll", ".", "Name", "(", ")", ",", "key", ",", "refcount", ",", "value", ")", "\n", "return", "txn", ".", "Op", "{", "}", ",", "errRefcountChanged", "\n", "}", "\n", "return", "ns", ".", "JustRemoveOp", "(", "coll", ".", "Name", "(", ")", ",", "key", ",", "value", ")", ",", "nil", "\n", "}" ]
// RemoveOp returns a txn.Op that removes a refcount doc so long as its // refcount is the supplied value, or an error.
[ "RemoveOp", "returns", "a", "txn", ".", "Op", "that", "removes", "a", "refcount", "doc", "so", "long", "as", "its", "refcount", "is", "the", "supplied", "value", "or", "an", "error", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/refcounts_ns.go#L126-L136
153,701
juju/juju
state/refcounts_ns.go
CurrentOp
func (ns nsRefcounts_) CurrentOp(coll mongo.Collection, key string) (txn.Op, int, error) { refcount, err := ns.read(coll, key) if errors.IsNotFound(err) { return txn.Op{ C: coll.Name(), Id: key, Assert: txn.DocMissing, }, 0, nil } if err != nil { return txn.Op{}, -1, errors.Trace(err) } return txn.Op{ C: coll.Name(), Id: key, Assert: bson.D{{"refcount", refcount}}, }, refcount, nil }
go
func (ns nsRefcounts_) CurrentOp(coll mongo.Collection, key string) (txn.Op, int, error) { refcount, err := ns.read(coll, key) if errors.IsNotFound(err) { return txn.Op{ C: coll.Name(), Id: key, Assert: txn.DocMissing, }, 0, nil } if err != nil { return txn.Op{}, -1, errors.Trace(err) } return txn.Op{ C: coll.Name(), Id: key, Assert: bson.D{{"refcount", refcount}}, }, refcount, nil }
[ "func", "(", "ns", "nsRefcounts_", ")", "CurrentOp", "(", "coll", "mongo", ".", "Collection", ",", "key", "string", ")", "(", "txn", ".", "Op", ",", "int", ",", "error", ")", "{", "refcount", ",", "err", ":=", "ns", ".", "read", "(", "coll", ",", "key", ")", "\n", "if", "errors", ".", "IsNotFound", "(", "err", ")", "{", "return", "txn", ".", "Op", "{", "C", ":", "coll", ".", "Name", "(", ")", ",", "Id", ":", "key", ",", "Assert", ":", "txn", ".", "DocMissing", ",", "}", ",", "0", ",", "nil", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "txn", ".", "Op", "{", "}", ",", "-", "1", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "txn", ".", "Op", "{", "C", ":", "coll", ".", "Name", "(", ")", ",", "Id", ":", "key", ",", "Assert", ":", "bson", ".", "D", "{", "{", "\"", "\"", ",", "refcount", "}", "}", ",", "}", ",", "refcount", ",", "nil", "\n", "}" ]
// CurrentOp returns the current reference count value, and a txn.Op that // asserts that the refcount has that value, or an error. If the refcount // doc does not exist, then the op will assert that the document does not // exist instead, and no error is returned.
[ "CurrentOp", "returns", "the", "current", "reference", "count", "value", "and", "a", "txn", ".", "Op", "that", "asserts", "that", "the", "refcount", "has", "that", "value", "or", "an", "error", ".", "If", "the", "refcount", "doc", "does", "not", "exist", "then", "the", "op", "will", "assert", "that", "the", "document", "does", "not", "exist", "instead", "and", "no", "error", "is", "returned", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/refcounts_ns.go#L142-L159
153,702
juju/juju
state/refcounts_ns.go
JustRemoveOp
func (ns nsRefcounts_) JustRemoveOp(collName, key string, count int) txn.Op { op := txn.Op{ C: collName, Id: key, Remove: true, } if count >= 0 { op.Assert = bson.D{{"refcount", count}} } return op }
go
func (ns nsRefcounts_) JustRemoveOp(collName, key string, count int) txn.Op { op := txn.Op{ C: collName, Id: key, Remove: true, } if count >= 0 { op.Assert = bson.D{{"refcount", count}} } return op }
[ "func", "(", "ns", "nsRefcounts_", ")", "JustRemoveOp", "(", "collName", ",", "key", "string", ",", "count", "int", ")", "txn", ".", "Op", "{", "op", ":=", "txn", ".", "Op", "{", "C", ":", "collName", ",", "Id", ":", "key", ",", "Remove", ":", "true", ",", "}", "\n", "if", "count", ">=", "0", "{", "op", ".", "Assert", "=", "bson", ".", "D", "{", "{", "\"", "\"", ",", "count", "}", "}", "\n", "}", "\n", "return", "op", "\n", "}" ]
// JustRemoveOp returns a txn.Op that deletes a refcount doc so long as // the refcount matches count. You should avoid using this method in // most cases.
[ "JustRemoveOp", "returns", "a", "txn", ".", "Op", "that", "deletes", "a", "refcount", "doc", "so", "long", "as", "the", "refcount", "matches", "count", ".", "You", "should", "avoid", "using", "this", "method", "in", "most", "cases", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/refcounts_ns.go#L188-L198
153,703
juju/juju
state/refcounts_ns.go
exists
func (nsRefcounts_) exists(coll mongo.Collection, key string) (bool, error) { count, err := coll.FindId(key).Count() if err != nil { return false, errors.Trace(err) } return count != 0, nil }
go
func (nsRefcounts_) exists(coll mongo.Collection, key string) (bool, error) { count, err := coll.FindId(key).Count() if err != nil { return false, errors.Trace(err) } return count != 0, nil }
[ "func", "(", "nsRefcounts_", ")", "exists", "(", "coll", "mongo", ".", "Collection", ",", "key", "string", ")", "(", "bool", ",", "error", ")", "{", "count", ",", "err", ":=", "coll", ".", "FindId", "(", "key", ")", ".", "Count", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "count", "!=", "0", ",", "nil", "\n", "}" ]
// exists returns whether the identified refcount doc exists.
[ "exists", "returns", "whether", "the", "identified", "refcount", "doc", "exists", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/refcounts_ns.go#L215-L221
153,704
juju/juju
state/refcounts_ns.go
read
func (nsRefcounts_) read(coll mongo.Collection, key string) (int, error) { var doc refcountDoc if err := coll.FindId(key).One(&doc); err == mgo.ErrNotFound { return 0, errors.NotFoundf("refcount %q", key) } else if err != nil { return 0, errors.Trace(err) } return doc.RefCount, nil }
go
func (nsRefcounts_) read(coll mongo.Collection, key string) (int, error) { var doc refcountDoc if err := coll.FindId(key).One(&doc); err == mgo.ErrNotFound { return 0, errors.NotFoundf("refcount %q", key) } else if err != nil { return 0, errors.Trace(err) } return doc.RefCount, nil }
[ "func", "(", "nsRefcounts_", ")", "read", "(", "coll", "mongo", ".", "Collection", ",", "key", "string", ")", "(", "int", ",", "error", ")", "{", "var", "doc", "refcountDoc", "\n", "if", "err", ":=", "coll", ".", "FindId", "(", "key", ")", ".", "One", "(", "&", "doc", ")", ";", "err", "==", "mgo", ".", "ErrNotFound", "{", "return", "0", ",", "errors", ".", "NotFoundf", "(", "\"", "\"", ",", "key", ")", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "0", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "doc", ".", "RefCount", ",", "nil", "\n", "}" ]
// read returns the value stored in the identified refcount doc.
[ "read", "returns", "the", "value", "stored", "in", "the", "identified", "refcount", "doc", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/refcounts_ns.go#L224-L232
153,705
juju/juju
provider/lxd/config.go
newConfig
func newConfig(cfg *config.Config) *environConfig { return &environConfig{ Config: cfg, attrs: cfg.UnknownAttrs(), } }
go
func newConfig(cfg *config.Config) *environConfig { return &environConfig{ Config: cfg, attrs: cfg.UnknownAttrs(), } }
[ "func", "newConfig", "(", "cfg", "*", "config", ".", "Config", ")", "*", "environConfig", "{", "return", "&", "environConfig", "{", "Config", ":", "cfg", ",", "attrs", ":", "cfg", ".", "UnknownAttrs", "(", ")", ",", "}", "\n", "}" ]
// newConfig builds a new environConfig from the provided Config and // returns it.
[ "newConfig", "builds", "a", "new", "environConfig", "from", "the", "provided", "Config", "and", "returns", "it", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/config.go#L32-L37
153,706
juju/juju
provider/lxd/config.go
newValidConfig
func newValidConfig(cfg *config.Config) (*environConfig, error) { // Ensure that the provided config is valid. if err := config.Validate(cfg, nil); err != nil { return nil, errors.Trace(err) } // Build the config. ecfg := newConfig(cfg) // Do final (more complex, provider-specific) validation. if err := ecfg.validate(); err != nil { return nil, errors.Trace(err) } return ecfg, nil }
go
func newValidConfig(cfg *config.Config) (*environConfig, error) { // Ensure that the provided config is valid. if err := config.Validate(cfg, nil); err != nil { return nil, errors.Trace(err) } // Build the config. ecfg := newConfig(cfg) // Do final (more complex, provider-specific) validation. if err := ecfg.validate(); err != nil { return nil, errors.Trace(err) } return ecfg, nil }
[ "func", "newValidConfig", "(", "cfg", "*", "config", ".", "Config", ")", "(", "*", "environConfig", ",", "error", ")", "{", "// Ensure that the provided config is valid.", "if", "err", ":=", "config", ".", "Validate", "(", "cfg", ",", "nil", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// Build the config.", "ecfg", ":=", "newConfig", "(", "cfg", ")", "\n\n", "// Do final (more complex, provider-specific) validation.", "if", "err", ":=", "ecfg", ".", "validate", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "return", "ecfg", ",", "nil", "\n", "}" ]
// newValidConfig builds a new environConfig from the provided Config // and returns it. This includes applying the provided defaults // values, if any. The resulting config values are validated.
[ "newValidConfig", "builds", "a", "new", "environConfig", "from", "the", "provided", "Config", "and", "returns", "it", ".", "This", "includes", "applying", "the", "provided", "defaults", "values", "if", "any", ".", "The", "resulting", "config", "values", "are", "validated", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/config.go#L42-L57
153,707
juju/juju
provider/lxd/config.go
validate
func (c *environConfig) validate() error { _, err := c.ValidateUnknownAttrs(configFields, configDefaults) if err != nil { return errors.Trace(err) } // There are currently no known extra fields for LXD return nil }
go
func (c *environConfig) validate() error { _, err := c.ValidateUnknownAttrs(configFields, configDefaults) if err != nil { return errors.Trace(err) } // There are currently no known extra fields for LXD return nil }
[ "func", "(", "c", "*", "environConfig", ")", "validate", "(", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "ValidateUnknownAttrs", "(", "configFields", ",", "configDefaults", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "// There are currently no known extra fields for LXD", "return", "nil", "\n", "}" ]
// validate validates LXD-specific configuration.
[ "validate", "validates", "LXD", "-", "specific", "configuration", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/config.go#L60-L67
153,708
juju/juju
container/broker/host_preparer.go
NewHostPreparer
func NewHostPreparer(params HostPreparerParams) *HostPreparer { return &HostPreparer{ api: params.API, observeNetworkFunc: params.ObserveNetworkFunc, acquireLockFunc: params.AcquireLockFunc, createBridger: params.CreateBridger, abortChan: params.AbortChan, machineTag: params.MachineTag, logger: params.Logger, } }
go
func NewHostPreparer(params HostPreparerParams) *HostPreparer { return &HostPreparer{ api: params.API, observeNetworkFunc: params.ObserveNetworkFunc, acquireLockFunc: params.AcquireLockFunc, createBridger: params.CreateBridger, abortChan: params.AbortChan, machineTag: params.MachineTag, logger: params.Logger, } }
[ "func", "NewHostPreparer", "(", "params", "HostPreparerParams", ")", "*", "HostPreparer", "{", "return", "&", "HostPreparer", "{", "api", ":", "params", ".", "API", ",", "observeNetworkFunc", ":", "params", ".", "ObserveNetworkFunc", ",", "acquireLockFunc", ":", "params", ".", "AcquireLockFunc", ",", "createBridger", ":", "params", ".", "CreateBridger", ",", "abortChan", ":", "params", ".", "AbortChan", ",", "machineTag", ":", "params", ".", "MachineTag", ",", "logger", ":", "params", ".", "Logger", ",", "}", "\n", "}" ]
// NewHostPreparer creates a HostPreparer using the supplied parameters
[ "NewHostPreparer", "creates", "a", "HostPreparer", "using", "the", "supplied", "parameters" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/broker/host_preparer.go#L54-L64
153,709
juju/juju
container/broker/host_preparer.go
Prepare
func (hp *HostPreparer) Prepare(containerTag names.MachineTag) error { devicesToBridge, reconfigureDelay, err := hp.api.HostChangesForContainer(containerTag) if err != nil { return errors.Annotate(err, "unable to setup network") } if len(devicesToBridge) == 0 { hp.logger.Debugf("container %q requires no additional bridges", containerTag) return nil } bridger, err := hp.createBridger() if err != nil { return errors.Trace(err) } hp.logger.Debugf("bridging %+v devices on host %q for container %q with delay=%v", devicesToBridge, hp.machineTag.String(), containerTag.String(), reconfigureDelay) releaser, err := hp.acquireLockFunc("bridging devices", hp.abortChan) if err != nil { return errors.Annotatef(err, "failed to acquire machine lock for bridging") } defer releaser() // TODO(jam): 2017-02-15 bridger.Bridge should probably also take AbortChan // if it is going to have reconfigureDelay err = bridger.Bridge(devicesToBridge, reconfigureDelay) if err != nil { return errors.Annotate(err, "failed to bridge devices") } // We just changed the hosts' network setup so discover new // interfaces/devices and propagate to state. observedConfig, err := hp.observeNetworkFunc() if err != nil { return errors.Annotate(err, "cannot discover observed network config") } if len(observedConfig) > 0 { hp.logger.Debugf("updating observed network config for %q to %#v", hp.machineTag.String(), observedConfig) err := hp.api.SetHostMachineNetworkConfig(hp.machineTag, observedConfig) if err != nil { return errors.Trace(err) } } return nil }
go
func (hp *HostPreparer) Prepare(containerTag names.MachineTag) error { devicesToBridge, reconfigureDelay, err := hp.api.HostChangesForContainer(containerTag) if err != nil { return errors.Annotate(err, "unable to setup network") } if len(devicesToBridge) == 0 { hp.logger.Debugf("container %q requires no additional bridges", containerTag) return nil } bridger, err := hp.createBridger() if err != nil { return errors.Trace(err) } hp.logger.Debugf("bridging %+v devices on host %q for container %q with delay=%v", devicesToBridge, hp.machineTag.String(), containerTag.String(), reconfigureDelay) releaser, err := hp.acquireLockFunc("bridging devices", hp.abortChan) if err != nil { return errors.Annotatef(err, "failed to acquire machine lock for bridging") } defer releaser() // TODO(jam): 2017-02-15 bridger.Bridge should probably also take AbortChan // if it is going to have reconfigureDelay err = bridger.Bridge(devicesToBridge, reconfigureDelay) if err != nil { return errors.Annotate(err, "failed to bridge devices") } // We just changed the hosts' network setup so discover new // interfaces/devices and propagate to state. observedConfig, err := hp.observeNetworkFunc() if err != nil { return errors.Annotate(err, "cannot discover observed network config") } if len(observedConfig) > 0 { hp.logger.Debugf("updating observed network config for %q to %#v", hp.machineTag.String(), observedConfig) err := hp.api.SetHostMachineNetworkConfig(hp.machineTag, observedConfig) if err != nil { return errors.Trace(err) } } return nil }
[ "func", "(", "hp", "*", "HostPreparer", ")", "Prepare", "(", "containerTag", "names", ".", "MachineTag", ")", "error", "{", "devicesToBridge", ",", "reconfigureDelay", ",", "err", ":=", "hp", ".", "api", ".", "HostChangesForContainer", "(", "containerTag", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "devicesToBridge", ")", "==", "0", "{", "hp", ".", "logger", ".", "Debugf", "(", "\"", "\"", ",", "containerTag", ")", "\n", "return", "nil", "\n", "}", "\n\n", "bridger", ",", "err", ":=", "hp", ".", "createBridger", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "hp", ".", "logger", ".", "Debugf", "(", "\"", "\"", ",", "devicesToBridge", ",", "hp", ".", "machineTag", ".", "String", "(", ")", ",", "containerTag", ".", "String", "(", ")", ",", "reconfigureDelay", ")", "\n", "releaser", ",", "err", ":=", "hp", ".", "acquireLockFunc", "(", "\"", "\"", ",", "hp", ".", "abortChan", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "defer", "releaser", "(", ")", "\n", "// TODO(jam): 2017-02-15 bridger.Bridge should probably also take AbortChan", "// if it is going to have reconfigureDelay", "err", "=", "bridger", ".", "Bridge", "(", "devicesToBridge", ",", "reconfigureDelay", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// We just changed the hosts' network setup so discover new", "// interfaces/devices and propagate to state.", "observedConfig", ",", "err", ":=", "hp", ".", "observeNetworkFunc", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "observedConfig", ")", ">", "0", "{", "hp", ".", "logger", ".", "Debugf", "(", "\"", "\"", ",", "hp", ".", "machineTag", ".", "String", "(", ")", ",", "observedConfig", ")", "\n", "err", ":=", "hp", ".", "api", ".", "SetHostMachineNetworkConfig", "(", "hp", ".", "machineTag", ",", "observedConfig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Prepare applies changes to the host machine that are necessary to create // the requested container.
[ "Prepare", "applies", "changes", "to", "the", "host", "machine", "that", "are", "necessary", "to", "create", "the", "requested", "container", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/broker/host_preparer.go#L68-L114
153,710
juju/juju
state/backups/create.go
create
func create(args *createArgs) (_ *createResult, err error) { // Prepare the backup builder. builder, err := newBuilder(args.backupDir, args.filesToBackUp, args.db) if err != nil { return nil, errors.Trace(err) } defer func() { if cerr := builder.cleanUp(args.noDownload); cerr != nil { cerr.Log(logger) if err == nil { err = cerr } } }() // Inject the metadata file. if args.metadataReader == nil { return nil, errors.New("missing metadataReader") } if err := builder.injectMetadataFile(args.metadataReader); err != nil { return nil, errors.Trace(err) } // Build the backup. if err := builder.buildAll(); err != nil { return nil, errors.Trace(err) } // Get the result. result, err := builder.result() if err != nil { return nil, errors.Trace(err) } // Return the result. Note that the entire build workspace will be // deleted at the end of this function. This includes the backup // archive file we built. However, the handle to that file in the // result will still be open and readable. // If we ever support state machines on Windows, this will need to // change (you can't delete open files on Windows). return result, nil }
go
func create(args *createArgs) (_ *createResult, err error) { // Prepare the backup builder. builder, err := newBuilder(args.backupDir, args.filesToBackUp, args.db) if err != nil { return nil, errors.Trace(err) } defer func() { if cerr := builder.cleanUp(args.noDownload); cerr != nil { cerr.Log(logger) if err == nil { err = cerr } } }() // Inject the metadata file. if args.metadataReader == nil { return nil, errors.New("missing metadataReader") } if err := builder.injectMetadataFile(args.metadataReader); err != nil { return nil, errors.Trace(err) } // Build the backup. if err := builder.buildAll(); err != nil { return nil, errors.Trace(err) } // Get the result. result, err := builder.result() if err != nil { return nil, errors.Trace(err) } // Return the result. Note that the entire build workspace will be // deleted at the end of this function. This includes the backup // archive file we built. However, the handle to that file in the // result will still be open and readable. // If we ever support state machines on Windows, this will need to // change (you can't delete open files on Windows). return result, nil }
[ "func", "create", "(", "args", "*", "createArgs", ")", "(", "_", "*", "createResult", ",", "err", "error", ")", "{", "// Prepare the backup builder.", "builder", ",", "err", ":=", "newBuilder", "(", "args", ".", "backupDir", ",", "args", ".", "filesToBackUp", ",", "args", ".", "db", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "defer", "func", "(", ")", "{", "if", "cerr", ":=", "builder", ".", "cleanUp", "(", "args", ".", "noDownload", ")", ";", "cerr", "!=", "nil", "{", "cerr", ".", "Log", "(", "logger", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "cerr", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "// Inject the metadata file.", "if", "args", ".", "metadataReader", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "err", ":=", "builder", ".", "injectMetadataFile", "(", "args", ".", "metadataReader", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// Build the backup.", "if", "err", ":=", "builder", ".", "buildAll", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// Get the result.", "result", ",", "err", ":=", "builder", ".", "result", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "// Return the result. Note that the entire build workspace will be", "// deleted at the end of this function. This includes the backup", "// archive file we built. However, the handle to that file in the", "// result will still be open and readable.", "// If we ever support state machines on Windows, this will need to", "// change (you can't delete open files on Windows).", "return", "result", ",", "nil", "\n", "}" ]
// create builds a new backup archive file and returns it. It also // updates the metadata with the file info.
[ "create", "builds", "a", "new", "backup", "archive", "file", "and", "returns", "it", ".", "It", "also", "updates", "the", "metadata", "with", "the", "file", "info", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/backups/create.go#L47-L87
153,711
juju/juju
controller/config.go
ControllerOnlyAttribute
func ControllerOnlyAttribute(attr string) bool { for _, a := range ControllerOnlyConfigAttributes { if attr == a { return true } } return false }
go
func ControllerOnlyAttribute(attr string) bool { for _, a := range ControllerOnlyConfigAttributes { if attr == a { return true } } return false }
[ "func", "ControllerOnlyAttribute", "(", "attr", "string", ")", "bool", "{", "for", "_", ",", "a", ":=", "range", "ControllerOnlyConfigAttributes", "{", "if", "attr", "==", "a", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// ControllerOnlyAttribute returns true if the specified attribute name // is only relevant for a controller.
[ "ControllerOnlyAttribute", "returns", "true", "if", "the", "specified", "attribute", "name", "is", "only", "relevant", "for", "a", "controller", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L320-L327
153,712
juju/juju
controller/config.go
mustInt
func (c Config) mustInt(name string) int { // Values obtained over the api are encoded as float64. if value, ok := c[name].(float64); ok { return int(value) } value, _ := c[name].(int) if value == 0 { panic(errors.Errorf("empty value for %q found in configuration", name)) } return value }
go
func (c Config) mustInt(name string) int { // Values obtained over the api are encoded as float64. if value, ok := c[name].(float64); ok { return int(value) } value, _ := c[name].(int) if value == 0 { panic(errors.Errorf("empty value for %q found in configuration", name)) } return value }
[ "func", "(", "c", "Config", ")", "mustInt", "(", "name", "string", ")", "int", "{", "// Values obtained over the api are encoded as float64.", "if", "value", ",", "ok", ":=", "c", "[", "name", "]", ".", "(", "float64", ")", ";", "ok", "{", "return", "int", "(", "value", ")", "\n", "}", "\n", "value", ",", "_", ":=", "c", "[", "name", "]", ".", "(", "int", ")", "\n", "if", "value", "==", "0", "{", "panic", "(", "errors", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", ")", "\n", "}", "\n", "return", "value", "\n", "}" ]
// mustInt returns the named attribute as an integer, panicking if // it is not found or is zero. Zero values should have been // diagnosed at Validate time.
[ "mustInt", "returns", "the", "named", "attribute", "as", "an", "integer", "panicking", "if", "it", "is", "not", "found", "or", "is", "zero", ".", "Zero", "values", "should", "have", "been", "diagnosed", "at", "Validate", "time", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L358-L368
153,713
juju/juju
controller/config.go
APIPortOpenDelay
func (c Config) APIPortOpenDelay() time.Duration { v := c.asString(APIPortOpenDelay) // We know that v must be a parseable time.Duration for the config // to be valid. d, _ := time.ParseDuration(v) return d }
go
func (c Config) APIPortOpenDelay() time.Duration { v := c.asString(APIPortOpenDelay) // We know that v must be a parseable time.Duration for the config // to be valid. d, _ := time.ParseDuration(v) return d }
[ "func", "(", "c", "Config", ")", "APIPortOpenDelay", "(", ")", "time", ".", "Duration", "{", "v", ":=", "c", ".", "asString", "(", "APIPortOpenDelay", ")", "\n", "// We know that v must be a parseable time.Duration for the config", "// to be valid.", "d", ",", "_", ":=", "time", ".", "ParseDuration", "(", "v", ")", "\n", "return", "d", "\n", "}" ]
// APIPortOpenDelay returns the duration to wait before opening // the APIPort once the controller has started up. Only used when // the ControllerAPIPort is non-zero.
[ "APIPortOpenDelay", "returns", "the", "duration", "to", "wait", "before", "opening", "the", "APIPort", "once", "the", "controller", "has", "started", "up", ".", "Only", "used", "when", "the", "ControllerAPIPort", "is", "non", "-", "zero", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L408-L414
153,714
juju/juju
controller/config.go
ControllerAPIPort
func (c Config) ControllerAPIPort() int { if value, ok := c[ControllerAPIPort].(float64); ok { return int(value) } // If the value isn't an int, this conversion will fail and value // will be 0, which is what we want here. value, _ := c[ControllerAPIPort].(int) return value }
go
func (c Config) ControllerAPIPort() int { if value, ok := c[ControllerAPIPort].(float64); ok { return int(value) } // If the value isn't an int, this conversion will fail and value // will be 0, which is what we want here. value, _ := c[ControllerAPIPort].(int) return value }
[ "func", "(", "c", "Config", ")", "ControllerAPIPort", "(", ")", "int", "{", "if", "value", ",", "ok", ":=", "c", "[", "ControllerAPIPort", "]", ".", "(", "float64", ")", ";", "ok", "{", "return", "int", "(", "value", ")", "\n", "}", "\n", "// If the value isn't an int, this conversion will fail and value", "// will be 0, which is what we want here.", "value", ",", "_", ":=", "c", "[", "ControllerAPIPort", "]", ".", "(", "int", ")", "\n", "return", "value", "\n", "}" ]
// ControllerAPIPort returns the optional API port to be used for // the controllers to talk to each other. A zero value means that // it is not set.
[ "ControllerAPIPort", "returns", "the", "optional", "API", "port", "to", "be", "used", "for", "the", "controllers", "to", "talk", "to", "each", "other", ".", "A", "zero", "value", "means", "that", "it", "is", "not", "set", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L419-L427
153,715
juju/juju
controller/config.go
AuditingEnabled
func (c Config) AuditingEnabled() bool { if v, ok := c[AuditingEnabled]; ok { return v.(bool) } return DefaultAuditingEnabled }
go
func (c Config) AuditingEnabled() bool { if v, ok := c[AuditingEnabled]; ok { return v.(bool) } return DefaultAuditingEnabled }
[ "func", "(", "c", "Config", ")", "AuditingEnabled", "(", ")", "bool", "{", "if", "v", ",", "ok", ":=", "c", "[", "AuditingEnabled", "]", ";", "ok", "{", "return", "v", ".", "(", "bool", ")", "\n", "}", "\n", "return", "DefaultAuditingEnabled", "\n", "}" ]
// AuditingEnabled returns whether or not auditing has been enabled // for the environment. The default is false.
[ "AuditingEnabled", "returns", "whether", "or", "not", "auditing", "has", "been", "enabled", "for", "the", "environment", ".", "The", "default", "is", "false", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L431-L436
153,716
juju/juju
controller/config.go
AuditLogCaptureArgs
func (c Config) AuditLogCaptureArgs() bool { if v, ok := c[AuditLogCaptureArgs]; ok { return v.(bool) } return DefaultAuditLogCaptureArgs }
go
func (c Config) AuditLogCaptureArgs() bool { if v, ok := c[AuditLogCaptureArgs]; ok { return v.(bool) } return DefaultAuditLogCaptureArgs }
[ "func", "(", "c", "Config", ")", "AuditLogCaptureArgs", "(", ")", "bool", "{", "if", "v", ",", "ok", ":=", "c", "[", "AuditLogCaptureArgs", "]", ";", "ok", "{", "return", "v", ".", "(", "bool", ")", "\n", "}", "\n", "return", "DefaultAuditLogCaptureArgs", "\n", "}" ]
// AuditLogCaptureArgs returns whether audit logging should capture // the arguments to API methods. The default is false.
[ "AuditLogCaptureArgs", "returns", "whether", "audit", "logging", "should", "capture", "the", "arguments", "to", "API", "methods", ".", "The", "default", "is", "false", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L440-L445
153,717
juju/juju
controller/config.go
AuditLogMaxSizeMB
func (c Config) AuditLogMaxSizeMB() int { // Value has already been validated. value, _ := utils.ParseSize(c.asString(AuditLogMaxSize)) return int(value) }
go
func (c Config) AuditLogMaxSizeMB() int { // Value has already been validated. value, _ := utils.ParseSize(c.asString(AuditLogMaxSize)) return int(value) }
[ "func", "(", "c", "Config", ")", "AuditLogMaxSizeMB", "(", ")", "int", "{", "// Value has already been validated.", "value", ",", "_", ":=", "utils", ".", "ParseSize", "(", "c", ".", "asString", "(", "AuditLogMaxSize", ")", ")", "\n", "return", "int", "(", "value", ")", "\n", "}" ]
// AuditLogMaxSizeMB returns the maximum size for an audit log file in // MB.
[ "AuditLogMaxSizeMB", "returns", "the", "maximum", "size", "for", "an", "audit", "log", "file", "in", "MB", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L449-L453
153,718
juju/juju
controller/config.go
AuditLogExcludeMethods
func (c Config) AuditLogExcludeMethods() set.Strings { if value, ok := c[AuditLogExcludeMethods]; ok { value := value.([]interface{}) items := set.NewStrings() for _, item := range value { items.Add(item.(string)) } return items } return set.NewStrings(DefaultAuditLogExcludeMethods...) }
go
func (c Config) AuditLogExcludeMethods() set.Strings { if value, ok := c[AuditLogExcludeMethods]; ok { value := value.([]interface{}) items := set.NewStrings() for _, item := range value { items.Add(item.(string)) } return items } return set.NewStrings(DefaultAuditLogExcludeMethods...) }
[ "func", "(", "c", "Config", ")", "AuditLogExcludeMethods", "(", ")", "set", ".", "Strings", "{", "if", "value", ",", "ok", ":=", "c", "[", "AuditLogExcludeMethods", "]", ";", "ok", "{", "value", ":=", "value", ".", "(", "[", "]", "interface", "{", "}", ")", "\n", "items", ":=", "set", ".", "NewStrings", "(", ")", "\n", "for", "_", ",", "item", ":=", "range", "value", "{", "items", ".", "Add", "(", "item", ".", "(", "string", ")", ")", "\n", "}", "\n", "return", "items", "\n", "}", "\n", "return", "set", ".", "NewStrings", "(", "DefaultAuditLogExcludeMethods", "...", ")", "\n", "}" ]
// AuditLogExcludeMethods returns the set of method names that are // considered uninteresting for audit logging. Conversations // containing only these will be excluded from the audit log.
[ "AuditLogExcludeMethods", "returns", "the", "set", "of", "method", "names", "that", "are", "considered", "uninteresting", "for", "audit", "logging", ".", "Conversations", "containing", "only", "these", "will", "be", "excluded", "from", "the", "audit", "log", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L464-L474
153,719
juju/juju
controller/config.go
Features
func (c Config) Features() set.Strings { features := set.NewStrings() if value, ok := c[Features]; ok { value := value.([]interface{}) for _, item := range value { features.Add(item.(string)) } } return features }
go
func (c Config) Features() set.Strings { features := set.NewStrings() if value, ok := c[Features]; ok { value := value.([]interface{}) for _, item := range value { features.Add(item.(string)) } } return features }
[ "func", "(", "c", "Config", ")", "Features", "(", ")", "set", ".", "Strings", "{", "features", ":=", "set", ".", "NewStrings", "(", ")", "\n", "if", "value", ",", "ok", ":=", "c", "[", "Features", "]", ";", "ok", "{", "value", ":=", "value", ".", "(", "[", "]", "interface", "{", "}", ")", "\n", "for", "_", ",", "item", ":=", "range", "value", "{", "features", ".", "Add", "(", "item", ".", "(", "string", ")", ")", "\n", "}", "\n", "}", "\n", "return", "features", "\n", "}" ]
// Features returns the controller config set features flags.
[ "Features", "returns", "the", "controller", "config", "set", "features", "flags", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L477-L486
153,720
juju/juju
controller/config.go
CharmStoreURL
func (c Config) CharmStoreURL() string { url := c.asString(CharmStoreURL) if url == "" { return csclient.ServerURL } return url }
go
func (c Config) CharmStoreURL() string { url := c.asString(CharmStoreURL) if url == "" { return csclient.ServerURL } return url }
[ "func", "(", "c", "Config", ")", "CharmStoreURL", "(", ")", "string", "{", "url", ":=", "c", ".", "asString", "(", "CharmStoreURL", ")", "\n", "if", "url", "==", "\"", "\"", "{", "return", "csclient", ".", "ServerURL", "\n", "}", "\n", "return", "url", "\n", "}" ]
// CharmStoreURL returns the URL to use for charmstore api calls.
[ "CharmStoreURL", "returns", "the", "URL", "to", "use", "for", "charmstore", "api", "calls", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L489-L495
153,721
juju/juju
controller/config.go
IdentityPublicKey
func (c Config) IdentityPublicKey() *bakery.PublicKey { key := c.asString(IdentityPublicKey) if key == "" { return nil } var pubKey bakery.PublicKey err := pubKey.UnmarshalText([]byte(key)) if err != nil { // We check if the key string can be unmarshalled into a PublicKey in the // Validate function, so we really do not expect this to fail. panic(err) } return &pubKey }
go
func (c Config) IdentityPublicKey() *bakery.PublicKey { key := c.asString(IdentityPublicKey) if key == "" { return nil } var pubKey bakery.PublicKey err := pubKey.UnmarshalText([]byte(key)) if err != nil { // We check if the key string can be unmarshalled into a PublicKey in the // Validate function, so we really do not expect this to fail. panic(err) } return &pubKey }
[ "func", "(", "c", "Config", ")", "IdentityPublicKey", "(", ")", "*", "bakery", ".", "PublicKey", "{", "key", ":=", "c", ".", "asString", "(", "IdentityPublicKey", ")", "\n", "if", "key", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "var", "pubKey", "bakery", ".", "PublicKey", "\n", "err", ":=", "pubKey", ".", "UnmarshalText", "(", "[", "]", "byte", "(", "key", ")", ")", "\n", "if", "err", "!=", "nil", "{", "// We check if the key string can be unmarshalled into a PublicKey in the", "// Validate function, so we really do not expect this to fail.", "panic", "(", "err", ")", "\n", "}", "\n", "return", "&", "pubKey", "\n", "}" ]
// IdentityPublicKey returns the public key of the identity manager.
[ "IdentityPublicKey", "returns", "the", "public", "key", "of", "the", "identity", "manager", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L533-L546
153,722
juju/juju
controller/config.go
MongoMemoryProfile
func (c Config) MongoMemoryProfile() string { if profile, ok := c[MongoMemoryProfile]; ok { return profile.(string) } return DefaultMongoMemoryProfile }
go
func (c Config) MongoMemoryProfile() string { if profile, ok := c[MongoMemoryProfile]; ok { return profile.(string) } return DefaultMongoMemoryProfile }
[ "func", "(", "c", "Config", ")", "MongoMemoryProfile", "(", ")", "string", "{", "if", "profile", ",", "ok", ":=", "c", "[", "MongoMemoryProfile", "]", ";", "ok", "{", "return", "profile", ".", "(", "string", ")", "\n", "}", "\n", "return", "DefaultMongoMemoryProfile", "\n", "}" ]
// MongoMemoryProfile returns the selected profile or low.
[ "MongoMemoryProfile", "returns", "the", "selected", "profile", "or", "low", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L549-L554
153,723
juju/juju
controller/config.go
NUMACtlPreference
func (c Config) NUMACtlPreference() bool { if numa, ok := c[SetNUMAControlPolicyKey]; ok { return numa.(bool) } return DefaultNUMAControlPolicy }
go
func (c Config) NUMACtlPreference() bool { if numa, ok := c[SetNUMAControlPolicyKey]; ok { return numa.(bool) } return DefaultNUMAControlPolicy }
[ "func", "(", "c", "Config", ")", "NUMACtlPreference", "(", ")", "bool", "{", "if", "numa", ",", "ok", ":=", "c", "[", "SetNUMAControlPolicyKey", "]", ";", "ok", "{", "return", "numa", ".", "(", "bool", ")", "\n", "}", "\n", "return", "DefaultNUMAControlPolicy", "\n", "}" ]
// NUMACtlPreference returns if numactl is preferred.
[ "NUMACtlPreference", "returns", "if", "numactl", "is", "preferred", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L557-L562
153,724
juju/juju
controller/config.go
AllowModelAccess
func (c Config) AllowModelAccess() bool { value, _ := c[AllowModelAccessKey].(bool) return value }
go
func (c Config) AllowModelAccess() bool { value, _ := c[AllowModelAccessKey].(bool) return value }
[ "func", "(", "c", "Config", ")", "AllowModelAccess", "(", ")", "bool", "{", "value", ",", "_", ":=", "c", "[", "AllowModelAccessKey", "]", ".", "(", "bool", ")", "\n", "return", "value", "\n", "}" ]
// AllowModelAccess reports whether users are allowed to access models // they have been granted permission for even when they can't access // the controller.
[ "AllowModelAccess", "reports", "whether", "users", "are", "allowed", "to", "access", "models", "they", "have", "been", "granted", "permission", "for", "even", "when", "they", "can", "t", "access", "the", "controller", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L567-L570
153,725
juju/juju
controller/config.go
MaxLogSizeMB
func (c Config) MaxLogSizeMB() int { // Value has already been validated. val, _ := utils.ParseSize(c.mustString(MaxLogsSize)) return int(val) }
go
func (c Config) MaxLogSizeMB() int { // Value has already been validated. val, _ := utils.ParseSize(c.mustString(MaxLogsSize)) return int(val) }
[ "func", "(", "c", "Config", ")", "MaxLogSizeMB", "(", ")", "int", "{", "// Value has already been validated.", "val", ",", "_", ":=", "utils", ".", "ParseSize", "(", "c", ".", "mustString", "(", "MaxLogsSize", ")", ")", "\n", "return", "int", "(", "val", ")", "\n", "}" ]
// MaxLogSizeMB is the maximum size in MiB which the log collection // can grow to before being pruned.
[ "MaxLogSizeMB", "is", "the", "maximum", "size", "in", "MiB", "which", "the", "log", "collection", "can", "grow", "to", "before", "being", "pruned", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L581-L585
153,726
juju/juju
controller/config.go
MaxTxnLogSizeMB
func (c Config) MaxTxnLogSizeMB() int { // Value has already been validated. val, _ := utils.ParseSize(c.mustString(MaxTxnLogSize)) return int(val) }
go
func (c Config) MaxTxnLogSizeMB() int { // Value has already been validated. val, _ := utils.ParseSize(c.mustString(MaxTxnLogSize)) return int(val) }
[ "func", "(", "c", "Config", ")", "MaxTxnLogSizeMB", "(", ")", "int", "{", "// Value has already been validated.", "val", ",", "_", ":=", "utils", ".", "ParseSize", "(", "c", ".", "mustString", "(", "MaxTxnLogSize", ")", ")", "\n", "return", "int", "(", "val", ")", "\n", "}" ]
// MaxTxnLogSizeMB is the maximum size in MiB of the txn log collection.
[ "MaxTxnLogSizeMB", "is", "the", "maximum", "size", "in", "MiB", "of", "the", "txn", "log", "collection", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L588-L592
153,727
juju/juju
controller/config.go
PruneTxnSleepTime
func (c Config) PruneTxnSleepTime() time.Duration { asInterface, ok := c[PruneTxnSleepTime] if !ok { asInterface = DefaultPruneTxnSleepTime } asStr, ok := asInterface.(string) if !ok { asStr = DefaultPruneTxnSleepTime } val, _ := time.ParseDuration(asStr) return val }
go
func (c Config) PruneTxnSleepTime() time.Duration { asInterface, ok := c[PruneTxnSleepTime] if !ok { asInterface = DefaultPruneTxnSleepTime } asStr, ok := asInterface.(string) if !ok { asStr = DefaultPruneTxnSleepTime } val, _ := time.ParseDuration(asStr) return val }
[ "func", "(", "c", "Config", ")", "PruneTxnSleepTime", "(", ")", "time", ".", "Duration", "{", "asInterface", ",", "ok", ":=", "c", "[", "PruneTxnSleepTime", "]", "\n", "if", "!", "ok", "{", "asInterface", "=", "DefaultPruneTxnSleepTime", "\n", "}", "\n", "asStr", ",", "ok", ":=", "asInterface", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "asStr", "=", "DefaultPruneTxnSleepTime", "\n", "}", "\n", "val", ",", "_", ":=", "time", ".", "ParseDuration", "(", "asStr", ")", "\n", "return", "val", "\n", "}" ]
// PruneTxnSleepTime is the amount of time to sleep between batches.
[ "PruneTxnSleepTime", "is", "the", "amount", "of", "time", "to", "sleep", "between", "batches", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L610-L621
153,728
juju/juju
controller/config.go
MeteringURL
func (c Config) MeteringURL() string { url := c.asString(MeteringURL) if url == "" { return romulus.DefaultAPIRoot } return url }
go
func (c Config) MeteringURL() string { url := c.asString(MeteringURL) if url == "" { return romulus.DefaultAPIRoot } return url }
[ "func", "(", "c", "Config", ")", "MeteringURL", "(", ")", "string", "{", "url", ":=", "c", ".", "asString", "(", "MeteringURL", ")", "\n", "if", "url", "==", "\"", "\"", "{", "return", "romulus", ".", "DefaultAPIRoot", "\n", "}", "\n", "return", "url", "\n", "}" ]
// MeteringURL returns the URL to use for metering api calls.
[ "MeteringURL", "returns", "the", "URL", "to", "use", "for", "metering", "api", "calls", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L648-L654
153,729
juju/juju
controller/config.go
GenerateControllerCertAndKey
func GenerateControllerCertAndKey(caCert, caKey string, hostAddresses []string) (string, string, error) { return cert.NewDefaultServer(caCert, caKey, hostAddresses) }
go
func GenerateControllerCertAndKey(caCert, caKey string, hostAddresses []string) (string, string, error) { return cert.NewDefaultServer(caCert, caKey, hostAddresses) }
[ "func", "GenerateControllerCertAndKey", "(", "caCert", ",", "caKey", "string", ",", "hostAddresses", "[", "]", "string", ")", "(", "string", ",", "string", ",", "error", ")", "{", "return", "cert", ".", "NewDefaultServer", "(", "caCert", ",", "caKey", ",", "hostAddresses", ")", "\n", "}" ]
// GenerateControllerCertAndKey makes sure that the config has a CACert and // CAPrivateKey, generates and returns new certificate and key.
[ "GenerateControllerCertAndKey", "makes", "sure", "that", "the", "config", "has", "a", "CACert", "and", "CAPrivateKey", "generates", "and", "returns", "new", "certificate", "and", "key", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/controller/config.go#L845-L847
153,730
juju/juju
upgrades/steps_234.go
stateStepsFor234
func stateStepsFor234() []Step { return []Step{ &upgradeStep{ description: "delete cloud image metadata cache", targets: []Target{DatabaseMaster}, run: func(context Context) error { return context.State().DeleteCloudImageMetadata() }, }, } }
go
func stateStepsFor234() []Step { return []Step{ &upgradeStep{ description: "delete cloud image metadata cache", targets: []Target{DatabaseMaster}, run: func(context Context) error { return context.State().DeleteCloudImageMetadata() }, }, } }
[ "func", "stateStepsFor234", "(", ")", "[", "]", "Step", "{", "return", "[", "]", "Step", "{", "&", "upgradeStep", "{", "description", ":", "\"", "\"", ",", "targets", ":", "[", "]", "Target", "{", "DatabaseMaster", "}", ",", "run", ":", "func", "(", "context", "Context", ")", "error", "{", "return", "context", ".", "State", "(", ")", ".", "DeleteCloudImageMetadata", "(", ")", "\n", "}", ",", "}", ",", "}", "\n", "}" ]
// stateStepsFor234 returns upgrade steps for Juju 2.3.4 that manipulate state directly.
[ "stateStepsFor234", "returns", "upgrade", "steps", "for", "Juju", "2", ".", "3", ".", "4", "that", "manipulate", "state", "directly", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/upgrades/steps_234.go#L7-L17
153,731
juju/juju
cmd/juju/model/mocks/diff_mock.go
NewMockDiffCommandAPI
func NewMockDiffCommandAPI(ctrl *gomock.Controller) *MockDiffCommandAPI { mock := &MockDiffCommandAPI{ctrl: ctrl} mock.recorder = &MockDiffCommandAPIMockRecorder{mock} return mock }
go
func NewMockDiffCommandAPI(ctrl *gomock.Controller) *MockDiffCommandAPI { mock := &MockDiffCommandAPI{ctrl: ctrl} mock.recorder = &MockDiffCommandAPIMockRecorder{mock} return mock }
[ "func", "NewMockDiffCommandAPI", "(", "ctrl", "*", "gomock", ".", "Controller", ")", "*", "MockDiffCommandAPI", "{", "mock", ":=", "&", "MockDiffCommandAPI", "{", "ctrl", ":", "ctrl", "}", "\n", "mock", ".", "recorder", "=", "&", "MockDiffCommandAPIMockRecorder", "{", "mock", "}", "\n", "return", "mock", "\n", "}" ]
// NewMockDiffCommandAPI creates a new mock instance
[ "NewMockDiffCommandAPI", "creates", "a", "new", "mock", "instance" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/model/mocks/diff_mock.go#L26-L30
153,732
juju/juju
cmd/juju/model/mocks/diff_mock.go
BranchInfo
func (m *MockDiffCommandAPI) BranchInfo(arg0 string, arg1 bool, arg2 func(time.Time) string) (map[string]model.Generation, error) { ret := m.ctrl.Call(m, "BranchInfo", arg0, arg1, arg2) ret0, _ := ret[0].(map[string]model.Generation) ret1, _ := ret[1].(error) return ret0, ret1 }
go
func (m *MockDiffCommandAPI) BranchInfo(arg0 string, arg1 bool, arg2 func(time.Time) string) (map[string]model.Generation, error) { ret := m.ctrl.Call(m, "BranchInfo", arg0, arg1, arg2) ret0, _ := ret[0].(map[string]model.Generation) ret1, _ := ret[1].(error) return ret0, ret1 }
[ "func", "(", "m", "*", "MockDiffCommandAPI", ")", "BranchInfo", "(", "arg0", "string", ",", "arg1", "bool", ",", "arg2", "func", "(", "time", ".", "Time", ")", "string", ")", "(", "map", "[", "string", "]", "model", ".", "Generation", ",", "error", ")", "{", "ret", ":=", "m", ".", "ctrl", ".", "Call", "(", "m", ",", "\"", "\"", ",", "arg0", ",", "arg1", ",", "arg2", ")", "\n", "ret0", ",", "_", ":=", "ret", "[", "0", "]", ".", "(", "map", "[", "string", "]", "model", ".", "Generation", ")", "\n", "ret1", ",", "_", ":=", "ret", "[", "1", "]", ".", "(", "error", ")", "\n", "return", "ret0", ",", "ret1", "\n", "}" ]
// BranchInfo mocks base method
[ "BranchInfo", "mocks", "base", "method" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/model/mocks/diff_mock.go#L38-L43
153,733
juju/juju
cmd/juju/model/mocks/diff_mock.go
BranchInfo
func (mr *MockDiffCommandAPIMockRecorder) BranchInfo(arg0, arg1, arg2 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BranchInfo", reflect.TypeOf((*MockDiffCommandAPI)(nil).BranchInfo), arg0, arg1, arg2) }
go
func (mr *MockDiffCommandAPIMockRecorder) BranchInfo(arg0, arg1, arg2 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BranchInfo", reflect.TypeOf((*MockDiffCommandAPI)(nil).BranchInfo), arg0, arg1, arg2) }
[ "func", "(", "mr", "*", "MockDiffCommandAPIMockRecorder", ")", "BranchInfo", "(", "arg0", ",", "arg1", ",", "arg2", "interface", "{", "}", ")", "*", "gomock", ".", "Call", "{", "return", "mr", ".", "mock", ".", "ctrl", ".", "RecordCallWithMethodType", "(", "mr", ".", "mock", ",", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "(", "*", "MockDiffCommandAPI", ")", "(", "nil", ")", ".", "BranchInfo", ")", ",", "arg0", ",", "arg1", ",", "arg2", ")", "\n", "}" ]
// BranchInfo indicates an expected call of BranchInfo
[ "BranchInfo", "indicates", "an", "expected", "call", "of", "BranchInfo" ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/model/mocks/diff_mock.go#L46-L48
153,734
juju/juju
apiserver/facades/client/charms/client.go
List
func (a *API) List(args params.CharmsList) (params.CharmsListResult, error) { if err := a.checkCanRead(); err != nil { return params.CharmsListResult{}, errors.Trace(err) } charms, err := a.backend.AllCharms() if err != nil { return params.CharmsListResult{}, errors.Annotatef(err, " listing charms ") } names := set.NewStrings(args.Names...) checkName := !names.IsEmpty() charmURLs := []string{} for _, aCharm := range charms { charmURL := aCharm.URL() if checkName { if !names.Contains(charmURL.Name) { continue } } charmURLs = append(charmURLs, charmURL.String()) } return params.CharmsListResult{CharmURLs: charmURLs}, nil }
go
func (a *API) List(args params.CharmsList) (params.CharmsListResult, error) { if err := a.checkCanRead(); err != nil { return params.CharmsListResult{}, errors.Trace(err) } charms, err := a.backend.AllCharms() if err != nil { return params.CharmsListResult{}, errors.Annotatef(err, " listing charms ") } names := set.NewStrings(args.Names...) checkName := !names.IsEmpty() charmURLs := []string{} for _, aCharm := range charms { charmURL := aCharm.URL() if checkName { if !names.Contains(charmURL.Name) { continue } } charmURLs = append(charmURLs, charmURL.String()) } return params.CharmsListResult{CharmURLs: charmURLs}, nil }
[ "func", "(", "a", "*", "API", ")", "List", "(", "args", "params", ".", "CharmsList", ")", "(", "params", ".", "CharmsListResult", ",", "error", ")", "{", "if", "err", ":=", "a", ".", "checkCanRead", "(", ")", ";", "err", "!=", "nil", "{", "return", "params", ".", "CharmsListResult", "{", "}", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "charms", ",", "err", ":=", "a", ".", "backend", ".", "AllCharms", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "params", ".", "CharmsListResult", "{", "}", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "names", ":=", "set", ".", "NewStrings", "(", "args", ".", "Names", "...", ")", "\n", "checkName", ":=", "!", "names", ".", "IsEmpty", "(", ")", "\n", "charmURLs", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "aCharm", ":=", "range", "charms", "{", "charmURL", ":=", "aCharm", ".", "URL", "(", ")", "\n", "if", "checkName", "{", "if", "!", "names", ".", "Contains", "(", "charmURL", ".", "Name", ")", "{", "continue", "\n", "}", "\n", "}", "\n", "charmURLs", "=", "append", "(", "charmURLs", ",", "charmURL", ".", "String", "(", ")", ")", "\n", "}", "\n", "return", "params", ".", "CharmsListResult", "{", "CharmURLs", ":", "charmURLs", "}", ",", "nil", "\n", "}" ]
// List returns a list of charm URLs currently in the state. // If supplied parameter contains any names, the result will be filtered // to return only the charms with supplied names.
[ "List", "returns", "a", "list", "of", "charm", "URLs", "currently", "in", "the", "state", ".", "If", "supplied", "parameter", "contains", "any", "names", "the", "result", "will", "be", "filtered", "to", "return", "only", "the", "charms", "with", "supplied", "names", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/client/charms/client.go#L110-L133
153,735
juju/juju
container/network.go
FallbackInterfaceInfo
func FallbackInterfaceInfo() []network.InterfaceInfo { return []network.InterfaceInfo{{ InterfaceName: "eth0", InterfaceType: network.EthernetInterface, ConfigType: network.ConfigDHCP, }} }
go
func FallbackInterfaceInfo() []network.InterfaceInfo { return []network.InterfaceInfo{{ InterfaceName: "eth0", InterfaceType: network.EthernetInterface, ConfigType: network.ConfigDHCP, }} }
[ "func", "FallbackInterfaceInfo", "(", ")", "[", "]", "network", ".", "InterfaceInfo", "{", "return", "[", "]", "network", ".", "InterfaceInfo", "{", "{", "InterfaceName", ":", "\"", "\"", ",", "InterfaceType", ":", "network", ".", "EthernetInterface", ",", "ConfigType", ":", "network", ".", "ConfigDHCP", ",", "}", "}", "\n", "}" ]
// FallbackInterfaceInfo returns a single "eth0" interface configured with DHCP.
[ "FallbackInterfaceInfo", "returns", "a", "single", "eth0", "interface", "configured", "with", "DHCP", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/network.go#L25-L31
153,736
juju/juju
cloudconfig/cloudinit/cloudinit.go
SetAttr
func (cfg *cloudConfig) SetAttr(name string, value interface{}) { cfg.attrs[name] = value }
go
func (cfg *cloudConfig) SetAttr(name string, value interface{}) { cfg.attrs[name] = value }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "SetAttr", "(", "name", "string", ",", "value", "interface", "{", "}", ")", "{", "cfg", ".", "attrs", "[", "name", "]", "=", "value", "\n", "}" ]
// SetAttr is defined on the CloudConfig interface.
[ "SetAttr", "is", "defined", "on", "the", "CloudConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L92-L94
153,737
juju/juju
cloudconfig/cloudinit/cloudinit.go
AddUser
func (cfg *cloudConfig) AddUser(user *User) { users, _ := cfg.attrs["users"].([]map[string]interface{}) newUser := map[string]interface{}{ "name": user.Name, "lock_passwd": true, } if user.Groups != nil { newUser["groups"] = user.Groups } if user.Shell != "" { newUser["shell"] = user.Shell } if user.SSHAuthorizedKeys != "" { newUser["ssh-authorized-keys"] = annotateKeys(user.SSHAuthorizedKeys) } if user.Sudo != nil { newUser["sudo"] = user.Sudo } cfg.SetAttr("users", append(users, newUser)) }
go
func (cfg *cloudConfig) AddUser(user *User) { users, _ := cfg.attrs["users"].([]map[string]interface{}) newUser := map[string]interface{}{ "name": user.Name, "lock_passwd": true, } if user.Groups != nil { newUser["groups"] = user.Groups } if user.Shell != "" { newUser["shell"] = user.Shell } if user.SSHAuthorizedKeys != "" { newUser["ssh-authorized-keys"] = annotateKeys(user.SSHAuthorizedKeys) } if user.Sudo != nil { newUser["sudo"] = user.Sudo } cfg.SetAttr("users", append(users, newUser)) }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "AddUser", "(", "user", "*", "User", ")", "{", "users", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "[", "]", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "newUser", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "user", ".", "Name", ",", "\"", "\"", ":", "true", ",", "}", "\n", "if", "user", ".", "Groups", "!=", "nil", "{", "newUser", "[", "\"", "\"", "]", "=", "user", ".", "Groups", "\n", "}", "\n", "if", "user", ".", "Shell", "!=", "\"", "\"", "{", "newUser", "[", "\"", "\"", "]", "=", "user", ".", "Shell", "\n", "}", "\n", "if", "user", ".", "SSHAuthorizedKeys", "!=", "\"", "\"", "{", "newUser", "[", "\"", "\"", "]", "=", "annotateKeys", "(", "user", ".", "SSHAuthorizedKeys", ")", "\n", "}", "\n", "if", "user", ".", "Sudo", "!=", "nil", "{", "newUser", "[", "\"", "\"", "]", "=", "user", ".", "Sudo", "\n", "}", "\n", "cfg", ".", "SetAttr", "(", "\"", "\"", ",", "append", "(", "users", ",", "newUser", ")", ")", "\n", "}" ]
// AddUser is defined on the UsersConfig interface.
[ "AddUser", "is", "defined", "on", "the", "UsersConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L114-L133
153,738
juju/juju
cloudconfig/cloudinit/cloudinit.go
SystemUpdate
func (cfg *cloudConfig) SystemUpdate() bool { update, _ := cfg.attrs["package_update"].(bool) return update }
go
func (cfg *cloudConfig) SystemUpdate() bool { update, _ := cfg.attrs["package_update"].(bool) return update }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "SystemUpdate", "(", ")", "bool", "{", "update", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "bool", ")", "\n", "return", "update", "\n", "}" ]
// SystemUpdate is defined on the SystemUpdateConfig interface.
[ "SystemUpdate", "is", "defined", "on", "the", "SystemUpdateConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L151-L154
153,739
juju/juju
cloudconfig/cloudinit/cloudinit.go
SystemUpgrade
func (cfg *cloudConfig) SystemUpgrade() bool { upgrade, _ := cfg.attrs["package_upgrade"].(bool) return upgrade }
go
func (cfg *cloudConfig) SystemUpgrade() bool { upgrade, _ := cfg.attrs["package_upgrade"].(bool) return upgrade }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "SystemUpgrade", "(", ")", "bool", "{", "upgrade", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "bool", ")", "\n", "return", "upgrade", "\n", "}" ]
// SystemUpgrade is defined on the SystemUpgradeConfig interface.
[ "SystemUpgrade", "is", "defined", "on", "the", "SystemUpgradeConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L167-L170
153,740
juju/juju
cloudconfig/cloudinit/cloudinit.go
AddPackage
func (cfg *cloudConfig) AddPackage(pack string) { cfg.attrs["packages"] = append(cfg.Packages(), pack) }
go
func (cfg *cloudConfig) AddPackage(pack string) { cfg.attrs["packages"] = append(cfg.Packages(), pack) }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "AddPackage", "(", "pack", "string", ")", "{", "cfg", ".", "attrs", "[", "\"", "\"", "]", "=", "append", "(", "cfg", ".", "Packages", "(", ")", ",", "pack", ")", "\n", "}" ]
// AddPackage is defined on the PackagingConfig interface.
[ "AddPackage", "is", "defined", "on", "the", "PackagingConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L173-L175
153,741
juju/juju
cloudconfig/cloudinit/cloudinit.go
RemovePackage
func (cfg *cloudConfig) RemovePackage(pack string) { cfg.attrs["packages"] = removeStringFromSlice(cfg.Packages(), pack) }
go
func (cfg *cloudConfig) RemovePackage(pack string) { cfg.attrs["packages"] = removeStringFromSlice(cfg.Packages(), pack) }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "RemovePackage", "(", "pack", "string", ")", "{", "cfg", ".", "attrs", "[", "\"", "\"", "]", "=", "removeStringFromSlice", "(", "cfg", ".", "Packages", "(", ")", ",", "pack", ")", "\n", "}" ]
// RemovePackage is defined on the PackagingConfig interface.
[ "RemovePackage", "is", "defined", "on", "the", "PackagingConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L178-L180
153,742
juju/juju
cloudconfig/cloudinit/cloudinit.go
Packages
func (cfg *cloudConfig) Packages() []string { packs, _ := cfg.attrs["packages"].([]string) return packs }
go
func (cfg *cloudConfig) Packages() []string { packs, _ := cfg.attrs["packages"].([]string) return packs }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "Packages", "(", ")", "[", "]", "string", "{", "packs", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "[", "]", "string", ")", "\n", "return", "packs", "\n", "}" ]
// Packages is defined on the PackagingConfig interface.
[ "Packages", "is", "defined", "on", "the", "PackagingConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L183-L186
153,743
juju/juju
cloudconfig/cloudinit/cloudinit.go
AddRunCmd
func (cfg *cloudConfig) AddRunCmd(args ...string) { cfg.attrs["runcmd"] = append(cfg.RunCmds(), strings.Join(args, " ")) }
go
func (cfg *cloudConfig) AddRunCmd(args ...string) { cfg.attrs["runcmd"] = append(cfg.RunCmds(), strings.Join(args, " ")) }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "AddRunCmd", "(", "args", "...", "string", ")", "{", "cfg", ".", "attrs", "[", "\"", "\"", "]", "=", "append", "(", "cfg", ".", "RunCmds", "(", ")", ",", "strings", ".", "Join", "(", "args", ",", "\"", "\"", ")", ")", "\n", "}" ]
// AddRunCmd is defined on the RunCmdsConfig interface.
[ "AddRunCmd", "is", "defined", "on", "the", "RunCmdsConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L189-L191
153,744
juju/juju
cloudconfig/cloudinit/cloudinit.go
AddScripts
func (cfg *cloudConfig) AddScripts(script ...string) { for _, line := range script { cfg.AddRunCmd(line) } }
go
func (cfg *cloudConfig) AddScripts(script ...string) { for _, line := range script { cfg.AddRunCmd(line) } }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "AddScripts", "(", "script", "...", "string", ")", "{", "for", "_", ",", "line", ":=", "range", "script", "{", "cfg", ".", "AddRunCmd", "(", "line", ")", "\n", "}", "\n", "}" ]
// AddScripts is defined on the RunCmdsConfig interface.
[ "AddScripts", "is", "defined", "on", "the", "RunCmdsConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L194-L198
153,745
juju/juju
cloudconfig/cloudinit/cloudinit.go
RemoveRunCmd
func (cfg *cloudConfig) RemoveRunCmd(cmd string) { cfg.attrs["runcmd"] = removeStringFromSlice(cfg.RunCmds(), cmd) }
go
func (cfg *cloudConfig) RemoveRunCmd(cmd string) { cfg.attrs["runcmd"] = removeStringFromSlice(cfg.RunCmds(), cmd) }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "RemoveRunCmd", "(", "cmd", "string", ")", "{", "cfg", ".", "attrs", "[", "\"", "\"", "]", "=", "removeStringFromSlice", "(", "cfg", ".", "RunCmds", "(", ")", ",", "cmd", ")", "\n", "}" ]
// RemoveRunCmd is defined on the RunCmdsConfig interface.
[ "RemoveRunCmd", "is", "defined", "on", "the", "RunCmdsConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L206-L208
153,746
juju/juju
cloudconfig/cloudinit/cloudinit.go
RunCmds
func (cfg *cloudConfig) RunCmds() []string { cmds, _ := cfg.attrs["runcmd"].([]string) return cmds }
go
func (cfg *cloudConfig) RunCmds() []string { cmds, _ := cfg.attrs["runcmd"].([]string) return cmds }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "RunCmds", "(", ")", "[", "]", "string", "{", "cmds", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "[", "]", "string", ")", "\n", "return", "cmds", "\n", "}" ]
// RunCmds is defined on the RunCmdsConfig interface.
[ "RunCmds", "is", "defined", "on", "the", "RunCmdsConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L211-L214
153,747
juju/juju
cloudconfig/cloudinit/cloudinit.go
AddBootCmd
func (cfg *cloudConfig) AddBootCmd(args ...string) { cfg.attrs["bootcmd"] = append(cfg.BootCmds(), strings.Join(args, " ")) }
go
func (cfg *cloudConfig) AddBootCmd(args ...string) { cfg.attrs["bootcmd"] = append(cfg.BootCmds(), strings.Join(args, " ")) }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "AddBootCmd", "(", "args", "...", "string", ")", "{", "cfg", ".", "attrs", "[", "\"", "\"", "]", "=", "append", "(", "cfg", ".", "BootCmds", "(", ")", ",", "strings", ".", "Join", "(", "args", ",", "\"", "\"", ")", ")", "\n", "}" ]
// AddBootCmd is defined on the BootCmdsConfig interface.
[ "AddBootCmd", "is", "defined", "on", "the", "BootCmdsConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L217-L219
153,748
juju/juju
cloudconfig/cloudinit/cloudinit.go
RemoveBootCmd
func (cfg *cloudConfig) RemoveBootCmd(cmd string) { cfg.attrs["bootcmd"] = removeStringFromSlice(cfg.BootCmds(), cmd) }
go
func (cfg *cloudConfig) RemoveBootCmd(cmd string) { cfg.attrs["bootcmd"] = removeStringFromSlice(cfg.BootCmds(), cmd) }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "RemoveBootCmd", "(", "cmd", "string", ")", "{", "cfg", ".", "attrs", "[", "\"", "\"", "]", "=", "removeStringFromSlice", "(", "cfg", ".", "BootCmds", "(", ")", ",", "cmd", ")", "\n", "}" ]
// RemoveBootCmd is defined on the BootCmdsConfig interface.
[ "RemoveBootCmd", "is", "defined", "on", "the", "BootCmdsConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L222-L224
153,749
juju/juju
cloudconfig/cloudinit/cloudinit.go
BootCmds
func (cfg *cloudConfig) BootCmds() []string { cmds, _ := cfg.attrs["bootcmd"].([]string) return cmds }
go
func (cfg *cloudConfig) BootCmds() []string { cmds, _ := cfg.attrs["bootcmd"].([]string) return cmds }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "BootCmds", "(", ")", "[", "]", "string", "{", "cmds", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "[", "]", "string", ")", "\n", "return", "cmds", "\n", "}" ]
// BootCmds is defined on the BootCmdsConfig interface.
[ "BootCmds", "is", "defined", "on", "the", "BootCmdsConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L227-L230
153,750
juju/juju
cloudconfig/cloudinit/cloudinit.go
DisableEC2Metadata
func (cfg *cloudConfig) DisableEC2Metadata() bool { disEC2, _ := cfg.attrs["disable_ec2_metadata"].(bool) return disEC2 }
go
func (cfg *cloudConfig) DisableEC2Metadata() bool { disEC2, _ := cfg.attrs["disable_ec2_metadata"].(bool) return disEC2 }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "DisableEC2Metadata", "(", ")", "bool", "{", "disEC2", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "bool", ")", "\n", "return", "disEC2", "\n", "}" ]
// DisableEC2Metadata is defined on the EC2MetadataConfig interface.
[ "DisableEC2Metadata", "is", "defined", "on", "the", "EC2MetadataConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L243-L246
153,751
juju/juju
cloudconfig/cloudinit/cloudinit.go
FinalMessage
func (cfg *cloudConfig) FinalMessage() string { message, _ := cfg.attrs["final_message"].(string) return message }
go
func (cfg *cloudConfig) FinalMessage() string { message, _ := cfg.attrs["final_message"].(string) return message }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "FinalMessage", "(", ")", "string", "{", "message", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "return", "message", "\n", "}" ]
// FinalMessage is defined on the FinalMessageConfig interface.
[ "FinalMessage", "is", "defined", "on", "the", "FinalMessageConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L259-L262
153,752
juju/juju
cloudconfig/cloudinit/cloudinit.go
Locale
func (cfg *cloudConfig) Locale() string { locale, _ := cfg.attrs["locale"].(string) return locale }
go
func (cfg *cloudConfig) Locale() string { locale, _ := cfg.attrs["locale"].(string) return locale }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "Locale", "(", ")", "string", "{", "locale", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "string", ")", "\n", "return", "locale", "\n", "}" ]
// Locale is defined on the LocaleConfig interface.
[ "Locale", "is", "defined", "on", "the", "LocaleConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L275-L278
153,753
juju/juju
cloudconfig/cloudinit/cloudinit.go
SetOutput
func (cfg *cloudConfig) SetOutput(kind OutputKind, stdout, stderr string) { out, _ := cfg.attrs["output"].(map[string]interface{}) if out == nil { out = make(map[string]interface{}) } if stderr == "" { out[string(kind)] = stdout } else { out[string(kind)] = []string{stdout, stderr} } cfg.SetAttr("output", out) }
go
func (cfg *cloudConfig) SetOutput(kind OutputKind, stdout, stderr string) { out, _ := cfg.attrs["output"].(map[string]interface{}) if out == nil { out = make(map[string]interface{}) } if stderr == "" { out[string(kind)] = stdout } else { out[string(kind)] = []string{stdout, stderr} } cfg.SetAttr("output", out) }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "SetOutput", "(", "kind", "OutputKind", ",", "stdout", ",", "stderr", "string", ")", "{", "out", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "if", "out", "==", "nil", "{", "out", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n\n", "if", "stderr", "==", "\"", "\"", "{", "out", "[", "string", "(", "kind", ")", "]", "=", "stdout", "\n", "}", "else", "{", "out", "[", "string", "(", "kind", ")", "]", "=", "[", "]", "string", "{", "stdout", ",", "stderr", "}", "\n", "}", "\n\n", "cfg", ".", "SetAttr", "(", "\"", "\"", ",", "out", ")", "\n", "}" ]
// SetOutput is defined on the OutputConfig interface.
[ "SetOutput", "is", "defined", "on", "the", "OutputConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L289-L302
153,754
juju/juju
cloudconfig/cloudinit/cloudinit.go
Output
func (cfg *cloudConfig) Output(kind OutputKind) (stdout, stderr string) { if out, ok := cfg.attrs["output"].(map[string]interface{}); ok { switch out := out[string(kind)].(type) { case string: stdout = out case []string: stdout, stderr = out[0], out[1] } } return stdout, stderr }
go
func (cfg *cloudConfig) Output(kind OutputKind) (stdout, stderr string) { if out, ok := cfg.attrs["output"].(map[string]interface{}); ok { switch out := out[string(kind)].(type) { case string: stdout = out case []string: stdout, stderr = out[0], out[1] } } return stdout, stderr }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "Output", "(", "kind", "OutputKind", ")", "(", "stdout", ",", "stderr", "string", ")", "{", "if", "out", ",", "ok", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", ";", "ok", "{", "switch", "out", ":=", "out", "[", "string", "(", "kind", ")", "]", ".", "(", "type", ")", "{", "case", "string", ":", "stdout", "=", "out", "\n", "case", "[", "]", "string", ":", "stdout", ",", "stderr", "=", "out", "[", "0", "]", ",", "out", "[", "1", "]", "\n", "}", "\n", "}", "\n\n", "return", "stdout", ",", "stderr", "\n", "}" ]
// Output is defined on the OutputConfig interface.
[ "Output", "is", "defined", "on", "the", "OutputConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L305-L316
153,755
juju/juju
cloudconfig/cloudinit/cloudinit.go
SetSSHAuthorizedKeys
func (cfg *cloudConfig) SetSSHAuthorizedKeys(rawKeys string) { keys := annotateKeys(rawKeys) if len(keys) != 0 { cfg.SetAttr("ssh_authorized_keys", keys) } else { cfg.UnsetAttr("ssh_authorized_keys") } }
go
func (cfg *cloudConfig) SetSSHAuthorizedKeys(rawKeys string) { keys := annotateKeys(rawKeys) if len(keys) != 0 { cfg.SetAttr("ssh_authorized_keys", keys) } else { cfg.UnsetAttr("ssh_authorized_keys") } }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "SetSSHAuthorizedKeys", "(", "rawKeys", "string", ")", "{", "keys", ":=", "annotateKeys", "(", "rawKeys", ")", "\n", "if", "len", "(", "keys", ")", "!=", "0", "{", "cfg", ".", "SetAttr", "(", "\"", "\"", ",", "keys", ")", "\n", "}", "else", "{", "cfg", ".", "UnsetAttr", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// SetSSHAuthorizedKeys is defined on the SSHAuthorizedKeysConfig interface.
[ "SetSSHAuthorizedKeys", "is", "defined", "on", "the", "SSHAuthorizedKeysConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L319-L326
153,756
juju/juju
cloudconfig/cloudinit/cloudinit.go
SetSSHKeys
func (cfg *cloudConfig) SetSSHKeys(keys SSHKeys) { if keys.RSA != nil { cfg.SetAttr("ssh_keys", map[string]interface{}{ string(RSAPrivate): keys.RSA.Private, string(RSAPublic): keys.RSA.Public, }) } else { cfg.UnsetAttr("ssh_keys") } }
go
func (cfg *cloudConfig) SetSSHKeys(keys SSHKeys) { if keys.RSA != nil { cfg.SetAttr("ssh_keys", map[string]interface{}{ string(RSAPrivate): keys.RSA.Private, string(RSAPublic): keys.RSA.Public, }) } else { cfg.UnsetAttr("ssh_keys") } }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "SetSSHKeys", "(", "keys", "SSHKeys", ")", "{", "if", "keys", ".", "RSA", "!=", "nil", "{", "cfg", ".", "SetAttr", "(", "\"", "\"", ",", "map", "[", "string", "]", "interface", "{", "}", "{", "string", "(", "RSAPrivate", ")", ":", "keys", ".", "RSA", ".", "Private", ",", "string", "(", "RSAPublic", ")", ":", "keys", ".", "RSA", ".", "Public", ",", "}", ")", "\n", "}", "else", "{", "cfg", ".", "UnsetAttr", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// SetSSHKeys is defined on the SSHKeysConfig interface.
[ "SetSSHKeys", "is", "defined", "on", "the", "SSHKeysConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L329-L338
153,757
juju/juju
cloudconfig/cloudinit/cloudinit.go
DisableRoot
func (cfg *cloudConfig) DisableRoot() bool { disable, _ := cfg.attrs["disable_root"].(bool) return disable }
go
func (cfg *cloudConfig) DisableRoot() bool { disable, _ := cfg.attrs["disable_root"].(bool) return disable }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "DisableRoot", "(", ")", "bool", "{", "disable", ",", "_", ":=", "cfg", ".", "attrs", "[", "\"", "\"", "]", ".", "(", "bool", ")", "\n", "return", "disable", "\n", "}" ]
// DisableRoot is defined on the RootUserConfig interface.
[ "DisableRoot", "is", "defined", "on", "the", "RootUserConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L351-L354
153,758
juju/juju
cloudconfig/cloudinit/cloudinit.go
AddRunTextFile
func (cfg *cloudConfig) AddRunTextFile(filename, contents string, perm uint) { cfg.AddScripts(addFileCmds(filename, []byte(contents), perm, false)...) }
go
func (cfg *cloudConfig) AddRunTextFile(filename, contents string, perm uint) { cfg.AddScripts(addFileCmds(filename, []byte(contents), perm, false)...) }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "AddRunTextFile", "(", "filename", ",", "contents", "string", ",", "perm", "uint", ")", "{", "cfg", ".", "AddScripts", "(", "addFileCmds", "(", "filename", ",", "[", "]", "byte", "(", "contents", ")", ",", "perm", ",", "false", ")", "...", ")", "\n", "}" ]
// AddRunTextFile is defined on the WrittenFilesConfig interface.
[ "AddRunTextFile", "is", "defined", "on", "the", "WrittenFilesConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L366-L368
153,759
juju/juju
cloudconfig/cloudinit/cloudinit.go
AddBootTextFile
func (cfg *cloudConfig) AddBootTextFile(filename, contents string, perm uint) { for _, cmd := range addFileCmds(filename, []byte(contents), perm, false) { cfg.AddBootCmd(cmd) } }
go
func (cfg *cloudConfig) AddBootTextFile(filename, contents string, perm uint) { for _, cmd := range addFileCmds(filename, []byte(contents), perm, false) { cfg.AddBootCmd(cmd) } }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "AddBootTextFile", "(", "filename", ",", "contents", "string", ",", "perm", "uint", ")", "{", "for", "_", ",", "cmd", ":=", "range", "addFileCmds", "(", "filename", ",", "[", "]", "byte", "(", "contents", ")", ",", "perm", ",", "false", ")", "{", "cfg", ".", "AddBootCmd", "(", "cmd", ")", "\n", "}", "\n", "}" ]
// AddBootTextFile is defined on the WrittenFilesConfig interface.
[ "AddBootTextFile", "is", "defined", "on", "the", "WrittenFilesConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L371-L375
153,760
juju/juju
cloudconfig/cloudinit/cloudinit.go
AddRunBinaryFile
func (cfg *cloudConfig) AddRunBinaryFile(filename string, data []byte, mode uint) { cfg.AddScripts(addFileCmds(filename, data, mode, true)...) }
go
func (cfg *cloudConfig) AddRunBinaryFile(filename string, data []byte, mode uint) { cfg.AddScripts(addFileCmds(filename, data, mode, true)...) }
[ "func", "(", "cfg", "*", "cloudConfig", ")", "AddRunBinaryFile", "(", "filename", "string", ",", "data", "[", "]", "byte", ",", "mode", "uint", ")", "{", "cfg", ".", "AddScripts", "(", "addFileCmds", "(", "filename", ",", "data", ",", "mode", ",", "true", ")", "...", ")", "\n", "}" ]
// AddRunBinaryFile is defined on the WrittenFilesConfig interface.
[ "AddRunBinaryFile", "is", "defined", "on", "the", "WrittenFilesConfig", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloudconfig/cloudinit/cloudinit.go#L378-L380
153,761
juju/juju
storage/provider/rootfs.go
ensureDir
func ensureDir(d dirFuncs, path string) error { // If path already exists, we check that it is empty. // It is up to the storage provisioner to ensure that any // shared storage constraints and attachments with the same // path are validated etc. So the check here is more a sanity check. fi, err := d.lstat(path) if err == nil { if !fi.IsDir() { return errors.Errorf("path %q must be a directory", path) } return nil } if !os.IsNotExist(err) { return errors.Trace(err) } if err := d.mkDirAll(path, 0755); err != nil { return errors.Annotate(err, "could not create directory") } return nil }
go
func ensureDir(d dirFuncs, path string) error { // If path already exists, we check that it is empty. // It is up to the storage provisioner to ensure that any // shared storage constraints and attachments with the same // path are validated etc. So the check here is more a sanity check. fi, err := d.lstat(path) if err == nil { if !fi.IsDir() { return errors.Errorf("path %q must be a directory", path) } return nil } if !os.IsNotExist(err) { return errors.Trace(err) } if err := d.mkDirAll(path, 0755); err != nil { return errors.Annotate(err, "could not create directory") } return nil }
[ "func", "ensureDir", "(", "d", "dirFuncs", ",", "path", "string", ")", "error", "{", "// If path already exists, we check that it is empty.", "// It is up to the storage provisioner to ensure that any", "// shared storage constraints and attachments with the same", "// path are validated etc. So the check here is more a sanity check.", "fi", ",", "err", ":=", "d", ".", "lstat", "(", "path", ")", "\n", "if", "err", "==", "nil", "{", "if", "!", "fi", ".", "IsDir", "(", ")", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "path", ")", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "if", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "if", "err", ":=", "d", ".", "mkDirAll", "(", "path", ",", "0755", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ensureDir ensures the specified path is a directory, or // if it does not exist, that a directory can be created there.
[ "ensureDir", "ensures", "the", "specified", "path", "is", "a", "directory", "or", "if", "it", "does", "not", "exist", "that", "a", "directory", "can", "be", "created", "there", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/rootfs.go#L103-L122
153,762
juju/juju
storage/provider/rootfs.go
ensureEmptyDir
func ensureEmptyDir(d dirFuncs, path string) error { fileCount, err := d.fileCount(path) if err != nil { return errors.Annotate(err, "could not read directory") } if fileCount > 0 { return errors.Errorf("%q is not empty", path) } return nil }
go
func ensureEmptyDir(d dirFuncs, path string) error { fileCount, err := d.fileCount(path) if err != nil { return errors.Annotate(err, "could not read directory") } if fileCount > 0 { return errors.Errorf("%q is not empty", path) } return nil }
[ "func", "ensureEmptyDir", "(", "d", "dirFuncs", ",", "path", "string", ")", "error", "{", "fileCount", ",", "err", ":=", "d", ".", "fileCount", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "fileCount", ">", "0", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "path", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ensureEmptyDir ensures the specified directory is empty.
[ "ensureEmptyDir", "ensures", "the", "specified", "directory", "is", "empty", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/rootfs.go#L125-L134
153,763
juju/juju
storage/provider/rootfs.go
CreateFilesystems
func (s *rootfsFilesystemSource) CreateFilesystems(ctx context.ProviderCallContext, args []storage.FilesystemParams) ([]storage.CreateFilesystemsResult, error) { results := make([]storage.CreateFilesystemsResult, len(args)) for i, arg := range args { filesystem, err := s.createFilesystem(arg) if err != nil { results[i].Error = err continue } results[i].Filesystem = filesystem } return results, nil }
go
func (s *rootfsFilesystemSource) CreateFilesystems(ctx context.ProviderCallContext, args []storage.FilesystemParams) ([]storage.CreateFilesystemsResult, error) { results := make([]storage.CreateFilesystemsResult, len(args)) for i, arg := range args { filesystem, err := s.createFilesystem(arg) if err != nil { results[i].Error = err continue } results[i].Filesystem = filesystem } return results, nil }
[ "func", "(", "s", "*", "rootfsFilesystemSource", ")", "CreateFilesystems", "(", "ctx", "context", ".", "ProviderCallContext", ",", "args", "[", "]", "storage", ".", "FilesystemParams", ")", "(", "[", "]", "storage", ".", "CreateFilesystemsResult", ",", "error", ")", "{", "results", ":=", "make", "(", "[", "]", "storage", ".", "CreateFilesystemsResult", ",", "len", "(", "args", ")", ")", "\n", "for", "i", ",", "arg", ":=", "range", "args", "{", "filesystem", ",", "err", ":=", "s", ".", "createFilesystem", "(", "arg", ")", "\n", "if", "err", "!=", "nil", "{", "results", "[", "i", "]", ".", "Error", "=", "err", "\n", "continue", "\n", "}", "\n", "results", "[", "i", "]", ".", "Filesystem", "=", "filesystem", "\n", "}", "\n", "return", "results", ",", "nil", "\n", "}" ]
// CreateFilesystems is defined on the FilesystemSource interface.
[ "CreateFilesystems", "is", "defined", "on", "the", "FilesystemSource", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/rootfs.go#L147-L158
153,764
juju/juju
storage/provider/rootfs.go
AttachFilesystems
func (s *rootfsFilesystemSource) AttachFilesystems(ctx context.ProviderCallContext, args []storage.FilesystemAttachmentParams) ([]storage.AttachFilesystemsResult, error) { results := make([]storage.AttachFilesystemsResult, len(args)) for i, arg := range args { attachment, err := s.attachFilesystem(arg) if err != nil { results[i].Error = err continue } results[i].FilesystemAttachment = attachment } return results, nil }
go
func (s *rootfsFilesystemSource) AttachFilesystems(ctx context.ProviderCallContext, args []storage.FilesystemAttachmentParams) ([]storage.AttachFilesystemsResult, error) { results := make([]storage.AttachFilesystemsResult, len(args)) for i, arg := range args { attachment, err := s.attachFilesystem(arg) if err != nil { results[i].Error = err continue } results[i].FilesystemAttachment = attachment } return results, nil }
[ "func", "(", "s", "*", "rootfsFilesystemSource", ")", "AttachFilesystems", "(", "ctx", "context", ".", "ProviderCallContext", ",", "args", "[", "]", "storage", ".", "FilesystemAttachmentParams", ")", "(", "[", "]", "storage", ".", "AttachFilesystemsResult", ",", "error", ")", "{", "results", ":=", "make", "(", "[", "]", "storage", ".", "AttachFilesystemsResult", ",", "len", "(", "args", ")", ")", "\n", "for", "i", ",", "arg", ":=", "range", "args", "{", "attachment", ",", "err", ":=", "s", ".", "attachFilesystem", "(", "arg", ")", "\n", "if", "err", "!=", "nil", "{", "results", "[", "i", "]", ".", "Error", "=", "err", "\n", "continue", "\n", "}", "\n", "results", "[", "i", "]", ".", "FilesystemAttachment", "=", "attachment", "\n", "}", "\n", "return", "results", ",", "nil", "\n", "}" ]
// AttachFilesystems is defined on the FilesystemSource interface.
[ "AttachFilesystems", "is", "defined", "on", "the", "FilesystemSource", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/storage/provider/rootfs.go#L203-L214
153,765
juju/juju
worker/meterstatus/context.go
NewLimitedContext
func NewLimitedContext(unitName string) *limitedContext { // TODO(fwereade): 2016-03-17 lp:1558657 id := fmt.Sprintf("%s-%s-%d", unitName, "meter-status", rand.New(rand.NewSource(time.Now().Unix())).Int63()) return &limitedContext{unitName: unitName, id: id} }
go
func NewLimitedContext(unitName string) *limitedContext { // TODO(fwereade): 2016-03-17 lp:1558657 id := fmt.Sprintf("%s-%s-%d", unitName, "meter-status", rand.New(rand.NewSource(time.Now().Unix())).Int63()) return &limitedContext{unitName: unitName, id: id} }
[ "func", "NewLimitedContext", "(", "unitName", "string", ")", "*", "limitedContext", "{", "// TODO(fwereade): 2016-03-17 lp:1558657", "id", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "unitName", ",", "\"", "\"", ",", "rand", ".", "New", "(", "rand", ".", "NewSource", "(", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", ")", ")", ".", "Int63", "(", ")", ")", "\n", "return", "&", "limitedContext", "{", "unitName", ":", "unitName", ",", "id", ":", "id", "}", "\n", "}" ]
// NewLimitedContext creates a new context that implements just the bare minimum // of the hooks.Context interface.
[ "NewLimitedContext", "creates", "a", "new", "context", "that", "implements", "just", "the", "bare", "minimum", "of", "the", "hooks", ".", "Context", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/meterstatus/context.go#L28-L32
153,766
juju/juju
worker/meterstatus/context.go
SetEnvVars
func (ctx *limitedContext) SetEnvVars(vars map[string]string) { if ctx.env == nil { ctx.env = vars return } for key, val := range vars { ctx.env[key] = val } }
go
func (ctx *limitedContext) SetEnvVars(vars map[string]string) { if ctx.env == nil { ctx.env = vars return } for key, val := range vars { ctx.env[key] = val } }
[ "func", "(", "ctx", "*", "limitedContext", ")", "SetEnvVars", "(", "vars", "map", "[", "string", "]", "string", ")", "{", "if", "ctx", ".", "env", "==", "nil", "{", "ctx", ".", "env", "=", "vars", "\n", "return", "\n", "}", "\n", "for", "key", ",", "val", ":=", "range", "vars", "{", "ctx", ".", "env", "[", "key", "]", "=", "val", "\n", "}", "\n", "}" ]
// SetEnvVars sets additional environment variables to be exported by the context.
[ "SetEnvVars", "sets", "additional", "environment", "variables", "to", "be", "exported", "by", "the", "context", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/meterstatus/context.go#L50-L58
153,767
juju/juju
cloud/clouds.go
Contains
func (a AuthTypes) Contains(t AuthType) bool { for _, v := range a { if v == t { return true } } return false }
go
func (a AuthTypes) Contains(t AuthType) bool { for _, v := range a { if v == t { return true } } return false }
[ "func", "(", "a", "AuthTypes", ")", "Contains", "(", "t", "AuthType", ")", "bool", "{", "for", "_", ",", "v", ":=", "range", "a", "{", "if", "v", "==", "t", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// Contains checks if AuthType t is in a AuthTypes.
[ "Contains", "checks", "if", "AuthType", "t", "is", "in", "a", "AuthTypes", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L36-L43
153,768
juju/juju
cloud/clouds.go
RegionByName
func RegionByName(regions []Region, name string) (*Region, error) { for _, region := range regions { if !strings.EqualFold(region.Name, name) { continue } return &region, nil } return nil, errors.NewNotFound(nil, fmt.Sprintf( "region %q not found (expected one of %q)", name, RegionNames(regions), )) }
go
func RegionByName(regions []Region, name string) (*Region, error) { for _, region := range regions { if !strings.EqualFold(region.Name, name) { continue } return &region, nil } return nil, errors.NewNotFound(nil, fmt.Sprintf( "region %q not found (expected one of %q)", name, RegionNames(regions), )) }
[ "func", "RegionByName", "(", "regions", "[", "]", "Region", ",", "name", "string", ")", "(", "*", "Region", ",", "error", ")", "{", "for", "_", ",", "region", ":=", "range", "regions", "{", "if", "!", "strings", ".", "EqualFold", "(", "region", ".", "Name", ",", "name", ")", "{", "continue", "\n", "}", "\n", "return", "&", "region", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "errors", ".", "NewNotFound", "(", "nil", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ",", "RegionNames", "(", "regions", ")", ",", ")", ")", "\n", "}" ]
// RegionByName finds the region in the given slice with the // specified name, with case folding.
[ "RegionByName", "finds", "the", "region", "in", "the", "given", "slice", "with", "the", "specified", "name", "with", "case", "folding", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L282-L293
153,769
juju/juju
cloud/clouds.go
RegionNames
func RegionNames(regions []Region) []string { names := make([]string, len(regions)) for i, region := range regions { names[i] = region.Name } sort.Strings(names) return names }
go
func RegionNames(regions []Region) []string { names := make([]string, len(regions)) for i, region := range regions { names[i] = region.Name } sort.Strings(names) return names }
[ "func", "RegionNames", "(", "regions", "[", "]", "Region", ")", "[", "]", "string", "{", "names", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "regions", ")", ")", "\n", "for", "i", ",", "region", ":=", "range", "regions", "{", "names", "[", "i", "]", "=", "region", ".", "Name", "\n", "}", "\n", "sort", ".", "Strings", "(", "names", ")", "\n", "return", "names", "\n", "}" ]
// RegionNames returns a sorted list of the names of the given regions.
[ "RegionNames", "returns", "a", "sorted", "list", "of", "the", "names", "of", "the", "given", "regions", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L296-L303
153,770
juju/juju
cloud/clouds.go
PublicCloudMetadata
func PublicCloudMetadata(searchPath ...string) (result map[string]Cloud, fallbackUsed bool, err error) { for _, file := range searchPath { data, err := ioutil.ReadFile(file) if err != nil && os.IsNotExist(err) { continue } if err != nil { return nil, false, errors.Trace(err) } clouds, err := ParseCloudMetadata(data) if err != nil { return nil, false, errors.Trace(err) } return clouds, false, err } clouds, err := ParseCloudMetadata([]byte(fallbackPublicCloudInfo)) return clouds, true, err }
go
func PublicCloudMetadata(searchPath ...string) (result map[string]Cloud, fallbackUsed bool, err error) { for _, file := range searchPath { data, err := ioutil.ReadFile(file) if err != nil && os.IsNotExist(err) { continue } if err != nil { return nil, false, errors.Trace(err) } clouds, err := ParseCloudMetadata(data) if err != nil { return nil, false, errors.Trace(err) } return clouds, false, err } clouds, err := ParseCloudMetadata([]byte(fallbackPublicCloudInfo)) return clouds, true, err }
[ "func", "PublicCloudMetadata", "(", "searchPath", "...", "string", ")", "(", "result", "map", "[", "string", "]", "Cloud", ",", "fallbackUsed", "bool", ",", "err", "error", ")", "{", "for", "_", ",", "file", ":=", "range", "searchPath", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "file", ")", "\n", "if", "err", "!=", "nil", "&&", "os", ".", "IsNotExist", "(", "err", ")", "{", "continue", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "clouds", ",", "err", ":=", "ParseCloudMetadata", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "false", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "clouds", ",", "false", ",", "err", "\n", "}", "\n", "clouds", ",", "err", ":=", "ParseCloudMetadata", "(", "[", "]", "byte", "(", "fallbackPublicCloudInfo", ")", ")", "\n", "return", "clouds", ",", "true", ",", "err", "\n", "}" ]
// PublicCloudMetadata looks in searchPath for cloud metadata files and if none // are found, returns the fallback public cloud metadata.
[ "PublicCloudMetadata", "looks", "in", "searchPath", "for", "cloud", "metadata", "files", "and", "if", "none", "are", "found", "returns", "the", "fallback", "public", "cloud", "metadata", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L313-L330
153,771
juju/juju
cloud/clouds.go
ParseOneCloud
func ParseOneCloud(data []byte) (Cloud, error) { c := &cloud{} if err := yaml.Unmarshal(data, &c); err != nil { return Cloud{}, errors.Annotate(err, "cannot unmarshal yaml cloud metadata") } return cloudFromInternal(c), nil }
go
func ParseOneCloud(data []byte) (Cloud, error) { c := &cloud{} if err := yaml.Unmarshal(data, &c); err != nil { return Cloud{}, errors.Annotate(err, "cannot unmarshal yaml cloud metadata") } return cloudFromInternal(c), nil }
[ "func", "ParseOneCloud", "(", "data", "[", "]", "byte", ")", "(", "Cloud", ",", "error", ")", "{", "c", ":=", "&", "cloud", "{", "}", "\n", "if", "err", ":=", "yaml", ".", "Unmarshal", "(", "data", ",", "&", "c", ")", ";", "err", "!=", "nil", "{", "return", "Cloud", "{", "}", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "cloudFromInternal", "(", "c", ")", ",", "nil", "\n", "}" ]
// ParseOneCloud parses the given yaml bytes into a single Cloud metadata.
[ "ParseOneCloud", "parses", "the", "given", "yaml", "bytes", "into", "a", "single", "Cloud", "metadata", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L333-L339
153,772
juju/juju
cloud/clouds.go
ParseCloudMetadata
func ParseCloudMetadata(data []byte) (map[string]Cloud, error) { var metadata cloudSet if err := yaml.Unmarshal(data, &metadata); err != nil { return nil, errors.Annotate(err, "cannot unmarshal yaml cloud metadata") } // Translate to the exported type. For each cloud, we store // the first region for the cloud as its default region. clouds := make(map[string]Cloud) for name, cloud := range metadata.Clouds { details := cloudFromInternal(cloud) details.Name = name if details.Description == "" { var ok bool if details.Description, ok = defaultCloudDescription[name]; !ok { details.Description = defaultCloudDescription[cloud.Type] } } clouds[name] = details } return clouds, nil }
go
func ParseCloudMetadata(data []byte) (map[string]Cloud, error) { var metadata cloudSet if err := yaml.Unmarshal(data, &metadata); err != nil { return nil, errors.Annotate(err, "cannot unmarshal yaml cloud metadata") } // Translate to the exported type. For each cloud, we store // the first region for the cloud as its default region. clouds := make(map[string]Cloud) for name, cloud := range metadata.Clouds { details := cloudFromInternal(cloud) details.Name = name if details.Description == "" { var ok bool if details.Description, ok = defaultCloudDescription[name]; !ok { details.Description = defaultCloudDescription[cloud.Type] } } clouds[name] = details } return clouds, nil }
[ "func", "ParseCloudMetadata", "(", "data", "[", "]", "byte", ")", "(", "map", "[", "string", "]", "Cloud", ",", "error", ")", "{", "var", "metadata", "cloudSet", "\n", "if", "err", ":=", "yaml", ".", "Unmarshal", "(", "data", ",", "&", "metadata", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Translate to the exported type. For each cloud, we store", "// the first region for the cloud as its default region.", "clouds", ":=", "make", "(", "map", "[", "string", "]", "Cloud", ")", "\n", "for", "name", ",", "cloud", ":=", "range", "metadata", ".", "Clouds", "{", "details", ":=", "cloudFromInternal", "(", "cloud", ")", "\n", "details", ".", "Name", "=", "name", "\n", "if", "details", ".", "Description", "==", "\"", "\"", "{", "var", "ok", "bool", "\n", "if", "details", ".", "Description", ",", "ok", "=", "defaultCloudDescription", "[", "name", "]", ";", "!", "ok", "{", "details", ".", "Description", "=", "defaultCloudDescription", "[", "cloud", ".", "Type", "]", "\n", "}", "\n", "}", "\n", "clouds", "[", "name", "]", "=", "details", "\n", "}", "\n", "return", "clouds", ",", "nil", "\n", "}" ]
// ParseCloudMetadata parses the given yaml bytes into Clouds metadata.
[ "ParseCloudMetadata", "parses", "the", "given", "yaml", "bytes", "into", "Clouds", "metadata", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L342-L363
153,773
juju/juju
cloud/clouds.go
WritePublicCloudMetadata
func WritePublicCloudMetadata(cloudsMap map[string]Cloud) error { data, err := marshalCloudMetadata(cloudsMap) if err != nil { return errors.Trace(err) } return utils.AtomicWriteFile(JujuPublicCloudsPath(), data, 0600) }
go
func WritePublicCloudMetadata(cloudsMap map[string]Cloud) error { data, err := marshalCloudMetadata(cloudsMap) if err != nil { return errors.Trace(err) } return utils.AtomicWriteFile(JujuPublicCloudsPath(), data, 0600) }
[ "func", "WritePublicCloudMetadata", "(", "cloudsMap", "map", "[", "string", "]", "Cloud", ")", "error", "{", "data", ",", "err", ":=", "marshalCloudMetadata", "(", "cloudsMap", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "utils", ".", "AtomicWriteFile", "(", "JujuPublicCloudsPath", "(", ")", ",", "data", ",", "0600", ")", "\n", "}" ]
// WritePublicCloudMetadata marshals to YAML and writes the cloud metadata // to the public cloud file.
[ "WritePublicCloudMetadata", "marshals", "to", "YAML", "and", "writes", "the", "cloud", "metadata", "to", "the", "public", "cloud", "file", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L390-L396
153,774
juju/juju
cloud/clouds.go
IsSameCloudMetadata
func IsSameCloudMetadata(meta1, meta2 map[string]Cloud) (bool, error) { // The easiest approach is to simply marshall to YAML and compare. yaml1, err := marshalCloudMetadata(meta1) if err != nil { return false, err } yaml2, err := marshalCloudMetadata(meta2) if err != nil { return false, err } return string(yaml1) == string(yaml2), nil }
go
func IsSameCloudMetadata(meta1, meta2 map[string]Cloud) (bool, error) { // The easiest approach is to simply marshall to YAML and compare. yaml1, err := marshalCloudMetadata(meta1) if err != nil { return false, err } yaml2, err := marshalCloudMetadata(meta2) if err != nil { return false, err } return string(yaml1) == string(yaml2), nil }
[ "func", "IsSameCloudMetadata", "(", "meta1", ",", "meta2", "map", "[", "string", "]", "Cloud", ")", "(", "bool", ",", "error", ")", "{", "// The easiest approach is to simply marshall to YAML and compare.", "yaml1", ",", "err", ":=", "marshalCloudMetadata", "(", "meta1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "yaml2", ",", "err", ":=", "marshalCloudMetadata", "(", "meta2", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "string", "(", "yaml1", ")", "==", "string", "(", "yaml2", ")", ",", "nil", "\n", "}" ]
// IsSameCloudMetadata returns true if both meta and meta2 contain the // same cloud metadata.
[ "IsSameCloudMetadata", "returns", "true", "if", "both", "meta", "and", "meta2", "contain", "the", "same", "cloud", "metadata", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L400-L411
153,775
juju/juju
cloud/clouds.go
marshalCloudMetadata
func marshalCloudMetadata(cloudsMap map[string]Cloud) ([]byte, error) { clouds := cloudSet{make(map[string]*cloud)} for name, metadata := range cloudsMap { clouds.Clouds[name] = cloudToInternal(metadata, false) } data, err := yaml.Marshal(clouds) if err != nil { return nil, errors.Annotate(err, "cannot marshal cloud metadata") } return data, nil }
go
func marshalCloudMetadata(cloudsMap map[string]Cloud) ([]byte, error) { clouds := cloudSet{make(map[string]*cloud)} for name, metadata := range cloudsMap { clouds.Clouds[name] = cloudToInternal(metadata, false) } data, err := yaml.Marshal(clouds) if err != nil { return nil, errors.Annotate(err, "cannot marshal cloud metadata") } return data, nil }
[ "func", "marshalCloudMetadata", "(", "cloudsMap", "map", "[", "string", "]", "Cloud", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "clouds", ":=", "cloudSet", "{", "make", "(", "map", "[", "string", "]", "*", "cloud", ")", "}", "\n", "for", "name", ",", "metadata", ":=", "range", "cloudsMap", "{", "clouds", ".", "Clouds", "[", "name", "]", "=", "cloudToInternal", "(", "metadata", ",", "false", ")", "\n", "}", "\n", "data", ",", "err", ":=", "yaml", ".", "Marshal", "(", "clouds", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "data", ",", "nil", "\n", "}" ]
// marshalCloudMetadata marshals the given clouds to YAML.
[ "marshalCloudMetadata", "marshals", "the", "given", "clouds", "to", "YAML", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L414-L424
153,776
juju/juju
cloud/clouds.go
MarshalCloud
func MarshalCloud(cloud Cloud) ([]byte, error) { return yaml.Marshal(cloudToInternal(cloud, true)) }
go
func MarshalCloud(cloud Cloud) ([]byte, error) { return yaml.Marshal(cloudToInternal(cloud, true)) }
[ "func", "MarshalCloud", "(", "cloud", "Cloud", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "return", "yaml", ".", "Marshal", "(", "cloudToInternal", "(", "cloud", ",", "true", ")", ")", "\n", "}" ]
// MarshalCloud marshals a Cloud to an opaque byte array.
[ "MarshalCloud", "marshals", "a", "Cloud", "to", "an", "opaque", "byte", "array", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L427-L429
153,777
juju/juju
cloud/clouds.go
UnmarshalCloud
func UnmarshalCloud(in []byte) (Cloud, error) { var internal cloud if err := yaml.Unmarshal(in, &internal); err != nil { return Cloud{}, errors.Annotate(err, "cannot unmarshal yaml cloud metadata") } return cloudFromInternal(&internal), nil }
go
func UnmarshalCloud(in []byte) (Cloud, error) { var internal cloud if err := yaml.Unmarshal(in, &internal); err != nil { return Cloud{}, errors.Annotate(err, "cannot unmarshal yaml cloud metadata") } return cloudFromInternal(&internal), nil }
[ "func", "UnmarshalCloud", "(", "in", "[", "]", "byte", ")", "(", "Cloud", ",", "error", ")", "{", "var", "internal", "cloud", "\n", "if", "err", ":=", "yaml", ".", "Unmarshal", "(", "in", ",", "&", "internal", ")", ";", "err", "!=", "nil", "{", "return", "Cloud", "{", "}", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "cloudFromInternal", "(", "&", "internal", ")", ",", "nil", "\n", "}" ]
// UnmarshalCloud unmarshals a Cloud from a byte array produced by MarshalCloud.
[ "UnmarshalCloud", "unmarshals", "a", "Cloud", "from", "a", "byte", "array", "produced", "by", "MarshalCloud", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L432-L438
153,778
juju/juju
cloud/clouds.go
RegisterStructTags
func RegisterStructTags(vals ...interface{}) { tags := mkTags(vals...) for k, v := range tags { tagsForType[k] = v } }
go
func RegisterStructTags(vals ...interface{}) { tags := mkTags(vals...) for k, v := range tags { tagsForType[k] = v } }
[ "func", "RegisterStructTags", "(", "vals", "...", "interface", "{", "}", ")", "{", "tags", ":=", "mkTags", "(", "vals", "...", ")", "\n", "for", "k", ",", "v", ":=", "range", "tags", "{", "tagsForType", "[", "k", "]", "=", "v", "\n", "}", "\n", "}" ]
// RegisterStructTags ensures the yaml tags for the given structs are able to be used // when parsing cloud metadata.
[ "RegisterStructTags", "ensures", "the", "yaml", "tags", "for", "the", "given", "structs", "are", "able", "to", "be", "used", "when", "parsing", "cloud", "metadata", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L540-L545
153,779
juju/juju
cloud/clouds.go
yamlTags
func yamlTags(t reflect.Type) map[string]int { if t.Kind() != reflect.Struct { panic(errors.Errorf("cannot get yaml tags on type %s", t)) } tags := make(map[string]int) for i := 0; i < t.NumField(); i++ { f := t.Field(i) if f.Type != reflect.TypeOf("") { continue } if tag := f.Tag.Get("yaml"); tag != "" { if i := strings.Index(tag, ","); i >= 0 { tag = tag[0:i] } if tag == "-" { continue } if tag != "" { f.Name = tag } } tags[f.Name] = i } return tags }
go
func yamlTags(t reflect.Type) map[string]int { if t.Kind() != reflect.Struct { panic(errors.Errorf("cannot get yaml tags on type %s", t)) } tags := make(map[string]int) for i := 0; i < t.NumField(); i++ { f := t.Field(i) if f.Type != reflect.TypeOf("") { continue } if tag := f.Tag.Get("yaml"); tag != "" { if i := strings.Index(tag, ","); i >= 0 { tag = tag[0:i] } if tag == "-" { continue } if tag != "" { f.Name = tag } } tags[f.Name] = i } return tags }
[ "func", "yamlTags", "(", "t", "reflect", ".", "Type", ")", "map", "[", "string", "]", "int", "{", "if", "t", ".", "Kind", "(", ")", "!=", "reflect", ".", "Struct", "{", "panic", "(", "errors", ".", "Errorf", "(", "\"", "\"", ",", "t", ")", ")", "\n", "}", "\n", "tags", ":=", "make", "(", "map", "[", "string", "]", "int", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "t", ".", "NumField", "(", ")", ";", "i", "++", "{", "f", ":=", "t", ".", "Field", "(", "i", ")", "\n", "if", "f", ".", "Type", "!=", "reflect", ".", "TypeOf", "(", "\"", "\"", ")", "{", "continue", "\n", "}", "\n", "if", "tag", ":=", "f", ".", "Tag", ".", "Get", "(", "\"", "\"", ")", ";", "tag", "!=", "\"", "\"", "{", "if", "i", ":=", "strings", ".", "Index", "(", "tag", ",", "\"", "\"", ")", ";", "i", ">=", "0", "{", "tag", "=", "tag", "[", "0", ":", "i", "]", "\n", "}", "\n", "if", "tag", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "if", "tag", "!=", "\"", "\"", "{", "f", ".", "Name", "=", "tag", "\n", "}", "\n", "}", "\n", "tags", "[", "f", ".", "Name", "]", "=", "i", "\n", "}", "\n", "return", "tags", "\n", "}" ]
// yamlTags returns a map from yaml tag to the field index for the string fields in the given type.
[ "yamlTags", "returns", "a", "map", "from", "yaml", "tag", "to", "the", "field", "index", "for", "the", "string", "fields", "in", "the", "given", "type", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L561-L585
153,780
juju/juju
cloud/clouds.go
inherit
func inherit(dst, src interface{}) { for tag := range tags(dst) { setFieldByTag(dst, tag, fieldByTag(src, tag), false) } }
go
func inherit(dst, src interface{}) { for tag := range tags(dst) { setFieldByTag(dst, tag, fieldByTag(src, tag), false) } }
[ "func", "inherit", "(", "dst", ",", "src", "interface", "{", "}", ")", "{", "for", "tag", ":=", "range", "tags", "(", "dst", ")", "{", "setFieldByTag", "(", "dst", ",", "tag", ",", "fieldByTag", "(", "src", ",", "tag", ")", ",", "false", ")", "\n", "}", "\n", "}" ]
// inherit sets any blank fields in dst to their equivalent values in fields in src that have matching json tags. // The dst parameter must be a pointer to a struct.
[ "inherit", "sets", "any", "blank", "fields", "in", "dst", "to", "their", "equivalent", "values", "in", "fields", "in", "src", "that", "have", "matching", "json", "tags", ".", "The", "dst", "parameter", "must", "be", "a", "pointer", "to", "a", "struct", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L589-L593
153,781
juju/juju
cloud/clouds.go
tags
func tags(x interface{}) map[string]int { t := reflect.TypeOf(x) if t.Kind() == reflect.Ptr { t = t.Elem() } if t.Kind() != reflect.Struct { panic(errors.Errorf("expected struct, not %s", t)) } if tagm := tagsForType[t]; tagm != nil { return tagm } panic(errors.Errorf("%s not found in type table", t)) }
go
func tags(x interface{}) map[string]int { t := reflect.TypeOf(x) if t.Kind() == reflect.Ptr { t = t.Elem() } if t.Kind() != reflect.Struct { panic(errors.Errorf("expected struct, not %s", t)) } if tagm := tagsForType[t]; tagm != nil { return tagm } panic(errors.Errorf("%s not found in type table", t)) }
[ "func", "tags", "(", "x", "interface", "{", "}", ")", "map", "[", "string", "]", "int", "{", "t", ":=", "reflect", ".", "TypeOf", "(", "x", ")", "\n", "if", "t", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "t", "=", "t", ".", "Elem", "(", ")", "\n", "}", "\n", "if", "t", ".", "Kind", "(", ")", "!=", "reflect", ".", "Struct", "{", "panic", "(", "errors", ".", "Errorf", "(", "\"", "\"", ",", "t", ")", ")", "\n", "}", "\n\n", "if", "tagm", ":=", "tagsForType", "[", "t", "]", ";", "tagm", "!=", "nil", "{", "return", "tagm", "\n", "}", "\n", "panic", "(", "errors", ".", "Errorf", "(", "\"", "\"", ",", "t", ")", ")", "\n", "}" ]
// tags returns the field offsets for the JSON tags defined by the given value, which must be // a struct or a pointer to a struct.
[ "tags", "returns", "the", "field", "offsets", "for", "the", "JSON", "tags", "defined", "by", "the", "given", "value", "which", "must", "be", "a", "struct", "or", "a", "pointer", "to", "a", "struct", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L597-L610
153,782
juju/juju
cloud/clouds.go
fieldByTag
func fieldByTag(x interface{}, tag string) string { tagm := tags(x) v := reflect.ValueOf(x) if v.Kind() == reflect.Ptr { v = v.Elem() } if i, ok := tagm[tag]; ok { return v.Field(i).Interface().(string) } return "" }
go
func fieldByTag(x interface{}, tag string) string { tagm := tags(x) v := reflect.ValueOf(x) if v.Kind() == reflect.Ptr { v = v.Elem() } if i, ok := tagm[tag]; ok { return v.Field(i).Interface().(string) } return "" }
[ "func", "fieldByTag", "(", "x", "interface", "{", "}", ",", "tag", "string", ")", "string", "{", "tagm", ":=", "tags", "(", "x", ")", "\n", "v", ":=", "reflect", ".", "ValueOf", "(", "x", ")", "\n", "if", "v", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "{", "v", "=", "v", ".", "Elem", "(", ")", "\n", "}", "\n", "if", "i", ",", "ok", ":=", "tagm", "[", "tag", "]", ";", "ok", "{", "return", "v", ".", "Field", "(", "i", ")", ".", "Interface", "(", ")", ".", "(", "string", ")", "\n", "}", "\n", "return", "\"", "\"", "\n", "}" ]
// fieldByTag returns the value for the field in x with the given JSON tag, or "" if there is no such field.
[ "fieldByTag", "returns", "the", "value", "for", "the", "field", "in", "x", "with", "the", "given", "JSON", "tag", "or", "if", "there", "is", "no", "such", "field", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L613-L623
153,783
juju/juju
cloud/clouds.go
setFieldByTag
func setFieldByTag(x interface{}, tag, val string, override bool) { i, ok := tags(x)[tag] if !ok { return } v := reflect.ValueOf(x).Elem() f := v.Field(i) if override || f.Interface().(string) == "" { f.Set(reflect.ValueOf(val)) } }
go
func setFieldByTag(x interface{}, tag, val string, override bool) { i, ok := tags(x)[tag] if !ok { return } v := reflect.ValueOf(x).Elem() f := v.Field(i) if override || f.Interface().(string) == "" { f.Set(reflect.ValueOf(val)) } }
[ "func", "setFieldByTag", "(", "x", "interface", "{", "}", ",", "tag", ",", "val", "string", ",", "override", "bool", ")", "{", "i", ",", "ok", ":=", "tags", "(", "x", ")", "[", "tag", "]", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n", "v", ":=", "reflect", ".", "ValueOf", "(", "x", ")", ".", "Elem", "(", ")", "\n", "f", ":=", "v", ".", "Field", "(", "i", ")", "\n", "if", "override", "||", "f", ".", "Interface", "(", ")", ".", "(", "string", ")", "==", "\"", "\"", "{", "f", ".", "Set", "(", "reflect", ".", "ValueOf", "(", "val", ")", ")", "\n", "}", "\n", "}" ]
// setFieldByTag sets the value for the field in x with the given JSON tag to val. // The override parameter specifies whether the value will be set even if the original value is non-empty.
[ "setFieldByTag", "sets", "the", "value", "for", "the", "field", "in", "x", "with", "the", "given", "JSON", "tag", "to", "val", ".", "The", "override", "parameter", "specifies", "whether", "the", "value", "will", "be", "set", "even", "if", "the", "original", "value", "is", "non", "-", "empty", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/clouds.go#L627-L637
153,784
juju/juju
api/cleaner/cleaner.go
NewAPI
func NewAPI(caller base.APICaller) *API { facadeCaller := base.NewFacadeCaller(caller, cleanerFacade) return &API{facade: facadeCaller} }
go
func NewAPI(caller base.APICaller) *API { facadeCaller := base.NewFacadeCaller(caller, cleanerFacade) return &API{facade: facadeCaller} }
[ "func", "NewAPI", "(", "caller", "base", ".", "APICaller", ")", "*", "API", "{", "facadeCaller", ":=", "base", ".", "NewFacadeCaller", "(", "caller", ",", "cleanerFacade", ")", "\n", "return", "&", "API", "{", "facade", ":", "facadeCaller", "}", "\n", "}" ]
// NewAPI creates a new client-side Cleaner facade.
[ "NewAPI", "creates", "a", "new", "client", "-", "side", "Cleaner", "facade", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/cleaner/cleaner.go#L21-L24
153,785
juju/juju
api/cleaner/cleaner.go
WatchCleanups
func (api *API) WatchCleanups() (watcher.NotifyWatcher, error) { var result params.NotifyWatchResult err := api.facade.FacadeCall("WatchCleanups", nil, &result) if err != nil { return nil, err } if err := result.Error; err != nil { return nil, result.Error } w := apiwatcher.NewNotifyWatcher(api.facade.RawAPICaller(), result) return w, nil }
go
func (api *API) WatchCleanups() (watcher.NotifyWatcher, error) { var result params.NotifyWatchResult err := api.facade.FacadeCall("WatchCleanups", nil, &result) if err != nil { return nil, err } if err := result.Error; err != nil { return nil, result.Error } w := apiwatcher.NewNotifyWatcher(api.facade.RawAPICaller(), result) return w, nil }
[ "func", "(", "api", "*", "API", ")", "WatchCleanups", "(", ")", "(", "watcher", ".", "NotifyWatcher", ",", "error", ")", "{", "var", "result", "params", ".", "NotifyWatchResult", "\n", "err", ":=", "api", ".", "facade", ".", "FacadeCall", "(", "\"", "\"", ",", "nil", ",", "&", "result", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "result", ".", "Error", ";", "err", "!=", "nil", "{", "return", "nil", ",", "result", ".", "Error", "\n", "}", "\n", "w", ":=", "apiwatcher", ".", "NewNotifyWatcher", "(", "api", ".", "facade", ".", "RawAPICaller", "(", ")", ",", "result", ")", "\n", "return", "w", ",", "nil", "\n", "}" ]
// WatchCleanups calls the server-side WatchCleanups method.
[ "WatchCleanups", "calls", "the", "server", "-", "side", "WatchCleanups", "method", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/cleaner/cleaner.go#L32-L43
153,786
juju/juju
cloud/credentials.go
MarshalYAML
func (c Credential) MarshalYAML() (interface{}, error) { return credentialInternal{c.authType, c.attributes}, nil }
go
func (c Credential) MarshalYAML() (interface{}, error) { return credentialInternal{c.authType, c.attributes}, nil }
[ "func", "(", "c", "Credential", ")", "MarshalYAML", "(", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "return", "credentialInternal", "{", "c", ".", "authType", ",", "c", ".", "attributes", "}", ",", "nil", "\n", "}" ]
// MarshalYAML implements the yaml.Marshaler interface.
[ "MarshalYAML", "implements", "the", "yaml", ".", "Marshaler", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/credentials.go#L76-L78
153,787
juju/juju
cloud/credentials.go
UnmarshalYAML
func (c *Credential) UnmarshalYAML(unmarshal func(interface{}) error) error { var internal credentialInternal if err := unmarshal(&internal); err != nil { return err } *c = Credential{authType: internal.AuthType, attributes: internal.Attributes} return nil }
go
func (c *Credential) UnmarshalYAML(unmarshal func(interface{}) error) error { var internal credentialInternal if err := unmarshal(&internal); err != nil { return err } *c = Credential{authType: internal.AuthType, attributes: internal.Attributes} return nil }
[ "func", "(", "c", "*", "Credential", ")", "UnmarshalYAML", "(", "unmarshal", "func", "(", "interface", "{", "}", ")", "error", ")", "error", "{", "var", "internal", "credentialInternal", "\n", "if", "err", ":=", "unmarshal", "(", "&", "internal", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "c", "=", "Credential", "{", "authType", ":", "internal", ".", "AuthType", ",", "attributes", ":", "internal", ".", "Attributes", "}", "\n", "return", "nil", "\n", "}" ]
// UnmarshalYAML implements the yaml.Marshaler interface.
[ "UnmarshalYAML", "implements", "the", "yaml", ".", "Marshaler", "interface", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/credentials.go#L81-L88
153,788
juju/juju
cloud/credentials.go
NewCredential
func NewCredential(authType AuthType, attributes map[string]string) Credential { return Credential{authType: authType, attributes: copyStringMap(attributes)} }
go
func NewCredential(authType AuthType, attributes map[string]string) Credential { return Credential{authType: authType, attributes: copyStringMap(attributes)} }
[ "func", "NewCredential", "(", "authType", "AuthType", ",", "attributes", "map", "[", "string", "]", "string", ")", "Credential", "{", "return", "Credential", "{", "authType", ":", "authType", ",", "attributes", ":", "copyStringMap", "(", "attributes", ")", "}", "\n", "}" ]
// NewCredential returns a new, immutable, Credential with the supplied // auth-type and attributes.
[ "NewCredential", "returns", "a", "new", "immutable", "Credential", "with", "the", "supplied", "auth", "-", "type", "and", "attributes", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/credentials.go#L92-L94
153,789
juju/juju
cloud/credentials.go
NewNamedCredential
func NewNamedCredential(name string, authType AuthType, attributes map[string]string, revoked bool) Credential { return Credential{ Label: name, authType: authType, attributes: copyStringMap(attributes), Revoked: revoked, } }
go
func NewNamedCredential(name string, authType AuthType, attributes map[string]string, revoked bool) Credential { return Credential{ Label: name, authType: authType, attributes: copyStringMap(attributes), Revoked: revoked, } }
[ "func", "NewNamedCredential", "(", "name", "string", ",", "authType", "AuthType", ",", "attributes", "map", "[", "string", "]", "string", ",", "revoked", "bool", ")", "Credential", "{", "return", "Credential", "{", "Label", ":", "name", ",", "authType", ":", "authType", ",", "attributes", ":", "copyStringMap", "(", "attributes", ")", ",", "Revoked", ":", "revoked", ",", "}", "\n", "}" ]
// NewNamedCredential returns an immutable Credential with the supplied properties.
[ "NewNamedCredential", "returns", "an", "immutable", "Credential", "with", "the", "supplied", "properties", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/credentials.go#L97-L104
153,790
juju/juju
cloud/credentials.go
Attribute
func (s CredentialSchema) Attribute(name string) (*CredentialAttr, bool) { for _, value := range s { if value.Name == name { result := value.CredentialAttr return &result, true } } return nil, false }
go
func (s CredentialSchema) Attribute(name string) (*CredentialAttr, bool) { for _, value := range s { if value.Name == name { result := value.CredentialAttr return &result, true } } return nil, false }
[ "func", "(", "s", "CredentialSchema", ")", "Attribute", "(", "name", "string", ")", "(", "*", "CredentialAttr", ",", "bool", ")", "{", "for", "_", ",", "value", ":=", "range", "s", "{", "if", "value", ".", "Name", "==", "name", "{", "result", ":=", "value", ".", "CredentialAttr", "\n", "return", "&", "result", ",", "true", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// Attribute returns the named CredentialAttr value.
[ "Attribute", "returns", "the", "named", "CredentialAttr", "value", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/credentials.go#L132-L140
153,791
juju/juju
cloud/credentials.go
FinalizeCredential
func FinalizeCredential( credential Credential, schemas map[AuthType]CredentialSchema, readFile func(string) ([]byte, error), ) (*Credential, error) { schema, ok := schemas[credential.authType] if !ok { return nil, errors.NotSupportedf("auth-type %q", credential.authType) } attrs, err := schema.Finalize(credential.attributes, readFile) if err != nil { return nil, errors.Trace(err) } return &Credential{authType: credential.authType, attributes: attrs}, nil }
go
func FinalizeCredential( credential Credential, schemas map[AuthType]CredentialSchema, readFile func(string) ([]byte, error), ) (*Credential, error) { schema, ok := schemas[credential.authType] if !ok { return nil, errors.NotSupportedf("auth-type %q", credential.authType) } attrs, err := schema.Finalize(credential.attributes, readFile) if err != nil { return nil, errors.Trace(err) } return &Credential{authType: credential.authType, attributes: attrs}, nil }
[ "func", "FinalizeCredential", "(", "credential", "Credential", ",", "schemas", "map", "[", "AuthType", "]", "CredentialSchema", ",", "readFile", "func", "(", "string", ")", "(", "[", "]", "byte", ",", "error", ")", ",", ")", "(", "*", "Credential", ",", "error", ")", "{", "schema", ",", "ok", ":=", "schemas", "[", "credential", ".", "authType", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "NotSupportedf", "(", "\"", "\"", ",", "credential", ".", "authType", ")", "\n", "}", "\n", "attrs", ",", "err", ":=", "schema", ".", "Finalize", "(", "credential", ".", "attributes", ",", "readFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "return", "&", "Credential", "{", "authType", ":", "credential", ".", "authType", ",", "attributes", ":", "attrs", "}", ",", "nil", "\n", "}" ]
// FinalizeCredential finalizes a credential by matching it with one of the // provided credential schemas, and reading any file attributes into their // corresponding non-file attributes. This will also validate the credential. // // If there is no schema with the matching auth-type, an error satisfying // errors.IsNotSupported will be returned.
[ "FinalizeCredential", "finalizes", "a", "credential", "by", "matching", "it", "with", "one", "of", "the", "provided", "credential", "schemas", "and", "reading", "any", "file", "attributes", "into", "their", "corresponding", "non", "-", "file", "attributes", ".", "This", "will", "also", "validate", "the", "credential", ".", "If", "there", "is", "no", "schema", "with", "the", "matching", "auth", "-", "type", "an", "error", "satisfying", "errors", ".", "IsNotSupported", "will", "be", "returned", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/credentials.go#L148-L162
153,792
juju/juju
cloud/credentials.go
Finalize
func (s CredentialSchema) Finalize( attrs map[string]string, readFile func(string) ([]byte, error), ) (map[string]string, error) { checker, err := s.schemaChecker() if err != nil { return nil, errors.Trace(err) } m := make(map[string]interface{}) for k, v := range attrs { m[k] = v } result, err := checker.Coerce(m, nil) if err != nil { return nil, errors.Trace(err) } resultMap := result.(map[string]interface{}) newAttrs := make(map[string]string) // Construct the final credential attributes map, reading values from files as necessary. for _, field := range s { if field.FileAttr != "" { if err := s.processFileAttrValue(field, resultMap, newAttrs, readFile); err != nil { return nil, errors.Trace(err) } continue } name := field.Name if field.FilePath { pathValue, ok := resultMap[name] if ok && pathValue != "" { absPath, err := ValidateFileAttrValue(pathValue.(string)) if err != nil { return nil, errors.Trace(err) } data, err := readFile(absPath) if err != nil { return nil, errors.Annotatef(err, "reading file for %q", name) } if len(data) == 0 { return nil, errors.NotValidf("empty file for %q", name) } newAttrs[name] = string(data) continue } } if val, ok := resultMap[name]; ok { newAttrs[name] = val.(string) } } return newAttrs, nil }
go
func (s CredentialSchema) Finalize( attrs map[string]string, readFile func(string) ([]byte, error), ) (map[string]string, error) { checker, err := s.schemaChecker() if err != nil { return nil, errors.Trace(err) } m := make(map[string]interface{}) for k, v := range attrs { m[k] = v } result, err := checker.Coerce(m, nil) if err != nil { return nil, errors.Trace(err) } resultMap := result.(map[string]interface{}) newAttrs := make(map[string]string) // Construct the final credential attributes map, reading values from files as necessary. for _, field := range s { if field.FileAttr != "" { if err := s.processFileAttrValue(field, resultMap, newAttrs, readFile); err != nil { return nil, errors.Trace(err) } continue } name := field.Name if field.FilePath { pathValue, ok := resultMap[name] if ok && pathValue != "" { absPath, err := ValidateFileAttrValue(pathValue.(string)) if err != nil { return nil, errors.Trace(err) } data, err := readFile(absPath) if err != nil { return nil, errors.Annotatef(err, "reading file for %q", name) } if len(data) == 0 { return nil, errors.NotValidf("empty file for %q", name) } newAttrs[name] = string(data) continue } } if val, ok := resultMap[name]; ok { newAttrs[name] = val.(string) } } return newAttrs, nil }
[ "func", "(", "s", "CredentialSchema", ")", "Finalize", "(", "attrs", "map", "[", "string", "]", "string", ",", "readFile", "func", "(", "string", ")", "(", "[", "]", "byte", ",", "error", ")", ",", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "checker", ",", "err", ":=", "s", ".", "schemaChecker", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "m", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "k", ",", "v", ":=", "range", "attrs", "{", "m", "[", "k", "]", "=", "v", "\n", "}", "\n", "result", ",", "err", ":=", "checker", ".", "Coerce", "(", "m", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n\n", "resultMap", ":=", "result", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "newAttrs", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n\n", "// Construct the final credential attributes map, reading values from files as necessary.", "for", "_", ",", "field", ":=", "range", "s", "{", "if", "field", ".", "FileAttr", "!=", "\"", "\"", "{", "if", "err", ":=", "s", ".", "processFileAttrValue", "(", "field", ",", "resultMap", ",", "newAttrs", ",", "readFile", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "continue", "\n", "}", "\n", "name", ":=", "field", ".", "Name", "\n", "if", "field", ".", "FilePath", "{", "pathValue", ",", "ok", ":=", "resultMap", "[", "name", "]", "\n", "if", "ok", "&&", "pathValue", "!=", "\"", "\"", "{", "absPath", ",", "err", ":=", "ValidateFileAttrValue", "(", "pathValue", ".", "(", "string", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "data", ",", "err", ":=", "readFile", "(", "absPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotatef", "(", "err", ",", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "if", "len", "(", "data", ")", "==", "0", "{", "return", "nil", ",", "errors", ".", "NotValidf", "(", "\"", "\"", ",", "name", ")", "\n", "}", "\n", "newAttrs", "[", "name", "]", "=", "string", "(", "data", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "if", "val", ",", "ok", ":=", "resultMap", "[", "name", "]", ";", "ok", "{", "newAttrs", "[", "name", "]", "=", "val", ".", "(", "string", ")", "\n", "}", "\n", "}", "\n", "return", "newAttrs", ",", "nil", "\n", "}" ]
// Finalize finalizes the given credential attributes against the credential // schema. If the attributes are invalid, Finalize will return an error. // // An updated attribute map will be returned, having any file attributes // deleted, and replaced by their non-file counterparts with the values set // to the contents of the files.
[ "Finalize", "finalizes", "the", "given", "credential", "attributes", "against", "the", "credential", "schema", ".", "If", "the", "attributes", "are", "invalid", "Finalize", "will", "return", "an", "error", ".", "An", "updated", "attribute", "map", "will", "be", "returned", "having", "any", "file", "attributes", "deleted", "and", "replaced", "by", "their", "non", "-", "file", "counterparts", "with", "the", "values", "set", "to", "the", "contents", "of", "the", "files", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/credentials.go#L170-L222
153,793
juju/juju
cloud/credentials.go
ValidateFileAttrValue
func ValidateFileAttrValue(path string) (string, error) { absPath, err := utils.ExpandPath(path) if err != nil { return "", err } info, err := os.Stat(absPath) if err != nil { return "", errors.Errorf("invalid file path: %s", absPath) } if info.IsDir() { return "", errors.Errorf("file path must be a file: %s", absPath) } return absPath, nil }
go
func ValidateFileAttrValue(path string) (string, error) { absPath, err := utils.ExpandPath(path) if err != nil { return "", err } info, err := os.Stat(absPath) if err != nil { return "", errors.Errorf("invalid file path: %s", absPath) } if info.IsDir() { return "", errors.Errorf("file path must be a file: %s", absPath) } return absPath, nil }
[ "func", "ValidateFileAttrValue", "(", "path", "string", ")", "(", "string", ",", "error", ")", "{", "absPath", ",", "err", ":=", "utils", ".", "ExpandPath", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "info", ",", "err", ":=", "os", ".", "Stat", "(", "absPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "absPath", ")", "\n", "}", "\n", "if", "info", ".", "IsDir", "(", ")", "{", "return", "\"", "\"", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "absPath", ")", "\n", "}", "\n", "return", "absPath", ",", "nil", "\n", "}" ]
// ValidateFileAttrValue returns the normalised file path, so // long as the specified path is valid and not a directory.
[ "ValidateFileAttrValue", "returns", "the", "normalised", "file", "path", "so", "long", "as", "the", "specified", "path", "is", "valid", "and", "not", "a", "directory", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/credentials.go#L226-L239
153,794
juju/juju
cloud/credentials.go
ParseCredentials
func ParseCredentials(data []byte) (map[string]CloudCredential, error) { var credentialsYAML struct { Credentials map[string]interface{} `yaml:"credentials"` } err := yaml.Unmarshal(data, &credentialsYAML) if err != nil { return nil, errors.Annotate(err, "cannot unmarshal yaml credentials") } credentials := make(map[string]CloudCredential) for cloud, v := range credentialsYAML.Credentials { v, err := cloudCredentialChecker{}.Coerce( v, []string{"credentials." + cloud}, ) if err != nil { return nil, errors.Trace(err) } credentials[cloud] = v.(CloudCredential) } return credentials, nil }
go
func ParseCredentials(data []byte) (map[string]CloudCredential, error) { var credentialsYAML struct { Credentials map[string]interface{} `yaml:"credentials"` } err := yaml.Unmarshal(data, &credentialsYAML) if err != nil { return nil, errors.Annotate(err, "cannot unmarshal yaml credentials") } credentials := make(map[string]CloudCredential) for cloud, v := range credentialsYAML.Credentials { v, err := cloudCredentialChecker{}.Coerce( v, []string{"credentials." + cloud}, ) if err != nil { return nil, errors.Trace(err) } credentials[cloud] = v.(CloudCredential) } return credentials, nil }
[ "func", "ParseCredentials", "(", "data", "[", "]", "byte", ")", "(", "map", "[", "string", "]", "CloudCredential", ",", "error", ")", "{", "var", "credentialsYAML", "struct", "{", "Credentials", "map", "[", "string", "]", "interface", "{", "}", "`yaml:\"credentials\"`", "\n", "}", "\n", "err", ":=", "yaml", ".", "Unmarshal", "(", "data", ",", "&", "credentialsYAML", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Annotate", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "credentials", ":=", "make", "(", "map", "[", "string", "]", "CloudCredential", ")", "\n", "for", "cloud", ",", "v", ":=", "range", "credentialsYAML", ".", "Credentials", "{", "v", ",", "err", ":=", "cloudCredentialChecker", "{", "}", ".", "Coerce", "(", "v", ",", "[", "]", "string", "{", "\"", "\"", "+", "cloud", "}", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Trace", "(", "err", ")", "\n", "}", "\n", "credentials", "[", "cloud", "]", "=", "v", ".", "(", "CloudCredential", ")", "\n", "}", "\n", "return", "credentials", ",", "nil", "\n", "}" ]
// ParseCredentials parses the given yaml bytes into Credentials, but does // not validate the credential attributes.
[ "ParseCredentials", "parses", "the", "given", "yaml", "bytes", "into", "Credentials", "but", "does", "not", "validate", "the", "credential", "attributes", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/credentials.go#L402-L421
153,795
juju/juju
cloud/credentials.go
RemoveSecrets
func RemoveSecrets( credential Credential, schemas map[AuthType]CredentialSchema, ) (*Credential, error) { schema, ok := schemas[credential.authType] if !ok { return nil, errors.NotSupportedf("auth-type %q", credential.authType) } redactedAttrs := credential.Attributes() for _, attr := range schema { if attr.Hidden { delete(redactedAttrs, attr.Name) } } return &Credential{authType: credential.authType, attributes: redactedAttrs}, nil }
go
func RemoveSecrets( credential Credential, schemas map[AuthType]CredentialSchema, ) (*Credential, error) { schema, ok := schemas[credential.authType] if !ok { return nil, errors.NotSupportedf("auth-type %q", credential.authType) } redactedAttrs := credential.Attributes() for _, attr := range schema { if attr.Hidden { delete(redactedAttrs, attr.Name) } } return &Credential{authType: credential.authType, attributes: redactedAttrs}, nil }
[ "func", "RemoveSecrets", "(", "credential", "Credential", ",", "schemas", "map", "[", "AuthType", "]", "CredentialSchema", ",", ")", "(", "*", "Credential", ",", "error", ")", "{", "schema", ",", "ok", ":=", "schemas", "[", "credential", ".", "authType", "]", "\n", "if", "!", "ok", "{", "return", "nil", ",", "errors", ".", "NotSupportedf", "(", "\"", "\"", ",", "credential", ".", "authType", ")", "\n", "}", "\n", "redactedAttrs", ":=", "credential", ".", "Attributes", "(", ")", "\n", "for", "_", ",", "attr", ":=", "range", "schema", "{", "if", "attr", ".", "Hidden", "{", "delete", "(", "redactedAttrs", ",", "attr", ".", "Name", ")", "\n", "}", "\n", "}", "\n", "return", "&", "Credential", "{", "authType", ":", "credential", ".", "authType", ",", "attributes", ":", "redactedAttrs", "}", ",", "nil", "\n", "}" ]
// RemoveSecrets returns a copy of the given credential with secret fields removed.
[ "RemoveSecrets", "returns", "a", "copy", "of", "the", "given", "credential", "with", "secret", "fields", "removed", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cloud/credentials.go#L424-L439
153,796
juju/juju
utils/stringforwarder/stringforwarder.go
New
func New(callback func(string)) *StringForwarder { if callback == nil { // Nothing to forward to, so no need to start the loop(). // We'll just count the discardCount. return &StringForwarder{stopped: true} } forwarder := &StringForwarder{} forwarder.cond = sync.NewCond(&forwarder.mu) go forwarder.loop(callback) return forwarder }
go
func New(callback func(string)) *StringForwarder { if callback == nil { // Nothing to forward to, so no need to start the loop(). // We'll just count the discardCount. return &StringForwarder{stopped: true} } forwarder := &StringForwarder{} forwarder.cond = sync.NewCond(&forwarder.mu) go forwarder.loop(callback) return forwarder }
[ "func", "New", "(", "callback", "func", "(", "string", ")", ")", "*", "StringForwarder", "{", "if", "callback", "==", "nil", "{", "// Nothing to forward to, so no need to start the loop().", "// We'll just count the discardCount.", "return", "&", "StringForwarder", "{", "stopped", ":", "true", "}", "\n", "}", "\n", "forwarder", ":=", "&", "StringForwarder", "{", "}", "\n", "forwarder", ".", "cond", "=", "sync", ".", "NewCond", "(", "&", "forwarder", ".", "mu", ")", "\n", "go", "forwarder", ".", "loop", "(", "callback", ")", "\n", "return", "forwarder", "\n", "}" ]
// New returns a new StringForwarder that sends messages to the callback, // function, dropping messages if the receiver has not yet consumed the // last message.
[ "New", "returns", "a", "new", "StringForwarder", "that", "sends", "messages", "to", "the", "callback", "function", "dropping", "messages", "if", "the", "receiver", "has", "not", "yet", "consumed", "the", "last", "message", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/utils/stringforwarder/stringforwarder.go#L24-L34
153,797
juju/juju
utils/stringforwarder/stringforwarder.go
Forward
func (f *StringForwarder) Forward(msg string) { f.mu.Lock() if f.stopped || f.current != nil { f.discardCount++ } else { f.current = &msg f.cond.Signal() } f.mu.Unlock() }
go
func (f *StringForwarder) Forward(msg string) { f.mu.Lock() if f.stopped || f.current != nil { f.discardCount++ } else { f.current = &msg f.cond.Signal() } f.mu.Unlock() }
[ "func", "(", "f", "*", "StringForwarder", ")", "Forward", "(", "msg", "string", ")", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "if", "f", ".", "stopped", "||", "f", ".", "current", "!=", "nil", "{", "f", ".", "discardCount", "++", "\n", "}", "else", "{", "f", ".", "current", "=", "&", "msg", "\n", "f", ".", "cond", ".", "Signal", "(", ")", "\n", "}", "\n", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// Forward sends the message to be processed by the callback function, // discarding the message if another message is currently being processed. // The number of discarded messages is recorded for reporting by the Stop // method. // // Forward is safe to call from multiple goroutines at once. // Note that if this StringForwarder was created with a nil callback, all // messages will be discarded.
[ "Forward", "sends", "the", "message", "to", "be", "processed", "by", "the", "callback", "function", "discarding", "the", "message", "if", "another", "message", "is", "currently", "being", "processed", ".", "The", "number", "of", "discarded", "messages", "is", "recorded", "for", "reporting", "by", "the", "Stop", "method", ".", "Forward", "is", "safe", "to", "call", "from", "multiple", "goroutines", "at", "once", ".", "Note", "that", "if", "this", "StringForwarder", "was", "created", "with", "a", "nil", "callback", "all", "messages", "will", "be", "discarded", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/utils/stringforwarder/stringforwarder.go#L44-L53
153,798
juju/juju
utils/stringforwarder/stringforwarder.go
Stop
func (f *StringForwarder) Stop() uint64 { var count uint64 f.mu.Lock() if !f.stopped { f.stopped = true f.cond.Signal() } count = f.discardCount f.mu.Unlock() return count }
go
func (f *StringForwarder) Stop() uint64 { var count uint64 f.mu.Lock() if !f.stopped { f.stopped = true f.cond.Signal() } count = f.discardCount f.mu.Unlock() return count }
[ "func", "(", "f", "*", "StringForwarder", ")", "Stop", "(", ")", "uint64", "{", "var", "count", "uint64", "\n", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "if", "!", "f", ".", "stopped", "{", "f", ".", "stopped", "=", "true", "\n", "f", ".", "cond", ".", "Signal", "(", ")", "\n", "}", "\n", "count", "=", "f", ".", "discardCount", "\n", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "count", "\n", "}" ]
// Stop cleans up the goroutine running behind StringForwarder and returns the // count of discarded messages. Stop is thread-safe and may be called multiple // times - after the first time, it simply returns the current discard count.
[ "Stop", "cleans", "up", "the", "goroutine", "running", "behind", "StringForwarder", "and", "returns", "the", "count", "of", "discarded", "messages", ".", "Stop", "is", "thread", "-", "safe", "and", "may", "be", "called", "multiple", "times", "-", "after", "the", "first", "time", "it", "simply", "returns", "the", "current", "discard", "count", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/utils/stringforwarder/stringforwarder.go#L58-L68
153,799
juju/juju
utils/stringforwarder/stringforwarder.go
loop
func (f *StringForwarder) loop(callback func(string)) { f.mu.Lock() defer f.mu.Unlock() for { for !f.stopped && f.current == nil { f.cond.Wait() } if f.current == nil { return } f.invokeCallback(callback, *f.current) f.current = nil } }
go
func (f *StringForwarder) loop(callback func(string)) { f.mu.Lock() defer f.mu.Unlock() for { for !f.stopped && f.current == nil { f.cond.Wait() } if f.current == nil { return } f.invokeCallback(callback, *f.current) f.current = nil } }
[ "func", "(", "f", "*", "StringForwarder", ")", "loop", "(", "callback", "func", "(", "string", ")", ")", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "for", "{", "for", "!", "f", ".", "stopped", "&&", "f", ".", "current", "==", "nil", "{", "f", ".", "cond", ".", "Wait", "(", ")", "\n", "}", "\n", "if", "f", ".", "current", "==", "nil", "{", "return", "\n", "}", "\n", "f", ".", "invokeCallback", "(", "callback", ",", "*", "f", ".", "current", ")", "\n", "f", ".", "current", "=", "nil", "\n", "}", "\n", "}" ]
// loop invokes forwarded messages with the given callback until stopped.
[ "loop", "invokes", "forwarded", "messages", "with", "the", "given", "callback", "until", "stopped", "." ]
ba728eedb1e44937c7bdc59f374b06400d0c7133
https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/utils/stringforwarder/stringforwarder.go#L71-L84