Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
eeae8161
Commit
eeae8161
authored
Jan 24, 2018
by
Minhan Xia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix url parsing for staging/dev endpoint
parent
ddea2dd5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
14 deletions
+16
-14
utils.go
pkg/cloudprovider/providers/gce/cloud/utils.go
+4
-13
utils_test.go
pkg/cloudprovider/providers/gce/cloud/utils_test.go
+12
-1
No files found.
pkg/cloudprovider/providers/gce/cloud/utils.go
View file @
eeae8161
...
@@ -30,10 +30,6 @@ const (
...
@@ -30,10 +30,6 @@ const (
betaPrefix
=
"https://www.googleapis.com/compute/beta/"
betaPrefix
=
"https://www.googleapis.com/compute/beta/"
)
)
var
(
allPrefixes
=
[]
string
{
gaPrefix
,
alphaPrefix
,
betaPrefix
}
)
// ResourceID identifies a GCE resource as parsed from compute resource URL.
// ResourceID identifies a GCE resource as parsed from compute resource URL.
type
ResourceID
struct
{
type
ResourceID
struct
{
ProjectID
string
ProjectID
string
...
@@ -66,15 +62,10 @@ func (r *ResourceID) Equal(other *ResourceID) bool {
...
@@ -66,15 +62,10 @@ func (r *ResourceID) Equal(other *ResourceID) bool {
func
ParseResourceURL
(
url
string
)
(
*
ResourceID
,
error
)
{
func
ParseResourceURL
(
url
string
)
(
*
ResourceID
,
error
)
{
errNotValid
:=
fmt
.
Errorf
(
"%q is not a valid resource URL"
,
url
)
errNotValid
:=
fmt
.
Errorf
(
"%q is not a valid resource URL"
,
url
)
// Remove the "https://..." prefix if present
// Remove the prefix up to ...projects/
for
_
,
prefix
:=
range
allPrefixes
{
projectsIndex
:=
strings
.
Index
(
url
,
"/projects/"
)
if
strings
.
HasPrefix
(
url
,
prefix
)
{
if
projectsIndex
>=
0
{
if
len
(
url
)
<
len
(
prefix
)
{
url
=
url
[
projectsIndex
+
1
:
]
return
nil
,
errNotValid
}
url
=
url
[
len
(
prefix
)
:
]
break
}
}
}
parts
:=
strings
.
Split
(
url
,
"/"
)
parts
:=
strings
.
Split
(
url
,
"/"
)
...
...
pkg/cloudprovider/providers/gce/cloud/utils_test.go
View file @
eeae8161
...
@@ -55,6 +55,18 @@ func TestParseResourceURL(t *testing.T) {
...
@@ -55,6 +55,18 @@ func TestParseResourceURL(t *testing.T) {
&
ResourceID
{
"some-gce-project"
,
"instances"
,
meta
.
ZonalKey
(
"instance-1"
,
"us-central1-c"
)},
&
ResourceID
{
"some-gce-project"
,
"instances"
,
meta
.
ZonalKey
(
"instance-1"
,
"us-central1-c"
)},
},
},
{
{
"http://localhost:3990/compute/beta/projects/some-gce-project/global/operations/operation-1513289952196-56054460af5a0-b1dae0c3-9bbf9dbf"
,
&
ResourceID
{
"some-gce-project"
,
"operations"
,
meta
.
GlobalKey
(
"operation-1513289952196-56054460af5a0-b1dae0c3-9bbf9dbf"
)},
},
{
"http://localhost:3990/compute/alpha/projects/some-gce-project/regions/dev-central1/addresses/my-address"
,
&
ResourceID
{
"some-gce-project"
,
"addresses"
,
meta
.
RegionalKey
(
"my-address"
,
"dev-central1"
)},
},
{
"http://localhost:3990/compute/v1/projects/some-gce-project/zones/dev-central1-std/instances/instance-1"
,
&
ResourceID
{
"some-gce-project"
,
"instances"
,
meta
.
ZonalKey
(
"instance-1"
,
"dev-central1-std"
)},
},
{
"projects/some-gce-project"
,
"projects/some-gce-project"
,
&
ResourceID
{
"some-gce-project"
,
"projects"
,
nil
},
&
ResourceID
{
"some-gce-project"
,
"projects"
,
nil
},
},
},
...
@@ -103,7 +115,6 @@ func TestParseResourceURL(t *testing.T) {
...
@@ -103,7 +115,6 @@ func TestParseResourceURL(t *testing.T) {
"projects/some-gce-project/global/foo/bar/baz"
,
"projects/some-gce-project/global/foo/bar/baz"
,
"projects/some-gce-project/zones/us-central1-c/res"
,
"projects/some-gce-project/zones/us-central1-c/res"
,
"projects/some-gce-project/zones/us-central1-c/res/name/extra"
,
"projects/some-gce-project/zones/us-central1-c/res/name/extra"
,
"https://www.googleapis.com/compute/gamma/projects/some-gce-project/global/addresses/name"
,
}
{
}
{
r
,
err
:=
ParseResourceURL
(
tc
)
r
,
err
:=
ParseResourceURL
(
tc
)
if
err
==
nil
{
if
err
==
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment