ProviderParts returns the provider information for a given reference
(reference string)
| 277 | |
| 278 | // ProviderParts returns the provider information for a given reference |
| 279 | func ProviderParts(reference string) *ProviderRef { |
| 280 | var ref, digest string |
| 281 | // first of all, remove the @sha256 suffix to make the parsing easier |
| 282 | withDigest := strings.SplitN(reference, "@sha256:", 2) |
| 283 | |
| 284 | if len(withDigest) > 1 { |
| 285 | // it has digest |
| 286 | ref = withDigest[0] |
| 287 | digest = withDigest[1] |
| 288 | } else { |
| 289 | ref = reference |
| 290 | } |
| 291 | |
| 292 | parts := strings.SplitN(ref, "://", 2) |
| 293 | var pn []string |
| 294 | if len(parts) == 1 { |
| 295 | pn = strings.SplitN(parts[0], ":", 2) |
| 296 | } else { |
| 297 | // ref might contain the chainloop://protocol |
| 298 | pn = strings.SplitN(parts[1], ":", 2) |
| 299 | } |
| 300 | |
| 301 | var ( |
| 302 | provider string |
| 303 | orgName string |
| 304 | name = pn[0] |
| 305 | ) |
| 306 | |
| 307 | if len(pn) == 2 { |
| 308 | provider = pn[0] |
| 309 | name = pn[1] |
| 310 | } |
| 311 | scoped := strings.SplitN(name, "/", 2) |
| 312 | if len(scoped) == 2 { |
| 313 | // the policy is scoped to a specific org |
| 314 | orgName = scoped[0] |
| 315 | name = scoped[1] |
| 316 | } |
| 317 | |
| 318 | // return the digest back |
| 319 | if digest != "" { |
| 320 | name = fmt.Sprintf("%s@sha256:%s", name, digest) |
| 321 | } |
| 322 | |
| 323 | return &ProviderRef{ |
| 324 | Provider: provider, |
| 325 | Name: name, |
| 326 | OrgName: orgName, |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | func ensureScheme(ref string, expected ...string) (string, error) { |
| 331 | scheme, id := RefParts(ref) |
no outgoing calls