NewUploader prepares uploads against targetRepository, the numeric REST id of the repository the assets are uploaded against, and viewerPermission, the GraphQL viewerPermission field on that same repository. It validates everything an upload needs, so a caller that gets an Uploader back can use it.
(httpClient *http.Client, tokenType gh.TokenType, host string, targetRepository int64, viewerPermission string)
| 37 | // makes an upload work, so any other order would name a fault the user cannot |
| 38 | // fix. The other checks are free to move. |
| 39 | func NewUploader(httpClient *http.Client, tokenType gh.TokenType, host string, targetRepository int64, viewerPermission string) (*Uploader, error) { |
| 40 | if err := checkHost(host); err != nil { |
| 41 | return nil, err |
| 42 | } |
| 43 | |
| 44 | if err := checkUploadTokenType(tokenType); err != nil { |
| 45 | return nil, err |
| 46 | } |
| 47 | |
| 48 | if targetRepository <= 0 { |
| 49 | return nil, errors.New("could not determine which repository to attach files to") |
| 50 | } |
| 51 | |
| 52 | if err := checkPermission(viewerPermission); err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | |
| 56 | // TODO(api-client-rollout) |
| 57 | // This line of code is part of a mechanical roll out of the api client. |
| 58 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 59 | return &Uploader{client: api.NewClientFromHTTP(httpClient), host: host, targetRepository: targetRepository}, nil |
| 60 | } |
| 61 | |
| 62 | // checkHost rejects a host that cannot serve the upload endpoint. IsEnterprise |
| 63 | // is false for ghe.com tenants, so data residency keeps working. |