Skip to content

Commit

Permalink
fix: add temp fix for go lint error so that this can be reviewed
Browse files Browse the repository at this point in the history
  • Loading branch information
carddev81 committed Oct 30, 2024
1 parent 4973ae6 commit 864dc92
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions provider-middleware/brightspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package main

import (
"UnlockEdv2/src/models"
"errors"
"net/http"
"net/url"
"os"
"strings"
"time"

"gorm.io/gorm"
Expand All @@ -27,9 +31,40 @@ type BrightspaceService struct {
JobParams *map[string]interface{}
}

func newBrightspaceService(provider *models.ProviderPlatform, db *gorm.DB, params *map[string]interface{}) (*BrightspaceService, error) {
//create new instance of BrightspaceService
return nil, nil
// for linting reasons changed new to New below temporarily so this can be reviewed,
func NewBrightspaceService(provider *models.ProviderPlatform, db *gorm.DB, params *map[string]interface{}) (*BrightspaceService, error) {
keysSplit := strings.Split(provider.AccessKey, ";")
if len(keysSplit) < 2 {
return nil, errors.New("unable to find refresh token, unable to intialize BrightspaceService")
}
scope := os.Getenv("BRIGHTSPACE_SCOPE")
if scope == "" {
return nil, errors.New("no brightspace scope found, unable to intialize BrightspaceService")
}
brightspaceService := BrightspaceService{
//brightspace - set fields
JobParams: params,
}
data := url.Values{}
data.Add("grant_type", "refresh_token")
data.Add("refresh_token", brightspaceService.RefreshToken)
data.Add("client_id", brightspaceService.ClientID)
data.Add("client_secret", brightspaceService.ClientSecret)
data.Add("scope", brightspaceService.Scope)
//a send post request to brightspace
//b parse response for access_token and refresh_token
//c save new refresh_token (tack it onto the end of the client secret separated by semicolon)
provider.AccessKey = brightspaceService.ClientSecret + ";" + brightspaceService.RefreshToken
if err := db.Debug().Save(&provider).Error; err != nil {
//send admin email??? maybe but not now
return nil, err
}
//d set headers that are required for requests to brightspace
headers := make(map[string]string)
headers["Authorization"] = "Bearer " + brightspaceService.AccessToken
headers["Accept"] = "application/json"
brightspaceService.BaseHeaders = &headers
return &brightspaceService, nil
}

func (srv *BrightspaceService) GetUsers(db *gorm.DB) ([]models.ImportUser, error) {
Expand Down

0 comments on commit 864dc92

Please sign in to comment.