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
10201f3f
Commit
10201f3f
authored
Feb 22, 2018
by
Di Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
read openstack auth config from client config
parent
44ede98e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
10 deletions
+94
-10
BUILD
...c/k8s.io/client-go/plugin/pkg/client/auth/openstack/BUILD
+1
-0
openstack.go
...o/client-go/plugin/pkg/client/auth/openstack/openstack.go
+36
-10
openstack_test.go
...ent-go/plugin/pkg/client/auth/openstack/openstack_test.go
+57
-0
No files found.
staging/src/k8s.io/client-go/plugin/pkg/client/auth/openstack/BUILD
View file @
10201f3f
...
...
@@ -18,6 +18,7 @@ go_library(
importpath = "k8s.io/client-go/plugin/pkg/client/auth/openstack",
deps = [
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
"//vendor/github.com/gophercloud/gophercloud/openstack:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
...
...
staging/src/k8s.io/client-go/plugin/pkg/client/auth/openstack/openstack.go
View file @
10201f3f
...
...
@@ -23,6 +23,7 @@ import (
"time"
"github.com/golang/glog"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"k8s.io/apimachinery/pkg/util/net"
...
...
@@ -42,8 +43,7 @@ const DefaultTTLDuration = 10 * time.Minute
// the environment variables to determine the client identity, and generates a
// token which will be inserted into the request header later.
type
openstackAuthProvider
struct
{
ttl
time
.
Duration
ttl
time
.
Duration
tokenGetter
TokenGetter
}
...
...
@@ -52,13 +52,23 @@ type TokenGetter interface {
Token
()
(
string
,
error
)
}
type
tokenGetter
struct
{}
type
tokenGetter
struct
{
authOpt
*
gophercloud
.
AuthOptions
}
// Token creates a token by authenticate with keystone.
func
(
*
tokenGetter
)
Token
()
(
string
,
error
)
{
options
,
err
:=
openstack
.
AuthOptionsFromEnv
()
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to read openstack env vars: %s"
,
err
)
func
(
t
*
tokenGetter
)
Token
()
(
string
,
error
)
{
var
options
gophercloud
.
AuthOptions
var
err
error
if
t
.
authOpt
==
nil
{
// reads the config from the environment
glog
.
V
(
4
)
.
Info
(
"reading openstack config from the environment variables"
)
options
,
err
=
openstack
.
AuthOptionsFromEnv
()
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to read openstack env vars: %s"
,
err
)
}
}
else
{
options
=
*
t
.
authOpt
}
client
,
err
:=
openstack
.
AuthenticatedClient
(
options
)
if
err
!=
nil
{
...
...
@@ -126,7 +136,7 @@ func (t *tokenRoundTripper) WrappedRoundTripper() http.RoundTripper { return t.R
// newOpenstackAuthProvider creates an auth provider which works with openstack
// environment.
func
newOpenstackAuthProvider
(
clusterAddress
string
,
config
map
[
string
]
string
,
persister
restclient
.
AuthProviderConfigPersister
)
(
restclient
.
AuthProvider
,
error
)
{
func
newOpenstackAuthProvider
(
_
string
,
config
map
[
string
]
string
,
persister
restclient
.
AuthProviderConfigPersister
)
(
restclient
.
AuthProvider
,
error
)
{
var
ttlDuration
time
.
Duration
var
err
error
...
...
@@ -145,11 +155,27 @@ func newOpenstackAuthProvider(clusterAddress string, config map[string]string, p
}
}
// TODO: read/persist client configuration(OS_XXX env vars) in config
authOpt
:=
gophercloud
.
AuthOptions
{
IdentityEndpoint
:
config
[
"identityEndpoint"
],
Username
:
config
[
"username"
],
Password
:
config
[
"password"
],
DomainName
:
config
[
"name"
],
TenantID
:
config
[
"tenantId"
],
TenantName
:
config
[
"tenantName"
],
}
getter
:=
tokenGetter
{}
// not empty
if
(
authOpt
!=
gophercloud
.
AuthOptions
{})
{
if
len
(
authOpt
.
IdentityEndpoint
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"empty %q in the config for openstack auth provider"
,
"identityEndpoint"
)
}
getter
.
authOpt
=
&
authOpt
}
return
&
openstackAuthProvider
{
ttl
:
ttlDuration
,
tokenGetter
:
&
tokenGetter
{}
,
tokenGetter
:
&
getter
,
},
nil
}
...
...
staging/src/k8s.io/client-go/plugin/pkg/client/auth/openstack/openstack_test.go
View file @
10201f3f
...
...
@@ -114,3 +114,60 @@ func TestOpenstackAuthProvider(t *testing.T) {
}
}
type
fakePersister
struct
{}
func
(
i
*
fakePersister
)
Persist
(
map
[
string
]
string
)
error
{
return
nil
}
func
TestNewOpenstackAuthProvider
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
config
map
[
string
]
string
expectError
bool
}{
{
name
:
"normal config without openstack configurations"
,
config
:
map
[
string
]
string
{
"ttl"
:
"1s"
,
"foo"
:
"bar"
,
},
},
{
name
:
"openstack auth provider: missing identityEndpoint"
,
config
:
map
[
string
]
string
{
"ttl"
:
"1s"
,
"foo"
:
"bar"
,
"username"
:
"xyz"
,
"password"
:
"123"
,
"tenantName"
:
"admin"
,
},
expectError
:
true
,
},
{
name
:
"openstack auth provider"
,
config
:
map
[
string
]
string
{
"ttl"
:
"1s"
,
"foo"
:
"bar"
,
"identityEndpoint"
:
"http://controller:35357/v3"
,
"username"
:
"xyz"
,
"password"
:
"123"
,
"tenantName"
:
"admin"
,
},
},
}
for
_
,
test
:=
range
tests
{
_
,
err
:=
newOpenstackAuthProvider
(
"test"
,
test
.
config
,
&
fakePersister
{})
if
err
!=
nil
{
if
!
test
.
expectError
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
else
{
if
test
.
expectError
{
t
.
Error
(
"expect error, but 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