Skip to content

Commit

Permalink
cmd,internal,servies: add update auth token request
Browse files Browse the repository at this point in the history
  • Loading branch information
cuonglm committed Mar 10, 2020
1 parent d7d889e commit 3670416
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cmd/agola/cmd/remotesourceupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type remoteSourceUpdateOptions struct {

newName string
apiURL string
authToken string
skipVerify bool
oauth2ClientID string
oauth2ClientSecret string
Expand All @@ -56,6 +57,7 @@ func init() {
flags.StringVarP(&remoteSourceUpdateOpts.ref, "ref", "", "", "current remotesource name or id")
flags.StringVarP(&remoteSourceUpdateOpts.newName, "new-name", "", "", "remotesource new name")
flags.StringVar(&remoteSourceUpdateOpts.apiURL, "api-url", "", "remotesource api url")
flags.StringVar(&remoteSourceUpdateOpts.authToken, "auth-token", "", "remotesource auth token")
flags.BoolVarP(&remoteSourceUpdateOpts.skipVerify, "skip-verify", "", false, "skip remote source api tls certificate verification")
flags.StringVar(&remoteSourceUpdateOpts.oauth2ClientID, "clientid", "", "remotesource oauth2 client id")
flags.StringVar(&remoteSourceUpdateOpts.oauth2ClientSecret, "secret", "", "remotesource oauth2 secret")
Expand Down Expand Up @@ -83,6 +85,9 @@ func remoteSourceUpdate(cmd *cobra.Command, args []string) error {
if flags.Changed("api-url") {
req.APIURL = &remoteSourceUpdateOpts.apiURL
}
if flags.Changed("auth-token") {
req.AuthToken = &remoteSourceUpdateOpts.authToken
}
if flags.Changed("skip-verify") {
req.SkipVerify = &remoteSourceUpdateOpts.skipVerify
}
Expand Down
2 changes: 1 addition & 1 deletion internal/services/common/gitsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func GetTokenSource(rs *cstypes.RemoteSource, accessToken string) (gitsource.Use
case cstypes.RemoteSourceTypeGitea:
userSource, err = newGitea(rs, accessToken)
default:
return nil, errors.Errorf("remote source %s isn't a valid token source", rs.Name)
return nil, errors.Errorf("remote source %s isn't a valid oauth2 source", rs.Name)
}

return userSource, err
Expand Down
4 changes: 4 additions & 0 deletions internal/services/gateway/action/remotesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type UpdateRemoteSourceRequest struct {

Name *string
APIURL *string
AuthToken *string
SkipVerify *bool
Oauth2ClientID *string
Oauth2ClientSecret *string
Expand All @@ -157,6 +158,9 @@ func (h *ActionHandler) UpdateRemoteSource(ctx context.Context, req *UpdateRemot
if req.APIURL != nil {
rs.APIURL = *req.APIURL
}
if req.AuthToken != nil {
rs.AuthToken = *req.AuthToken
}
if req.SkipVerify != nil {
rs.SkipVerify = *req.SkipVerify
}
Expand Down
1 change: 1 addition & 0 deletions internal/services/gateway/api/remotesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (h *UpdateRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req

Name: req.Name,
APIURL: req.APIURL,
AuthToken: req.AuthToken,
SkipVerify: req.SkipVerify,
Oauth2ClientID: req.Oauth2ClientID,
Oauth2ClientSecret: req.Oauth2ClientSecret,
Expand Down
1 change: 1 addition & 0 deletions services/gateway/api/types/remotesource.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type CreateRemoteSourceRequest struct {
type UpdateRemoteSourceRequest struct {
Name *string `json:"name"`
APIURL *string `json:"apiurl"`
AuthToken *string `json:"auth_token"`
SkipVerify *bool `json:"skip_verify"`
Oauth2ClientID *string `json:"oauth_2_client_id"`
Oauth2ClientSecret *string `json:"oauth_2_client_secret"`
Expand Down

0 comments on commit 3670416

Please sign in to comment.