Przeglądaj źródła

requested changes (no docs yet)

Ivan Galakhov 4 lat temu
rodzic
commit
a6e992129c

+ 1 - 0
cmd/app/main.go

@@ -73,6 +73,7 @@ func main() {
 		&ints.RegTokenCache{},
 		&ints.HelmRepoTokenCache{},
 		&ints.GithubAppInstallation{},
+		&ints.GithubAppOAuthIntegration{},
 	)
 
 	if err != nil {

+ 0 - 1
cmd/migrate/main.go

@@ -59,7 +59,6 @@ func main() {
 		&ints.HelmRepoTokenCache{},
 		&ints.GithubAppInstallation{},
 		&ints.GithubAppOAuthIntegration{},
-		&ints.GithubAppOAuthIntegration{},
 	)
 
 	if err != nil {

+ 11 - 0
internal/repository/gorm/auth.go

@@ -1093,10 +1093,12 @@ type GithubAppInstallationRepository struct {
 	db *gorm.DB
 }
 
+// NewGithubAppInstallationRepository creates a new GithubAppInstallationRepository
 func NewGithubAppInstallationRepository(db *gorm.DB) repository.GithubAppInstallationRepository {
 	return &GithubAppInstallationRepository{db}
 }
 
+// CreateGithubAppInstallation creates a new GithubAppInstallation instance
 func (repo *GithubAppInstallationRepository) CreateGithubAppInstallation(am *ints.GithubAppInstallation) (*ints.GithubAppInstallation, error) {
 	if err := repo.db.Create(am).Error; err != nil {
 		return nil, err
@@ -1104,6 +1106,7 @@ func (repo *GithubAppInstallationRepository) CreateGithubAppInstallation(am *int
 	return am, nil
 }
 
+// ReadGithubAppInstallation finds a GithubAppInstallation by id
 func (repo *GithubAppInstallationRepository) ReadGithubAppInstallation(id uint) (*ints.GithubAppInstallation, error) {
 	ret := &ints.GithubAppInstallation{}
 
@@ -1114,6 +1117,7 @@ func (repo *GithubAppInstallationRepository) ReadGithubAppInstallation(id uint)
 	return ret, nil
 }
 
+// ReadGithubAppInstallationByAccountID finds a GithubAppInstallation by an account ID
 func (repo *GithubAppInstallationRepository) ReadGithubAppInstallationByAccountID(accountID int64) (*ints.GithubAppInstallation, error) {
 
 	ret := &ints.GithubAppInstallation{}
@@ -1125,6 +1129,8 @@ func (repo *GithubAppInstallationRepository) ReadGithubAppInstallationByAccountI
 	return ret, nil
 }
 
+// ReadGithubAppInstallationByAccountIDs finds all instances of GithubInstallations given a list of account IDs
+// note that if there is not Installation for a given ID, no error will be generated
 func (repo *GithubAppInstallationRepository) ReadGithubAppInstallationByAccountIDs(accountIDs []int64) ([]*ints.GithubAppInstallation, error) {
 	ret := make([]*ints.GithubAppInstallation, 0)
 
@@ -1135,6 +1141,8 @@ func (repo *GithubAppInstallationRepository) ReadGithubAppInstallationByAccountI
 	return ret, nil
 }
 
+// DeleteGithubAppInstallationByAccountID deletes a GithubAppInstallation given an account ID
+// note that this deletion is done with db.Unscoped(), so the record is actually deleted
 func (repo *GithubAppInstallationRepository) DeleteGithubAppInstallationByAccountID(accountID int64) error {
 	if err := repo.db.Unscoped().Where("account_id = ?", accountID).Delete(&ints.GithubAppInstallation{}).Error; err != nil {
 		return err
@@ -1148,10 +1156,12 @@ type GithubAppOAuthIntegrationRepository struct {
 	db *gorm.DB
 }
 
+// NewGithubAppOAuthIntegrationRepository creates a GithubAppOAuthIntegrationRepository
 func NewGithubAppOAuthIntegrationRepository(db *gorm.DB) repository.GithubAppOAuthIntegrationRepository {
 	return &GithubAppOAuthIntegrationRepository{db}
 }
 
+// CreateGithubAppOAuthIntegration creates a new GithubAppOAuthIntegration
 func (repo *GithubAppOAuthIntegrationRepository) CreateGithubAppOAuthIntegration(am *ints.GithubAppOAuthIntegration) (*ints.GithubAppOAuthIntegration, error) {
 	if err := repo.db.Create(am).Error; err != nil {
 		return nil, err
@@ -1159,6 +1169,7 @@ func (repo *GithubAppOAuthIntegrationRepository) CreateGithubAppOAuthIntegration
 	return am, nil
 }
 
+// ReadGithubAppOauthIntegration finds a GithubAppOauthIntegration by id
 func (repo *GithubAppOAuthIntegrationRepository) ReadGithubAppOauthIntegration(id uint) (*ints.GithubAppOAuthIntegration, error) {
 	ret := &ints.GithubAppOAuthIntegration{}
 

+ 4 - 0
server/api/integration_handler.go

@@ -451,16 +451,20 @@ func (app *App) HandleGithubAppAuthorize(w http.ResponseWriter, r *http.Request)
 	http.Redirect(w, r, url, 302)
 }
 
+// HandleGithubAppInstall redirects the user to the Porter github app installation page
 func (app *App) HandleGithubAppInstall(w http.ResponseWriter, r *http.Request) {
 	http.Redirect(w, r, fmt.Sprintf("https://github.com/apps/%s/installations/new", app.GithubAppConf.AppName), 302)
 }
 
+// HandleListGithubAppAccessResp is the response returned by HandleListGithubAppAccess
 type HandleListGithubAppAccessResp struct {
 	HasAccess bool     `json:"has_access"`
 	LoginName string   `json:"username,omitempty"`
 	Accounts  []string `json:"accounts,omitempty"`
 }
 
+// HandleListGithubAppAccess provides basic info on if the current user is authenticated through the GitHub app
+// and what accounts/organizations their authentication has access to
 func (app *App) HandleListGithubAppAccess(w http.ResponseWriter, r *http.Request) {
 	tok, err := app.getGithubUserTokenFromRequest(r)
 

+ 2 - 2
server/api/oauth_github_handler.go

@@ -297,11 +297,11 @@ func (app *App) updateProjectFromToken(projectID uint, userID uint, tok *oauth2.
 	return err
 }
 
+// HandleGithubAppOAuthCallback handles the oauth callback from the GitHub app oauth flow
+// this basically just involves generating an access token and then linking it to the current user
 func (app *App) HandleGithubAppOAuthCallback(w http.ResponseWriter, r *http.Request) {
 	session, err := app.Store.Get(r, app.ServerConf.CookieName)
 
-	fmt.Println("hello...")
-
 	if err != nil {
 		app.handleErrorDataRead(err, w)
 		return