Skip to content

Commit 02bc6eb

Browse files
ceng-576-add-hf-upstream
1 parent f008aa9 commit 02bc6eb

File tree

3 files changed

+169
-17
lines changed

3 files changed

+169
-17
lines changed

cloudsmith/resource_repository_upstream.go

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ import (
1414

1515
// upstream types
1616
const (
17-
Cargo = "cargo"
18-
Composer = "composer"
19-
Conda = "conda"
20-
Cran = "cran"
21-
Dart = "dart"
22-
Deb = "deb"
23-
Docker = "docker"
24-
Go = "go"
25-
Helm = "helm"
26-
Maven = "maven"
27-
Npm = "npm"
28-
NuGet = "nuget"
29-
Python = "python"
30-
Rpm = "rpm"
31-
Ruby = "ruby"
32-
Swift = "swift"
17+
Cargo = "cargo"
18+
Composer = "composer"
19+
Conda = "conda"
20+
Cran = "cran"
21+
Dart = "dart"
22+
Deb = "deb"
23+
Docker = "docker"
24+
Go = "go"
25+
Helm = "helm"
26+
HuggingFace = "huggingface"
27+
Maven = "maven"
28+
Npm = "npm"
29+
NuGet = "nuget"
30+
Python = "python"
31+
Rpm = "rpm"
32+
Ruby = "ruby"
33+
Swift = "swift"
3334
)
3435

3536
// tf state prop names
@@ -78,6 +79,7 @@ var (
7879
Docker,
7980
Go,
8081
Helm,
82+
HuggingFace,
8183
Maven,
8284
Npm,
8385
NuGet,
@@ -373,6 +375,24 @@ func resourceRepositoryUpstreamCreate(d *schema.ResourceData, m interface{}) err
373375
VerifySsl: verifySsl,
374376
})
375377
upstream, resp, err = pc.APIClient.ReposApi.ReposUpstreamHelmCreateExecute(req)
378+
case HuggingFace:
379+
req := pc.APIClient.ReposApi.ReposUpstreamHuggingfaceCreate(pc.Auth, namespace, repository)
380+
req = req.Data(cloudsmith.HuggingfaceUpstreamRequest{
381+
AuthMode: authMode,
382+
AuthSecret: authSecret,
383+
AuthUsername: authUsername,
384+
ExtraHeader1: extraHeader1,
385+
ExtraHeader2: extraHeader2,
386+
ExtraValue1: extraValue1,
387+
ExtraValue2: extraValue2,
388+
IsActive: isActive,
389+
Mode: mode,
390+
Name: name,
391+
Priority: priority,
392+
UpstreamUrl: upstreamUrl,
393+
VerifySsl: verifySsl,
394+
})
395+
upstream, resp, err = pc.APIClient.ReposApi.ReposUpstreamHuggingfaceCreateExecute(req)
376396
case Maven:
377397
req := pc.APIClient.ReposApi.ReposUpstreamMavenCreate(pc.Auth, namespace, repository)
378398
req = req.Data(cloudsmith.MavenUpstreamRequest{
@@ -570,6 +590,9 @@ func getUpstream(d *schema.ResourceData, m interface{}) (Upstream, *http.Respons
570590
case Helm:
571591
req := pc.APIClient.ReposApi.ReposUpstreamHelmRead(pc.Auth, namespace, repository, d.Id())
572592
upstream, resp, err = pc.APIClient.ReposApi.ReposUpstreamHelmReadExecute(req)
593+
case HuggingFace:
594+
req := pc.APIClient.ReposApi.ReposUpstreamHuggingfaceRead(pc.Auth, namespace, repository, d.Id())
595+
upstream, resp, err = pc.APIClient.ReposApi.ReposUpstreamHuggingfaceReadExecute(req)
573596
case Maven:
574597
req := pc.APIClient.ReposApi.ReposUpstreamMavenRead(pc.Auth, namespace, repository, d.Id())
575598
upstream, resp, err = pc.APIClient.ReposApi.ReposUpstreamMavenReadExecute(req)
@@ -864,6 +887,24 @@ func resourceRepositoryUpstreamUpdate(d *schema.ResourceData, m interface{}) err
864887
VerifySsl: verifySsl,
865888
})
866889
upstream, _, err = pc.APIClient.ReposApi.ReposUpstreamHelmUpdateExecute(req)
890+
case HuggingFace:
891+
req := pc.APIClient.ReposApi.ReposUpstreamHuggingfaceUpdate(pc.Auth, namespace, repository, slugPerm)
892+
req = req.Data(cloudsmith.HuggingfaceUpstreamRequest{
893+
AuthMode: authMode,
894+
AuthSecret: authSecret,
895+
AuthUsername: authUsername,
896+
ExtraHeader1: extraHeader1,
897+
ExtraHeader2: extraHeader2,
898+
ExtraValue1: extraValue1,
899+
ExtraValue2: extraValue2,
900+
IsActive: isActive,
901+
Mode: mode,
902+
Name: name,
903+
Priority: priority,
904+
UpstreamUrl: upstreamUrl,
905+
VerifySsl: verifySsl,
906+
})
907+
upstream, _, err = pc.APIClient.ReposApi.ReposUpstreamHuggingfaceUpdateExecute(req)
867908
case Maven:
868909
req := pc.APIClient.ReposApi.ReposUpstreamMavenUpdate(pc.Auth, namespace, repository, slugPerm)
869910
req = req.Data(cloudsmith.MavenUpstreamRequest{
@@ -1055,6 +1096,9 @@ func resourceRepositoryUpstreamDelete(d *schema.ResourceData, m interface{}) err
10551096
case Helm:
10561097
req := pc.APIClient.ReposApi.ReposUpstreamHelmDelete(pc.Auth, namespace, repository, d.Id())
10571098
_, err = pc.APIClient.ReposApi.ReposUpstreamHelmDeleteExecute(req)
1099+
case HuggingFace:
1100+
req := pc.APIClient.ReposApi.ReposUpstreamHuggingfaceDelete(pc.Auth, namespace, repository, d.Id())
1101+
_, err = pc.APIClient.ReposApi.ReposUpstreamHuggingfaceDeleteExecute(req)
10581102
case Maven:
10591103
req := pc.APIClient.ReposApi.ReposUpstreamMavenDelete(pc.Auth, namespace, repository, d.Id())
10601104
_, err = pc.APIClient.ReposApi.ReposUpstreamMavenDeleteExecute(req)

cloudsmith/resource_repository_upstream_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,99 @@ resource "cloudsmith_repository_upstream" "helm" {
856856
})
857857
}
858858

859+
func TestAccRepositoryUpstreamHuggingface_basic(t *testing.T) {
860+
t.Parallel()
861+
862+
const huggingfaceUpstreamResourceName = "cloudsmith_repository_upstream.hugging_face"
863+
864+
testAccRepositoryHuggingfaceUpstreamConfigBasic := fmt.Sprintf(`
865+
resource "cloudsmith_repository" "test" {
866+
name = "terraform-acc-test-upstream-huggingface"
867+
namespace = "%s"
868+
}
869+
870+
resource "cloudsmith_repository_upstream" "hugging_face" {
871+
namespace = cloudsmith_repository.test.namespace
872+
repository = cloudsmith_repository.test.slug
873+
name = cloudsmith_repository.test.name
874+
upstream_type = "huggingface"
875+
upstream_url = "https://huggingface.co"
876+
}
877+
`, namespace)
878+
879+
testAccRepositoryHuggingfaceUpstreamConfigUpdate := fmt.Sprintf(`
880+
resource "cloudsmith_repository" "test" {
881+
name = "terraform-acc-test-upstream-huggingface"
882+
namespace = "%s"
883+
}
884+
885+
resource "cloudsmith_repository_upstream" "hugging_face" {
886+
extra_header_1 = "X-Custom-Header"
887+
extra_header_2 = "Access-Control-Allow-Origin"
888+
extra_value_1 = "custom-value"
889+
extra_value_2 = "*"
890+
namespace = cloudsmith_repository.test.namespace
891+
repository = cloudsmith_repository.test.slug
892+
name = cloudsmith_repository.test.name
893+
upstream_type = "huggingface"
894+
upstream_url = "https://huggingface.co"
895+
}
896+
`, namespace)
897+
898+
resource.Test(t, resource.TestCase{
899+
PreCheck: func() { testAccPreCheck(t) },
900+
Providers: testAccProviders,
901+
CheckDestroy: testAccRepositoryUpstreamCheckDestroy(huggingfaceUpstreamResourceName),
902+
Steps: []resource.TestStep{
903+
{
904+
Config: testAccRepositoryHuggingfaceUpstreamConfigBasic,
905+
Check: resource.ComposeTestCheckFunc(
906+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, AuthMode, "None"),
907+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, AuthUsername, ""),
908+
resource.TestCheckResourceAttrSet(huggingfaceUpstreamResourceName, CreatedAt),
909+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, ExtraHeader1, ""),
910+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, ExtraHeader2, ""),
911+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, ExtraValue1, ""),
912+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, ExtraValue2, ""),
913+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, IsActive, "true"),
914+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, Mode, "Proxy Only"),
915+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, Name, "terraform-acc-test-upstream-huggingface"),
916+
resource.TestCheckResourceAttrSet(huggingfaceUpstreamResourceName, Priority),
917+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, UpstreamType, "huggingface"),
918+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, UpstreamUrl, "https://huggingface.co"),
919+
resource.TestCheckResourceAttrSet(huggingfaceUpstreamResourceName, UpdatedAt),
920+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, VerifySsl, "true"),
921+
),
922+
},
923+
{
924+
Config: testAccRepositoryHuggingfaceUpstreamConfigUpdate,
925+
Check: resource.ComposeTestCheckFunc(
926+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, ExtraHeader1, "X-Custom-Header"),
927+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, ExtraHeader2, "Access-Control-Allow-Origin"),
928+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, ExtraValue1, "custom-value"),
929+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, ExtraValue2, "*"),
930+
resource.TestCheckResourceAttr(huggingfaceUpstreamResourceName, IsActive, "true"),
931+
),
932+
},
933+
{
934+
ResourceName: huggingfaceUpstreamResourceName,
935+
ImportState: true,
936+
ImportStateIdFunc: func(s *terraform.State) (string, error) {
937+
resourceState := s.RootModule().Resources[huggingfaceUpstreamResourceName]
938+
return fmt.Sprintf(
939+
"%s.%s.%s.%s",
940+
resourceState.Primary.Attributes[Namespace],
941+
resourceState.Primary.Attributes[Repository],
942+
resourceState.Primary.Attributes[UpstreamType],
943+
resourceState.Primary.Attributes[SlugPerm],
944+
), nil
945+
},
946+
ImportStateVerify: true,
947+
},
948+
},
949+
})
950+
}
951+
859952
func TestAccRepositoryUpstreamMaven_basic(t *testing.T) {
860953
t.Parallel()
861954

@@ -1647,6 +1740,9 @@ func testAccRepositoryUpstreamCheckDestroy(resourceName string) resource.TestChe
16471740
case Helm:
16481741
req := pc.APIClient.ReposApi.ReposUpstreamHelmRead(pc.Auth, namespace, repository, slugPerm)
16491742
_, resp, err = pc.APIClient.ReposApi.ReposUpstreamHelmReadExecute(req)
1743+
case HuggingFace:
1744+
req := pc.APIClient.ReposApi.ReposUpstreamHuggingfaceRead(pc.Auth, namespace, repository, slugPerm)
1745+
_, resp, err = pc.APIClient.ReposApi.ReposUpstreamHuggingfaceReadExecute(req)
16501746
case Maven:
16511747
req := pc.APIClient.ReposApi.ReposUpstreamMavenRead(pc.Auth, namespace, repository, slugPerm)
16521748
_, resp, err = pc.APIClient.ReposApi.ReposUpstreamMavenReadExecute(req)

docs/resources/repository_upstream.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ resource "cloudsmith_repository_upstream" "helm_charts" {
159159
}
160160
```
161161

162+
### HuggingFace
163+
164+
```hcl
165+
resource "cloudsmith_repository_upstream" "hugging_face" {
166+
name = "HuggingFace"
167+
namespace = "${data.cloudsmith_organization.my_organization.slug_perm}"
168+
repository = "${resource.cloudsmith_repository.my_repository.slug_perm}"
169+
upstream_type = "huggingface"
170+
upstream_url = "https://huggingface.co"
171+
}
172+
```
173+
162174
### Maven
163175

164176
```hcl
@@ -271,7 +283,7 @@ The following arguments are supported:
271283
| `priority` | N | number | N/A | Upstream sources are selected for resolving requests by sequential order (1..n), followed by creation date. |
272284
| `repository` | Y | string | N/A | The Repository to which the upstream belongs. |
273285
| `upstream_distribution` | N | string | N/A | Used only in conjunction with an `upstream_type` of `"deb"` to declare the [distribution](https://wiki.debian.org/DebianRepository/Format#Overview) to fetch from the upstream. |
274-
| `upstream_type` | Y | string | `"cargo"`<br>`"composer"`<br>`"conda"`<br>`"cran"`<br>`"dart"`<br>`"deb"`<br>`"docker"`<br>`"go"`<br>`"helm"`<br>`"maven"`<br>`"npm"`<br>`"nuget"`<br>`"python"`<br>`"rpm"`<br>`"ruby"`<br>`"swift"` | The type of Upstream. |
286+
| `upstream_type` | Y | string | `"cargo"`<br>`"composer"`<br>`"conda"`<br>`"cran"`<br>`"dart"`<br>`"deb"`<br>`"docker"`<br>`"go"`<br>`"helm"`<br>`"huggingface"`<br>`"maven"`<br>`"npm"`<br>`"nuget"`<br>`"python"`<br>`"rpm"`<br>`"ruby"`<br>`"swift"` | The type of Upstream. |
275287
| `upstream_url` | Y | string | N/A | The URL for this upstream source. This must be a fully qualified URL including any path elements required to reach the root of the repository. The URL cannot end with a trailing slash. |
276288
| `verify_ssl` | N | bool | N/A | If enabled, SSL certificates are verified when requests are made to this upstream. It's recommended to leave this enabled for all public sources to help mitigate Man-In-The-Middle (MITM) attacks. Please note this only applies to HTTPS upstreams. |
277289

0 commit comments

Comments
 (0)