Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dfss
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mpcs
dfss
Commits
45cd0c5c
Commit
45cd0c5c
authored
May 24, 2016
by
Richer Maximilien
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[c] Add unregister cmd
parent
eacf1637
Pipeline
#2131
passed with stage
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
1 deletion
+71
-1
dfssc/cmd/root.go
dfssc/cmd/root.go
+1
-1
dfssc/cmd/unregister.go
dfssc/cmd/unregister.go
+38
-0
dfssc/user/unregister.go
dfssc/user/unregister.go
+32
-0
No files found.
dfssc/cmd/root.go
View file @
45cd0c5c
...
@@ -58,6 +58,6 @@ func init() {
...
@@ -58,6 +58,6 @@ func init() {
_
=
viper
.
BindPFlag
(
"timeout"
,
RootCmd
.
PersistentFlags
()
.
Lookup
(
"timeout"
))
_
=
viper
.
BindPFlag
(
"timeout"
,
RootCmd
.
PersistentFlags
()
.
Lookup
(
"timeout"
))
// Bind subcommands to root
// Bind subcommands to root
RootCmd
.
AddCommand
(
dfss
.
VersionCmd
,
registerCmd
,
authCmd
,
newCmd
,
showCmd
,
fetchCmd
,
importCmd
,
exportCmd
,
signCmd
)
RootCmd
.
AddCommand
(
dfss
.
VersionCmd
,
registerCmd
,
authCmd
,
newCmd
,
showCmd
,
fetchCmd
,
importCmd
,
exportCmd
,
signCmd
,
unregisterCmd
)
}
}
dfssc/cmd/unregister.go
0 → 100644
View file @
45cd0c5c
package
cmd
import
(
"fmt"
"os"
"dfss/dfssc/security"
"dfss/dfssc/user"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var
unregisterCmd
=
&
cobra
.
Command
{
Use
:
"unregister"
,
Short
:
"delete current client information on platform"
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
// Read info from provided certificate
cert
,
err
:=
security
.
GetCertificate
(
viper
.
GetString
(
"file_cert"
))
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
"An error occurred:"
,
err
.
Error
())
os
.
Exit
(
2
)
}
// Confirmation
var
ready
string
readStringParam
(
"Do you REALLY want to delete "
+
cert
.
Subject
.
CommonName
+
"? Type 'yes' to confirm"
,
""
,
&
ready
)
if
ready
!=
"yes"
{
fmt
.
Println
(
"Unregistering aborted!"
)
os
.
Exit
(
1
)
}
err
=
user
.
Unregister
()
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
"Error: cannot unregister:"
,
err
.
Error
())
os
.
Exit
(
2
)
}
},
}
dfssc/user/unregister.go
0 → 100644
View file @
45cd0c5c
package
user
import
(
"errors"
"golang.org/x/net/context"
"google.golang.org/grpc"
pb
"dfss/dfssp/api"
"dfss/net"
)
// Unregister a user from the platform
func
Unregister
()
error
{
client
,
err
:=
connect
()
if
err
!=
nil
{
return
err
}
// Stop the context if it takes too long for the platform to answer
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
net
.
DefaultTimeout
)
defer
cancel
()
response
,
err
:=
client
.
Unregister
(
ctx
,
&
pb
.
Empty
{})
if
err
!=
nil
{
return
errors
.
New
(
grpc
.
ErrorDesc
(
err
))
}
if
response
.
Code
!=
pb
.
ErrorCode_SUCCESS
{
return
errors
.
New
(
response
.
Message
)
}
return
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