From 1e7c291e7acb8815605d7e4a58db3557f7a7a378 Mon Sep 17 00:00:00 2001 From: Artem Lifshits Date: Mon, 20 May 2024 10:38:31 +0200 Subject: [PATCH] fgs dependency version --- .../fgs/v2/dependency_version_test.go | 38 ++++++++++++++ openstack/fgs/v2/dependency_version/Create.go | 50 +++++++++++++++++++ openstack/fgs/v2/dependency_version/Delete.go | 8 +++ openstack/fgs/v2/dependency_version/Get.go | 17 +++++++ openstack/fgs/v2/dependency_version/List.go | 34 +++++++++++++ .../v2/dependency_version/ListDependencies.go | 32 ++++++++++++ 6 files changed, 179 insertions(+) create mode 100644 acceptance/openstack/fgs/v2/dependency_version_test.go create mode 100644 openstack/fgs/v2/dependency_version/Create.go create mode 100644 openstack/fgs/v2/dependency_version/Delete.go create mode 100644 openstack/fgs/v2/dependency_version/Get.go create mode 100644 openstack/fgs/v2/dependency_version/List.go create mode 100644 openstack/fgs/v2/dependency_version/ListDependencies.go diff --git a/acceptance/openstack/fgs/v2/dependency_version_test.go b/acceptance/openstack/fgs/v2/dependency_version_test.go new file mode 100644 index 000000000..2b07f0cf0 --- /dev/null +++ b/acceptance/openstack/fgs/v2/dependency_version_test.go @@ -0,0 +1,38 @@ +package v2 + +import ( + "strings" + "testing" + + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" + "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/fgs/v2/dependency_version" + "github.com/opentelekomcloud/gophertelekomcloud/openstack/fgs/v2/function" + th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" +) + +func TestDependencyVersionLifecycle(t *testing.T) { + client, err := clients.NewFuncGraphClient() + th.AssertNoErr(t, err) + + createResp, _ := createFunctionGraph(t, client) + + funcUrn := strings.TrimSuffix(createResp.FuncURN, ":latest") + + defer func(client *golangsdk.ServiceClient, id string) { + err = function.Delete(client, id) + th.AssertNoErr(t, err) + }(client, funcUrn) + + createOpts := dependency_version.CreateOpts{ + Name: tools.RandomString("dep-version-", 4), + Runtime: "Python2.7", + DependType: "zip", + DependFile: "", + } + + createDepResp, err := dependency_version.Create(client, createOpts) + th.AssertNoErr(t, err) + tools.PrintResource(t, createDepResp) +} diff --git a/openstack/fgs/v2/dependency_version/Create.go b/openstack/fgs/v2/dependency_version/Create.go new file mode 100644 index 000000000..3bd0f3e51 --- /dev/null +++ b/openstack/fgs/v2/dependency_version/Create.go @@ -0,0 +1,50 @@ +package dependency_version + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type CreateOpts struct { + DependFile string `json:"depend_file,omitempty"` + DependLink string `json:"depend_link,omitempty"` + DependType string `json:"depend_type" required:"true"` + Runtime string `json:"runtime" required:"true"` + Name string `json:"name" required:"true"` + Description string `json:"description,omitempty"` +} + +func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*DepVersionResp, error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return nil, err + } + + raw, err := client.Post(client.ServiceURL("fgs", "dependencies", "version"), b, nil, &golangsdk.RequestOpts{ + OkCodes: []int{200}, + }) + if err != nil { + return nil, err + } + + var res DepVersionResp + return &res, extract.Into(raw.Body, &res) +} + +type DepVersionResp struct { + Id string `json:"id"` + Owner string `json:"owner"` + Link string `json:"link"` + Runtime string `json:"runtime"` + Etag string `json:"etag"` + Size int `json:"size"` + Name string `json:"name"` + Description string `json:"description"` + FileName string `json:"file_name"` + Version int `json:"version"` + DepId string `json:"dep_id"` + LastModified int `json:"last_modified"` + DownloadLink string `json:"download_link"` + IsShared bool `json:"is_shared"` +} diff --git a/openstack/fgs/v2/dependency_version/Delete.go b/openstack/fgs/v2/dependency_version/Delete.go new file mode 100644 index 000000000..ac8c65dfb --- /dev/null +++ b/openstack/fgs/v2/dependency_version/Delete.go @@ -0,0 +1,8 @@ +package dependency_version + +import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + +func Delete(client *golangsdk.ServiceClient, dependId, version string) (err error) { + _, err = client.Delete(client.ServiceURL("fgs", "dependencies", dependId, "version", version), nil) + return +} diff --git a/openstack/fgs/v2/dependency_version/Get.go b/openstack/fgs/v2/dependency_version/Get.go new file mode 100644 index 000000000..3595b3238 --- /dev/null +++ b/openstack/fgs/v2/dependency_version/Get.go @@ -0,0 +1,17 @@ +package dependency_version + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func Get(client *golangsdk.ServiceClient, dependId, version string) (*DepVersionResp, error) { + raw, err := client.Get(client.ServiceURL("fgs", "dependencies", dependId, "version", version), nil, nil) + if err != nil { + return nil, err + } + + var res DepVersionResp + err = extract.Into(raw.Body, &res) + return &res, err +} diff --git a/openstack/fgs/v2/dependency_version/List.go b/openstack/fgs/v2/dependency_version/List.go new file mode 100644 index 000000000..232b8104b --- /dev/null +++ b/openstack/fgs/v2/dependency_version/List.go @@ -0,0 +1,34 @@ +package dependency_version + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ListOpts struct { + DependId string `json:"-"` + Marker string `q:"marker"` + MaxItems string `q:"max_items"` +} + +func List(client *golangsdk.ServiceClient, opts ListOpts) (*ListDepVersionResp, error) { + url, err := golangsdk.NewURLBuilder().WithEndpoints("fgs", "dependencies", opts.DependId, "version").WithQueryParams(&opts).Build() + if err != nil { + return nil, err + } + + raw, err := client.Get(client.ServiceURL(url.String()), nil, nil) + if err != nil { + return nil, err + } + + var res ListDepVersionResp + err = extract.Into(raw.Body, &res) + return &res, err +} + +type ListDepVersionResp struct { + Dependencies []DepVersionResp `json:"dependencies"` + NextMarker int `json:"next_marker"` + Count int `json:"count"` +} diff --git a/openstack/fgs/v2/dependency_version/ListDependencies.go b/openstack/fgs/v2/dependency_version/ListDependencies.go new file mode 100644 index 000000000..e97909a4d --- /dev/null +++ b/openstack/fgs/v2/dependency_version/ListDependencies.go @@ -0,0 +1,32 @@ +package dependency_version + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ListDependenciesOpts struct { + Marker string `q:"marker"` + MaxItems string `q:"max_items"` + IsPublic string `json:"is_public"` + DependencyType string `json:"dependency_type"` + Runtime string `json:"runtime"` + Name string `json:"name"` + Limit string `json:"limit"` +} + +func ListDependencies(client *golangsdk.ServiceClient, opts ListDependenciesOpts) (*ListDepVersionResp, error) { + url, err := golangsdk.NewURLBuilder().WithEndpoints("fgs", "dependencies").WithQueryParams(&opts).Build() + if err != nil { + return nil, err + } + + raw, err := client.Get(client.ServiceURL(url.String()), nil, nil) + if err != nil { + return nil, err + } + + var res ListDepVersionResp + err = extract.Into(raw.Body, &res) + return &res, err +}