Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
keystore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
id
keystore
Commits
e7fb4821
Commit
e7fb4821
authored
7 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Add a client package
parent
8c19ba4e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/client.go
+78
-0
78 additions, 0 deletions
client/client.go
with
78 additions
and
0 deletions
client/client.go
0 → 100644
+
78
−
0
View file @
e7fb4821
package
client
import
(
"context"
"crypto/tls"
"net/http"
"net/url"
"time"
"git.autistici.org/ai3/go-common/clientutil"
"git.autistici.org/id/keystore"
)
// Client for the keystore API.
type
Client
struct
{
*
http
.
Client
backendURL
string
}
// Config for a keystore client.
type
Config
struct
{
BackendURL
string
`yaml:"backend_url"`
TLSConfig
*
clientutil
.
TLSClientConfig
`yaml:"tls_config"`
}
// New returns a new Client with the given Config.
func
New
(
config
*
Config
)
(
*
Client
,
error
)
{
u
,
err
:=
url
.
Parse
(
config
.
BackendURL
)
if
err
!=
nil
{
return
nil
,
err
}
var
tlsConfig
*
tls
.
Config
if
config
.
TLSConfig
!=
nil
{
tlsConfig
,
err
=
config
.
TLSConfig
.
TLSConfig
()
if
err
!=
nil
{
return
nil
,
err
}
}
c
:=
&
http
.
Client
{
Transport
:
clientutil
.
NewTransport
([]
string
{
u
.
Host
},
tlsConfig
,
nil
),
Timeout
:
20
*
time
.
Second
,
}
return
&
Client
{
Client
:
c
,
backendURL
:
config
.
BackendURL
,
},
nil
}
func
(
c
*
Client
)
Open
(
ctx
context
.
Context
,
username
,
password
string
,
ttl
int
)
error
{
req
:=
keystore
.
OpenRequest
{
Username
:
username
,
Password
:
password
,
TTL
:
ttl
,
}
var
resp
keystore
.
OpenResponse
return
clientutil
.
DoJSONHTTPRequest
(
ctx
,
c
.
Client
,
c
.
backendURL
+
"/api/open"
,
&
req
,
&
resp
)
}
func
(
c
*
Client
)
Get
(
ctx
context
.
Context
,
username
,
ssoTicket
string
)
([]
byte
,
error
)
{
req
:=
keystore
.
GetRequest
{
Username
:
username
,
SSOTicket
:
ssoTicket
,
}
var
resp
keystore
.
GetResponse
err
:=
clientutil
.
DoJSONHTTPRequest
(
ctx
,
c
.
Client
,
c
.
backendURL
+
"/api/get"
,
&
req
,
&
resp
)
return
resp
.
Key
,
err
}
func
(
c
*
Client
)
Close
(
ctx
context
.
Context
,
username
string
)
error
{
req
:=
keystore
.
CloseRequest
{
Username
:
username
,
}
var
resp
keystore
.
CloseResponse
return
clientutil
.
DoJSONHTTPRequest
(
ctx
,
c
.
Client
,
c
.
backendURL
+
"/api/close"
,
&
req
,
&
resp
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment