func (cmd *ATCCommand) configureOAuthProviders(logger lager.Logger, sqlDB db.DB) error { var err error team := db.Team{ Name: atc.DefaultTeamName, } gitHubTeams := []db.GitHubTeam{} for _, gitHubTeam := range cmd.GitHubAuth.Teams { gitHubTeams = append(gitHubTeams, db.GitHubTeam{ TeamName: gitHubTeam.TeamName, OrganizationName: gitHubTeam.OrganizationName, }) } if len(cmd.GitHubAuth.Organizations) > 0 || len(gitHubTeams) > 0 || len(cmd.GitHubAuth.Users) > 0 { gitHubAuth := db.GitHubAuth{ ClientID: cmd.GitHubAuth.ClientID, ClientSecret: cmd.GitHubAuth.ClientSecret, Organizations: cmd.GitHubAuth.Organizations, Teams: gitHubTeams, Users: cmd.GitHubAuth.Users, AuthURL: cmd.GitHubAuth.AuthURL, TokenURL: cmd.GitHubAuth.TokenURL, APIURL: cmd.GitHubAuth.APIURL, } team.GitHubAuth = gitHubAuth } else { team.GitHubAuth = db.GitHubAuth{} } _, err = sqlDB.UpdateTeamGitHubAuth(team) if err != nil { return err } return nil }
}) }) }) Describe("Get Team by name", func() { Context("when team does not exist", func() { It("returns false with no error", func() { _, found, err := database.GetTeamByName("Venture") Expect(err).NotTo(HaveOccurred()) Expect(found).To(BeFalse()) }) }) }) Describe("UpdateTeam", func() { var basicAuthTeam, gitHubAuthTeam db.Team BeforeEach(func() { expectedTeam := db.Team{ Name: "avengers", } _, err := database.SaveTeam(expectedTeam) Expect(err).NotTo(HaveOccurred()) basicAuthTeam = db.Team{ Name: "avengers", BasicAuth: db.BasicAuth{ BasicAuthUsername: "******", BasicAuthPassword: "******", }, }
func (s *Server) SetTeam(w http.ResponseWriter, r *http.Request) { hLog := s.logger.Session("create-team") _, _, isAdmin, found := auth.GetTeam(r) if !found { w.WriteHeader(http.StatusInternalServerError) return } if !isAdmin { w.WriteHeader(http.StatusForbidden) return } teamName := r.FormValue(":team_name") var team db.Team err := json.NewDecoder(r.Body).Decode(&team) if err != nil { hLog.Error("malformed-request", err) w.WriteHeader(http.StatusBadRequest) return } team.Name = teamName err = s.validate(team) if err != nil { hLog.Error("request-body-validation-error", err) w.WriteHeader(http.StatusBadRequest) return } savedTeam, found, err := s.db.GetTeamByName(team.Name) if err != nil { hLog.Error("failed-to-get-team", err) w.WriteHeader(http.StatusInternalServerError) return } if found { err = s.updateCredentials(team) if err != nil { hLog.Error("failed-to-update-team", err) w.WriteHeader(http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) } else { savedTeam, err = s.db.SaveTeam(team) if err != nil { hLog.Error("failed-to-save-team", err) w.WriteHeader(http.StatusInternalServerError) return } w.WriteHeader(http.StatusCreated) } json.NewEncoder(w).Encode(present.Team(savedTeam)) }