// itemToResource attempts to decode the supplied `backend.Item` as one
// of the supported resource types.  If the resource's `kind` does not match
// one of the supported resource types, `trace.NotImplementedError` is returned.
itemToResource attempts to decode the supplied `backend.Item` as one
of the supported resource types.  If the resource's `kind` does not match
one of the supported resource types, `trace.NotImplementedError` is returned.
// itemToResource attempts to decode the supplied ` backend . Item ` as one // of the supported resource types . If the resource ' s ` kind ` does not match // one of the supported resource types ` trace . NotImplementedError ` is returned .
func itemToResource(item backend.Item) (services.Resource, error) {
	var u services.UnknownResource
	if err := u.UnmarshalJSON(item.Value); err != nil {
		return nil, trace.Wrap(err)
	}
	var rsc services.Resource
	var err error
	switch kind := u.GetKind(); kind {
	case services.KindUser:
		rsc, err = itemToUser(item)
	case services.KindCertAuthority:
		rsc, err = itemToCertAuthority(item)
	case services.KindTrustedCluster:
		rsc, err = itemToTrustedCluster(item)
	case services.KindGithubConnector:
		rsc, err = itemToGithubConnector(item)
	case services.KindRole:
		rsc, err = itemToRole(item)
	case services.KindOIDCConnector:
		rsc, err = itemToOIDCConnector(item)
	case services.KindSAMLConnector:
		rsc, err = itemToSAMLConnector(item)
	case "":
		return nil, trace.BadParameter("item %q is not a resource (missing field 'kind')", string(item.Key))
	default:
		return nil, trace.NotImplemented("cannot dynamically decode resource of kind %q", kind)
	}
	if err != nil {
		return nil, trace.Wrap(err)
	}
	return rsc, nil
}
func itemToResource ( item backend . Item ) ( services . Resource , error ) { var u services . UnknownResource if err := u . UnmarshalJSON ( item . Value ) ; err != nil { return nil , trace . Wrap ( err ) } var rsc services . Resource var err error switch kind := u . GetKind ( ) ; kind { case services . KindUser : rsc , err = itemToUser ( item ) case services . KindCertAuthority : rsc , err = itemToCertAuthority ( item ) case services . KindTrustedCluster : rsc , err = itemToTrustedCluster ( item ) case services . KindGithubConnector : rsc , err = itemToGithubConnector ( item ) case services . KindRole : rsc , err = itemToRole ( item ) case services . KindOIDCConnector : rsc , err = itemToOIDCConnector ( item ) case services . KindSAMLConnector : rsc , err = itemToSAMLConnector ( item ) case " " : return nil , trace . BadParameter ( " " , string ( item . Key ) ) default : return nil , trace . NotImplemented ( " " , kind ) } if err != nil { return nil , trace . Wrap ( err ) } return rsc , nil }
itemToResource attempts to decode the supplied `backend.Item` as one
of the supported resource types.
itemToResource attempts to decode the supplied ` backend . Item ` as one of the supported resource types .