func (st resourceState) setResource(pendingID, applicationID, userID string, chRes charmresource.Resource, r io.Reader) (resource.Resource, error) { id := newResourceID(applicationID, chRes.Name) res := resource.Resource{ Resource: chRes, ID: id, PendingID: pendingID, ApplicationID: applicationID, } if r != nil { // TODO(ericsnow) Validate the user ID (or use a tag). res.Username = userID res.Timestamp = st.currentTimestamp() } if err := res.Validate(); err != nil { return res, errors.Annotate(err, "bad resource metadata") } if r == nil { if err := st.persist.SetResource(res); err != nil { return res, errors.Trace(err) } } else { if err := st.storeResource(res, r); err != nil { return res, errors.Trace(err) } } return res, nil }