func (req LoginRequirement) Execute() (success bool) { if !req.config.IsLoggedIn() { req.ui.Say(terminal.NotLoggedInText()) return false } return true }
func (req ValidAccessTokenRequirement) Execute() (success bool) { _, apiResponse := req.appRepo.Read("checking_for_valid_access_token") if apiResponse.IsNotSuccessful() && apiResponse.StatusCode == 401 { req.ui.Say(terminal.NotLoggedInText()) return false } return true }
func (req ValidAccessTokenRequirement) Execute() (success bool) { _, apiErr := req.appRepo.FindByName("checking_for_valid_access_token") if apiErr != nil && apiErr.StatusCode == 401 { req.ui.Say(terminal.NotLoggedInText()) return false } return true }
func (req ValidAccessTokenRequirement) Execute() (success bool) { _, apiErr := req.appRepo.Read("checking_for_valid_access_token") if httpResp, ok := apiErr.(errors.HttpError); ok { if httpResp.StatusCode() == 401 { req.ui.Say(terminal.NotLoggedInText()) return false } } return true }
func (uaa UAAAuthenticationRepository) RefreshAuthToken() (updatedToken string, apiErr error) { data := url.Values{ "refresh_token": {uaa.config.RefreshToken()}, "grant_type": {"refresh_token"}, "scope": {""}, } apiErr = uaa.getAuthToken(data) updatedToken = uaa.config.AccessToken() if apiErr != nil { fmt.Printf("%s\n\n", terminal.NotLoggedInText()) os.Exit(1) } return }
func (uaa UAAAuthenticator) RefreshAuthToken() (updatedToken string, apiErr *net.ApiError) { data := url.Values{ "refresh_token": {uaa.config.RefreshToken}, "grant_type": {"refresh_token"}, "scope": {""}, } apiErr = uaa.getAuthToken(data) updatedToken = uaa.config.AccessToken if apiErr != nil && apiErr.StatusCode == 401 { fmt.Printf("%s\n\n", terminal.NotLoggedInText()) os.Exit(1) } return }
func (cmd Api) setNewApiEndpoint(endpoint string) { cmd.ui.Say("Setting api endpoint to %s...", term.EntityNameColor(endpoint)) request, apiErr := cmd.gateway.NewRequest("GET", endpoint+"/v2/info", "", nil) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } scheme := request.URL.Scheme if scheme != "http" && scheme != "https" { cmd.ui.Failed("API Endpoints should start with https:// or http://") return } serverResponse := new(InfoResponse) apiErr = cmd.gateway.PerformRequestForJSONResponse(request, &serverResponse) if apiErr != nil { cmd.ui.Failed(apiErr.Error()) return } err := cmd.saveEndpoint(endpoint, serverResponse) if err != nil { cmd.ui.Failed(err.Error()) return } cmd.ui.Ok() if scheme == "http" { cmd.ui.Say(term.WarningColor("\nWarning: Insecure http API Endpoint detected. Secure https API Endpoints are recommended.\n")) } cmd.showApiEndpoint() cmd.ui.Say(term.NotLoggedInText()) }