Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FGS]: dependency version #660

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions acceptance/openstack/fgs/v2/dependency_version_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
50 changes: 50 additions & 0 deletions openstack/fgs/v2/dependency_version/Create.go
Original file line number Diff line number Diff line change
@@ -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"`
}
8 changes: 8 additions & 0 deletions openstack/fgs/v2/dependency_version/Delete.go
Original file line number Diff line number Diff line change
@@ -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
}
17 changes: 17 additions & 0 deletions openstack/fgs/v2/dependency_version/Get.go
Original file line number Diff line number Diff line change
@@ -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
}
34 changes: 34 additions & 0 deletions openstack/fgs/v2/dependency_version/List.go
Original file line number Diff line number Diff line change
@@ -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"`
}
32 changes: 32 additions & 0 deletions openstack/fgs/v2/dependency_version/ListDependencies.go
Original file line number Diff line number Diff line change
@@ -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
}