本文整理汇总了Golang中github.com/juju/errors.NewNotValid函数的典型用法代码示例。如果您正苦于以下问题:Golang NewNotValid函数的具体用法?Golang NewNotValid怎么用?Golang NewNotValid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewNotValid函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: validateHost
func validateHost(url url.URL) error {
if url.Host == "" {
return errors.NewNotValid(nil, "URL missing host")
}
host, port, err := net.SplitHostPort(url.Host)
if err != nil {
return errors.NewNotValid(err, "")
}
// Check the host.
if net.ParseIP(host) == nil {
if err := validateDomainName(host); err != nil {
return errors.Trace(err)
}
}
// Check the port.
if p, err := strconv.Atoi(port); err != nil {
return errors.NewNotValid(err, fmt.Sprintf("invalid port in host %q", url.Host))
} else if p <= 0 || p > 0xFFFF {
return errors.NewNotValid(err, fmt.Sprintf("invalid port in host %q", url.Host))
}
return nil
}
开发者ID:bac,项目名称:juju,代码行数:26,代码来源:addserver.go
示例2: Validate
// Validate ensures that the origin is correct.
func (o Origin) Validate() error {
if o.ControllerUUID == "" {
return errors.NewNotValid(nil, "empty ControllerUUID")
}
if !names.IsValidModel(o.ControllerUUID) {
return errors.NewNotValid(nil, fmt.Sprintf("ControllerUUID %q not a valid UUID", o.ControllerUUID))
}
if o.ModelUUID == "" {
return errors.NewNotValid(nil, "empty ModelUUID")
}
if !names.IsValidModel(o.ModelUUID) {
return errors.NewNotValid(nil, fmt.Sprintf("ModelUUID %q not a valid UUID", o.ModelUUID))
}
if err := o.Type.Validate(); err != nil {
return errors.Annotate(err, "invalid Type")
}
if o.Name == "" && o.Type != OriginTypeUnknown {
return errors.NewNotValid(nil, "empty Name")
}
if err := o.Type.ValidateName(o.Name); err != nil {
return errors.Annotatef(err, "invalid Name %q", o.Name)
}
if !o.Software.isZero() {
if err := o.Software.Validate(); err != nil {
return errors.Annotate(err, "invalid Software")
}
}
return nil
}
开发者ID:bac,项目名称:juju,代码行数:35,代码来源:origin.go
示例3: newSizeChecker
func newSizeChecker(size int) func([]byte) error {
return func(sum []byte) error {
if len(sum) < size {
return errors.NewNotValid(nil, "invalid fingerprint (too small)")
}
if len(sum) > size {
return errors.NewNotValid(nil, "invalid fingerprint (too big)")
}
return nil
}
}
开发者ID:kat-co,项目名称:utils,代码行数:11,代码来源:hash.go
示例4: Validate
// Validate ensures that the entry considers itself to be in a
// complete and valid state.
func (e AuditEntry) Validate() error {
if e.JujuServerVersion == version.Zero {
return errors.NewNotValid(errors.NotAssignedf("JujuServerVersion"), "")
}
if e.ModelUUID == "" {
return errors.NewNotValid(errors.NotAssignedf("ModelUUID"), "")
}
if utils.IsValidUUIDString(e.ModelUUID) == false {
return errors.NotValidf("ModelUUID")
}
if e.Timestamp.IsZero() {
return errors.NewNotValid(errors.NotAssignedf("Timestamp"), "")
}
if e.Timestamp.Location() != time.UTC {
return errors.NewNotValid(errors.NotValidf("Timestamp"), "must be set to UTC")
}
if e.RemoteAddress == "" {
return errors.NewNotValid(errors.NotAssignedf("RemoteAddress"), "")
}
if e.OriginType == "" {
return errors.NewNotValid(errors.NotAssignedf("OriginType"), "")
}
if e.OriginName == "" {
return errors.NewNotValid(errors.NotAssignedf("OriginName"), "")
}
if e.Operation == "" {
return errors.NewNotValid(errors.NotAssignedf("Operation"), "")
}
// Data remains unchecked as it is always optional.
return nil
}
开发者ID:bac,项目名称:juju,代码行数:35,代码来源:audit.go
示例5: processFileAttrValue
func (s CredentialSchema) processFileAttrValue(
field NamedCredentialAttr, resultMap map[string]interface{}, newAttrs map[string]string,
readFile func(string) ([]byte, error),
) error {
name := field.Name
if fieldVal, ok := resultMap[name]; ok {
if _, ok := resultMap[field.FileAttr]; ok {
return errors.NotValidf(
"specifying both %q and %q",
name, field.FileAttr,
)
}
newAttrs[name] = fieldVal.(string)
return nil
}
fieldVal, ok := resultMap[field.FileAttr]
if !ok {
return errors.NewNotValid(nil, fmt.Sprintf(
"either %q or %q must be specified",
name, field.FileAttr,
))
}
data, err := readFile(fieldVal.(string))
if err != nil {
return errors.Annotatef(err, "reading file for %q", name)
}
if len(data) == 0 {
return errors.NotValidf("empty file for %q", name)
}
newAttrs[name] = string(data)
return nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:32,代码来源:credentials.go
示例6: promptControllerName
func (c *registerCommand) promptControllerName(store jujuclient.ClientStore, suggestedName string, stderr io.Writer, stdin io.Reader) (string, error) {
_, err := store.ControllerByName(suggestedName)
if err == nil {
fmt.Fprintf(stderr, errControllerConflicts, suggestedName)
suggestedName = ""
}
var setMsg string
setMsg = "Enter a name for this controller: "
if suggestedName != "" {
setMsg = fmt.Sprintf("Enter a name for this controller [%s]: ",
suggestedName)
}
fmt.Fprintf(stderr, setMsg)
defer stderr.Write([]byte{'\n'})
name, err := c.readLine(stdin)
if err != nil {
return "", errors.Trace(err)
}
name = strings.TrimSpace(name)
if name == "" && suggestedName == "" {
return "", errors.NewNotValid(nil, "you must specify a non-empty controller name")
}
if name == "" && suggestedName != "" {
return suggestedName, nil
}
return name, nil
}
开发者ID:kat-co,项目名称:juju,代码行数:27,代码来源:register.go
示例7: validateLinkLayerDeviceParent
func (m *Machine) validateLinkLayerDeviceParent(args *LinkLayerDeviceArgs) error {
hostMachineID, parentDeviceName, err := parseLinkLayerDeviceParentNameAsGlobalKey(args.ParentName)
if err != nil {
return errors.Trace(err)
} else if hostMachineID == "" {
// Not a global key, so validate as usual.
if err := m.validateParentDeviceNameWhenNotAGlobalKey(args); errors.IsNotFound(err) {
return errors.NewNotValid(err, "ParentName not valid")
} else if err != nil {
return errors.Trace(err)
}
return nil
}
ourParentMachineID, hasParent := m.ParentId()
if !hasParent {
// Using global key for ParentName not allowed for non-container machine
// devices.
return errors.NotValidf("ParentName %q for non-container machine %q", args.ParentName, m.Id())
}
if hostMachineID != ourParentMachineID {
// ParentName as global key only allowed when the key's machine ID is
// the container's host machine.
return errors.NotValidf("ParentName %q on non-host machine %q", args.ParentName, hostMachineID)
}
err = m.verifyHostMachineParentDeviceExistsAndIsABridgeDevice(hostMachineID, parentDeviceName)
return errors.Trace(err)
}
开发者ID:makyo,项目名称:juju,代码行数:28,代码来源:machine_linklayerdevices.go
示例8: validateSetDevicesAddressesArgs
func (m *Machine) validateSetDevicesAddressesArgs(args *LinkLayerDeviceAddress) error {
if args.CIDRAddress == "" {
return errors.NotValidf("empty CIDRAddress")
}
if _, _, err := net.ParseCIDR(args.CIDRAddress); err != nil {
return errors.NewNotValid(err, "CIDRAddress")
}
if args.DeviceName == "" {
return errors.NotValidf("empty DeviceName")
}
if !IsValidLinkLayerDeviceName(args.DeviceName) {
logger.Warningf(
"address %q on machine %q has invalid device name %q (using anyway)",
args.CIDRAddress, m.Id(), args.DeviceName,
)
}
if err := m.verifyDeviceAlreadyExists(args.DeviceName); err != nil {
return errors.Trace(err)
}
if !IsValidAddressConfigMethod(string(args.ConfigMethod)) {
return errors.NotValidf("ConfigMethod %q", args.ConfigMethod)
}
if args.GatewayAddress != "" {
if ip := net.ParseIP(args.GatewayAddress); ip == nil {
return errors.NotValidf("GatewayAddress %q", args.GatewayAddress)
}
}
return nil
}
开发者ID:makyo,项目名称:juju,代码行数:33,代码来源:machine_linklayerdevices.go
示例9: Run
func (c *setDefaultRegionCommand) Run(ctxt *cmd.Context) error {
cloudDetails, err := cloudOrProvider(c.cloud, jujucloud.CloudByName)
if err != nil {
return err
}
if len(cloudDetails.Regions) == 0 {
return errors.Errorf("cloud %s has no regions", c.cloud)
}
if !hasRegion(c.region, cloudDetails.Regions) {
var regionNames []string
for _, r := range cloudDetails.Regions {
regionNames = append(regionNames, r.Name)
}
return errors.NewNotValid(
nil,
fmt.Sprintf("region %q for cloud %s not valid, valid regions are %s",
c.region, c.cloud, strings.Join(regionNames, ", ")))
}
var cred *jujucloud.CloudCredential
cred, err = c.store.CredentialForCloud(c.cloud)
if errors.IsNotFound(err) {
cred = &jujucloud.CloudCredential{}
} else if err != nil {
return err
}
cred.DefaultRegion = c.region
if err := c.store.UpdateCredential(c.cloud, *cred); err != nil {
return err
}
ctxt.Infof("Default region in %s set to %q.", c.cloud, c.region)
return nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:32,代码来源:defaultregion.go
示例10: parseResourceFileArg
// parseResourceFileArg converts the provided string into a name and
// filename. The string must be in the "<name>=<filename>" format.
func parseResourceFileArg(raw string) (name string, filename string, _ error) {
vals := strings.SplitN(raw, "=", 2)
if len(vals) < 2 {
msg := fmt.Sprintf("expected name=path format")
return "", "", errors.NewNotValid(nil, msg)
}
name, filename = vals[0], vals[1]
if name == "" {
return "", "", errors.NewNotValid(nil, "missing resource name")
}
if filename == "" {
return "", "", errors.NewNotValid(nil, "missing filename")
}
return name, filename, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:18,代码来源:file.go
示例11: validateScheme
func validateScheme(url url.URL) error {
switch url.Scheme {
case "https":
default:
return errors.NewNotValid(nil, fmt.Sprintf("unsupported URL scheme %q", url.Scheme))
}
return nil
}
开发者ID:bac,项目名称:juju,代码行数:8,代码来源:addserver.go
示例12: AddSpace
// AddSpace creates and returns a new space.
func (st *State) AddSpace(name string, providerId network.Id, subnets []string, isPublic bool) (newSpace *Space, err error) {
defer errors.DeferredAnnotatef(&err, "adding space %q", name)
if !names.IsValidSpace(name) {
return nil, errors.NewNotValid(nil, "invalid space name")
}
spaceDoc := spaceDoc{
Life: Alive,
Name: name,
IsPublic: isPublic,
ProviderId: string(providerId),
}
newSpace = &Space{doc: spaceDoc, st: st}
ops := []txn.Op{{
C: spacesC,
Id: name,
Assert: txn.DocMissing,
Insert: spaceDoc,
}}
if providerId != "" {
ops = append(ops, st.networkEntityGlobalKeyOp("space", providerId))
}
for _, subnetId := range subnets {
// TODO:(mfoord) once we have refcounting for subnets we should
// also assert that the refcount is zero as moving the space of a
// subnet in use is not permitted.
ops = append(ops, txn.Op{
C: subnetsC,
Id: subnetId,
Assert: txn.DocExists,
Update: bson.D{{"$set", bson.D{{"space-name", name}}}},
})
}
if err := st.runTransaction(ops); err == txn.ErrAborted {
if _, err := st.Space(name); err == nil {
return nil, errors.AlreadyExistsf("space %q", name)
}
for _, subnetId := range subnets {
if _, err := st.Subnet(subnetId); errors.IsNotFound(err) {
return nil, err
}
}
if err := newSpace.Refresh(); err != nil {
if errors.IsNotFound(err) {
return nil, errors.Errorf("ProviderId %q not unique", providerId)
}
return nil, errors.Trace(err)
}
return nil, errors.Trace(err)
} else if err != nil {
return nil, err
}
return newSpace, nil
}
开发者ID:bac,项目名称:juju,代码行数:59,代码来源:spaces.go
示例13: TestNewFingerprintInvalid
func (s *FingerprintSuite) TestNewFingerprintInvalid(c *gc.C) {
expected, _ := newFingerprint(c, "spamspamspam")
failure := errors.NewNotValid(nil, "bogus!!!")
s.stub.SetErrors(failure)
_, err := hash.NewFingerprint(expected, s.validate)
s.stub.CheckCallNames(c, "validate")
c.Check(errors.Cause(err), gc.Equals, failure)
}
开发者ID:juju,项目名称:utils,代码行数:10,代码来源:fingerprint_test.go
示例14: validateParentDeviceNameWhenNotAGlobalKey
func (m *Machine) validateParentDeviceNameWhenNotAGlobalKey(args *LinkLayerDeviceArgs) error {
if !IsValidLinkLayerDeviceName(args.ParentName) {
return errors.NotValidf("ParentName %q", args.ParentName)
}
if args.Name == args.ParentName {
return errors.NewNotValid(nil, "Name and ParentName must be different")
}
if err := m.verifyParentDeviceExists(args.ParentName); err != nil {
return errors.Trace(err)
}
return nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:12,代码来源:machine_linklayerdevices.go
示例15: ValidateName
// ValidateName ensures that the given origin name is valid within the
// context of the origin type.
func (ot OriginType) ValidateName(name string) error {
switch ot {
case OriginTypeUnknown:
if name != "" {
return errors.NewNotValid(nil, "origin name must not be set if type is unknown")
}
case OriginTypeUser:
if !names.IsValidUser(name) {
return errors.NewNotValid(nil, "bad user name")
}
case OriginTypeMachine:
if !names.IsValidMachine(name) {
return errors.NewNotValid(nil, "bad machine name")
}
case OriginTypeUnit:
if !names.IsValidUnit(name) {
return errors.NewNotValid(nil, "bad unit name")
}
}
return nil
}
开发者ID:bac,项目名称:juju,代码行数:23,代码来源:origin.go
示例16: prepareOneSetLinkLayerDeviceArgs
func (m *Machine) prepareOneSetLinkLayerDeviceArgs(args *LinkLayerDeviceArgs, pendingNames set.Strings) (_ *linkLayerDeviceDoc, err error) {
defer errors.DeferredAnnotatef(&err, "invalid device %q", args.Name)
if err := m.validateSetLinkLayerDeviceArgs(args); err != nil {
return nil, errors.Trace(err)
}
if pendingNames.Contains(args.Name) {
return nil, errors.NewNotValid(nil, "Name specified more than once")
}
return m.newLinkLayerDeviceDocFromArgs(args), nil
}
开发者ID:bac,项目名称:juju,代码行数:13,代码来源:machine_linklayerdevices.go
示例17: promptControllerName
func (c *registerCommand) promptControllerName(stderr io.Writer, stdin io.Reader) (string, error) {
fmt.Fprintf(stderr, "Please set a name for this controller: ")
defer stderr.Write([]byte{'\n'})
name, err := c.readLine(stdin)
if err != nil {
return "", errors.Trace(err)
}
name = strings.TrimSpace(name)
if name == "" {
return "", errors.NewNotValid(nil, "you must specify a non-empty controller name")
}
return name, nil
}
开发者ID:makyo,项目名称:juju,代码行数:13,代码来源:register.go
示例18: Validate
// Validate ensures that the spec is valid.
func (res Resource) Validate() error {
// TODO(ericsnow) Ensure that the "placeholder" fields are not set
// if IsLocalPlaceholder() returns true (and that they *are* set
// otherwise)? Also ensure an "upload" origin in the "placeholder"
// case?
if err := res.Resource.Validate(); err != nil {
return errors.Annotate(err, "bad info")
}
if res.ServiceID == "" {
return errors.NewNotValid(nil, "missing service ID")
}
// TODO(ericsnow) Require that Username be set if timestamp is?
if res.Timestamp.IsZero() && res.Username != "" {
return errors.NewNotValid(nil, "missing timestamp")
}
return nil
}
开发者ID:OSBI,项目名称:juju,代码行数:23,代码来源:resource.go
示例19: validateCloudCredentials
// validateCloudCredentials checks that the supplied cloud credentials are
// valid for use with the controller's cloud, and returns a set of txn.Ops
// to assert the same in a transaction. The map keys are the cloud credential
// IDs.
//
// TODO(rogpeppe) We're going to a lot of effort here to assert that a
// cloud's auth types haven't changed since we looked at them a moment
// ago, but we don't support changing a cloud's definition currently and
// it's not clear that doing so would be a good idea, as changing a
// cloud's auth type would invalidate all existing credentials and would
// usually involve a new provider version and juju binary too, so
// perhaps all this code is unnecessary.
func validateCloudCredentials(
cloud cloud.Cloud,
cloudName string,
credentials map[names.CloudCredentialTag]cloud.Credential,
) ([]txn.Op, error) {
requiredAuthTypes := make(set.Strings)
for tag, credential := range credentials {
if tag.Cloud().Id() != cloudName {
return nil, errors.NewNotValid(nil, fmt.Sprintf(
"credential %q for non-matching cloud is not valid (expected %q)",
tag.Id(), cloudName,
))
}
var found bool
for _, authType := range cloud.AuthTypes {
if credential.AuthType() == authType {
found = true
break
}
}
if !found {
return nil, errors.NewNotValid(nil, fmt.Sprintf(
"credential %q with auth-type %q is not supported (expected one of %q)",
tag.Id(), credential.AuthType(), cloud.AuthTypes,
))
}
requiredAuthTypes.Add(string(credential.AuthType()))
}
ops := make([]txn.Op, len(requiredAuthTypes))
for i, authType := range requiredAuthTypes.SortedValues() {
ops[i] = txn.Op{
C: cloudsC,
Id: cloudName,
Assert: bson.D{{"auth-types", authType}},
}
}
return ops, nil
}
开发者ID:bac,项目名称:juju,代码行数:50,代码来源:cloudcredentials.go
示例20: AddSpace
// AddSpace creates and returns a new space.
func (st *State) AddSpace(name string, subnets []string, isPublic bool) (newSpace *Space, err error) {
defer errors.DeferredAnnotatef(&err, "adding space %q", name)
if !names.IsValidSpace(name) {
return nil, errors.NewNotValid(nil, "invalid space name")
}
spaceID := st.docID(name)
spaceDoc := spaceDoc{
DocID: spaceID,
EnvUUID: st.EnvironUUID(),
Life: Alive,
Name: name,
IsPublic: isPublic,
}
newSpace = &Space{doc: spaceDoc, st: st}
ops := []txn.Op{{
C: spacesC,
Id: spaceID,
Assert: txn.DocMissing,
Insert: spaceDoc,
}}
for _, subnetId := range subnets {
// TODO:(mfoord) once we have refcounting for subnets we should
// also assert that the refcount is zero as moving the space of a
// subnet in use is not permitted.
ops = append(ops, txn.Op{
C: subnetsC,
Id: st.docID(subnetId),
Assert: txn.DocExists,
Update: bson.D{{"$set", bson.D{{"space-name", name}}}},
})
}
if err := st.runTransaction(ops); err == txn.ErrAborted {
if _, err := st.Space(name); err == nil {
return nil, errors.AlreadyExistsf("space %q", name)
}
for _, subnetId := range subnets {
if _, err := st.Subnet(subnetId); errors.IsNotFound(err) {
return nil, err
}
}
} else if err != nil {
return nil, err
}
return newSpace, nil
}
开发者ID:imoapps,项目名称:juju,代码行数:50,代码来源:spaces.go
注:本文中的github.com/juju/errors.NewNotValid函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论