Skip to content

Commit

Permalink
Merge branch 'open-horizon:master' into Issue-open-horizon#4115
Browse files Browse the repository at this point in the history
  • Loading branch information
adhishreekadam authored Aug 1, 2024
2 parents df5cac2 + 760633f commit c8361a8
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 42 deletions.
14 changes: 8 additions & 6 deletions agreementbot/persistence/postgresql/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ func (db *AgbotPostgresqlDB) Initialize(cfg *config.HorizonConfig) error {
for si := 0; si < len(migrationSQL[v].sql); si++ {
if _, err := db.db.Exec(migrationSQL[v].sql[si]); err != nil {
return errors.New(fmt.Sprintf("unable to run SQL migration statement version %v, index %v, statement %v, error: %v", v, si, migrationSQL[v].sql[si], err))
} else if _, err := db.db.Exec(VERSION_UPDATE, HIGHEST_DATABASE_VERSION, migrationSQL[v].description); err != nil {
return errors.New(fmt.Sprintf("unable to create version table, error: %v", err))
} else {
glog.V(3).Infof("Postgresql database tables upgraded to version %v, %v", v, migrationSQL[v].description)
}
}
}
glog.V(3).Infof("Postgresql database tables upgraded for version %v, %v", v, migrationSQL[v].description)

glog.V(3).Infof("Postgresql database tables upgraded to version %v", HIGHEST_DATABASE_VERSION)
if _, err := db.db.Exec(VERSION_UPDATE, v, migrationSQL[v].description); err != nil {
return errors.New(fmt.Sprintf("unable to create version table, error: %v", err))
} else {
glog.V(3).Infof("Postgresql database tables upgraded to version %v, %v", v, migrationSQL[v].description)
}
}
glog.V(3).Infof("Finished upgrading postgresql database tables. The version is now %v", HIGHEST_DATABASE_VERSION)
}

glog.V(3).Infof("Postgresql database tables initialized.")
Expand Down
7 changes: 5 additions & 2 deletions agreementbot/persistence/postgresql/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ END $$`

const VERSION_UPDATE = `UPDATE version SET ver = $1, description = $2, updated = current_timestamp WHERE id = 1;`

const HIGHEST_DATABASE_VERSION = v1
const HIGHEST_DATABASE_VERSION = v2
const v2 = 1
const v1 = 0

type SchemaUpdate struct {
sql []string // The SQL statements to run for an update to the schema.
description string // A description of the schema change.
}

var migrationSQL = map[int]SchemaUpdate{}
var v2SchemaUpdate = SchemaUpdate{sql: []string{"ALTER TABLE secrets_policy ADD COLUMN IF NOT EXISTS \"secret_exists\" BOOLEAN NOT NULL DEFAULT true;", "ALTER TABLE secrets_pattern ADD COLUMN IF NOT EXISTS \"secret_exists\" BOOLEAN NOT NULL DEFAULT true;"}, description: "Add a column to the secrets table to indicate if the secret exists or not. This is necessary to support node-specific secrets."}

var migrationSQL = map[int]SchemaUpdate{v2: v2SchemaUpdate}
38 changes: 19 additions & 19 deletions cli/cliutils/cliutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,29 +1098,29 @@ func GetIcpCertPath() string {

// TrustIcpCert adds the icp cert file to be trusted in calls made by the given http client
func TrustIcpCert(httpClient *http.Client) error {
icpCertPath := GetIcpCertPath()
icpCertPath := GetIcpCertPath()

var caCertPool *x509.CertPool
var err error
var caCertPool *x509.CertPool
var err error

// Trust the system certs like the anax agent code can
caCertPool, err = x509.SystemCertPool()
if err != nil {
// Trust the system certs like the anax agent code can
caCertPool, err = x509.SystemCertPool()
if err != nil {
// Decided not to fail and return here but just create a new pool
caCertPool = x509.NewCertPool()
}

if icpCertPath != "" {
icpCert, err := ioutil.ReadFile(icpCertPath)
if err != nil {
return fmt.Errorf(i18n.GetMessagePrinter().Sprintf("Encountered error reading ICP cert file %v: %v", icpCertPath, err))
}
caCertPool.AppendCertsFromPEM(icpCert)
}

transport := httpClient.Transport.(*http.Transport)
transport.TLSClientConfig.RootCAs = caCertPool
return nil
}

if icpCertPath != "" {
icpCert, err := ioutil.ReadFile(icpCertPath)
if err != nil {
return fmt.Errorf(i18n.GetMessagePrinter().Sprintf("Encountered error reading ICP cert file %v: %v", icpCertPath, err))
}
caCertPool.AppendCertsFromPEM(icpCert)
}

transport := httpClient.Transport.(*http.Transport)
transport.TLSClientConfig.RootCAs = caCertPool
return nil
}

// Get exchange url from /etc/default/horizon file. if not set, check /etc/horizon/anax.json file
Expand Down
14 changes: 7 additions & 7 deletions cli/eventlog/eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func Delete(selections []string, force bool) {
retCode, count := cliutils.HorizonDelete(url_s, []int{204}, []int{200}, false)

if retCode == http.StatusOK {
fmt.Println(i18n.GetMessagePrinter().Sprintf("Successfully deleted %v matching event log entries.", cliutils.RemoveQuotes(fmt.Sprintf("%v",count))))
fmt.Println(i18n.GetMessagePrinter().Sprintf("Successfully deleted %v matching event log entries.", cliutils.RemoveQuotes(fmt.Sprintf("%v", count))))
} else {
fmt.Println(i18n.GetMessagePrinter().Sprintf("No event log entries matching the given selectors were found."))
}
Expand All @@ -97,13 +97,13 @@ func Prune(force bool) {
cliutils.ConfirmRemove(i18n.GetMessagePrinter().Sprintf("Are you sure you want to remove all event logs from previous registrations?"))
}

retCode, count := cliutils.HorizonDelete(url, []int{204}, []int{200}, false)
retCode, count := cliutils.HorizonDelete(url, []int{204}, []int{200}, false)

if retCode == http.StatusOK {
fmt.Println(i18n.GetMessagePrinter().Sprintf("Successfully pruned %v matching event log entries.", cliutils.RemoveQuotes(fmt.Sprintf("%v",count))))
} else {
fmt.Println(i18n.GetMessagePrinter().Sprintf("No event log entries from previous registrations were found."))
}
if retCode == http.StatusOK {
fmt.Println(i18n.GetMessagePrinter().Sprintf("Successfully pruned %v matching event log entries.", cliutils.RemoveQuotes(fmt.Sprintf("%v", count))))
} else {
fmt.Println(i18n.GetMessagePrinter().Sprintf("No event log entries from previous registrations were found."))
}
}

func List(all bool, detail bool, selections []string, tailing bool) {
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ require (
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/docker/cli v24.0.6+incompatible // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/docker v27.1.1+incompatible // indirect
github.com/docker/docker-credential-helpers v0.8.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
Expand All @@ -99,6 +99,7 @@ require (
github.com/klauspost/compress v1.16.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
Expand Down Expand Up @@ -143,7 +144,7 @@ require (

replace (
github.com/containerd/containerd => github.com/containerd/containerd v1.6.18
github.com/docker/docker => github.com/docker/docker v25.0.5+incompatible
github.com/docker/docker => github.com/docker/docker v27.1.1+incompatible
github.com/opencontainers/runc => github.com/opencontainers/runc v1.1.5
golang.org/x/crypto => golang.org/x/crypto v0.18.0
golang.org/x/text => golang.org/x/text v0.5.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUM
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.12.0-rc.0 h1:wX/F5huJxH9APBkhKSEAqaiZsuBvbbDnyBROZAqsSaY=
github.com/Microsoft/hcsshim v0.12.0-rc.0/go.mod h1:rvOnw3YlfoNnEp45wReUngvsXbwRW+AFQ10GVjG1kMU=
github.com/adams-sarah/prettytest v0.0.0-20150503061827-2880862ae7f5 h1:Asp4eRWQ0c1fqnY5+sTndqAjp/LCsmOy8wozEJLaNQs=
github.com/adams-sarah/prettytest v0.0.0-20150503061827-2880862ae7f5/go.mod h1:p2ev/QMGYqQo5byMwvkLP4vnZdCJYlFHwhmCII3aj3E=
github.com/adams-sarah/test2doc v0.0.0-20211124171229-79cd42e7411d h1:aSpAz6pKUc/UoAwTjYOLxfavWCfdGoS67TNlnwHXWC4=
Expand Down Expand Up @@ -103,8 +101,8 @@ github.com/docker/cli v24.0.6+incompatible h1:fF+XCQCgJjjQNIMjzaSmiKJSCcfcXb3TWT
github.com/docker/cli v24.0.6+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v25.0.5+incompatible h1:UmQydMduGkrD5nQde1mecF/YnSbTOaPeFIeP5C4W+DE=
github.com/docker/docker v25.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v27.1.1+incompatible h1:hO/M4MtV36kzKldqnA37IWhebRA+LnqqcqDja6kVaKY=
github.com/docker/docker v27.1.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0=
github.com/docker/docker-credential-helpers v0.8.0 h1:YQFtbBQb4VrpoPxhFuzEBPQ9E16qz5SpHLS+uswaCp8=
github.com/docker/docker-credential-helpers v0.8.0/go.mod h1:UGFXcuoQ5TxPiB54nHOZ32AWRqQdECoh/Mg0AlEYb40=
Expand Down Expand Up @@ -201,6 +199,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc=
Expand Down
4 changes: 2 additions & 2 deletions persistence/eventlogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (w EventLogBase) Matches(selectors map[string][]Selector) bool {
case "timestamp":
attr = w.Timestamp
case "time_since":
attr = (uint64(time.Now().Unix()) - w.Timestamp)/3600
attr = (uint64(time.Now().Unix()) - w.Timestamp) / 3600
default:
return false // not tolerate wrong attribute name in the selector
}
Expand Down Expand Up @@ -436,7 +436,7 @@ func DeleteEventLogsWithSelectors(db *bolt.DB, selectors map[string][]Selector,
glog.Errorf("Unable to convert event source: %v. Error: %v", el.Source, err)
} else if (*esrc).Matches(source_selectors) {
b.Delete(k)
count ++
count++
}
}
}
Expand Down

0 comments on commit c8361a8

Please sign in to comment.