Skip to content

Commit

Permalink
slim clouds
Browse files Browse the repository at this point in the history
  • Loading branch information
SimoneDutto committed Jan 9, 2025
1 parent 57ef498 commit 8cc9a90
Show file tree
Hide file tree
Showing 66 changed files with 482 additions and 478 deletions.
2 changes: 1 addition & 1 deletion cmd/jimmctl/cmd/purge_logs_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.
package cmd_test

import (
Expand Down
2 changes: 1 addition & 1 deletion cmd/jimmsrv/service/service.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

// service defines the methods necessary to start a JIMM server
// alongside all the config options that can be supplied to configure JIMM.
Expand Down
2 changes: 1 addition & 1 deletion internal/auth/oauth2_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package auth_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/applicationoffer_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/auditlog_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
45 changes: 11 additions & 34 deletions internal/db/cloud_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down Expand Up @@ -29,15 +29,11 @@ func (s *dbSuite) TestAddCloud(c *qt.C) {
ctx := context.Background()

cl := dbmodel.Cloud{
Name: "test-cloud",
Type: "test-provider",
Endpoint: "https://example.com",
IdentityEndpoint: "https://identity.example.com",
StorageEndpoint: "https://storage.example.com",
Name: "test-cloud",
Type: "test-provider",
Regions: []dbmodel.CloudRegion{{
Name: "test-cloud-region",
}},
CACertificates: dbmodel.Strings{"CACERT 1", "CACERT 2"},
}

err := s.Database.AddCloud(ctx, &cl)
Expand Down Expand Up @@ -90,15 +86,11 @@ func (s *dbSuite) TestGetCloud(c *qt.C) {
c.Check(errors.ErrorCode(err), qt.Equals, errors.CodeNotFound)

cl2 := dbmodel.Cloud{
Name: "test-cloud",
Type: "test-provider",
Endpoint: "https://example.com",
IdentityEndpoint: "https://identity.example.com",
StorageEndpoint: "https://storage.example.com",
Name: "test-cloud",
Type: "test-provider",
Regions: []dbmodel.CloudRegion{{
Name: "test-cloud-region",
}},
CACertificates: dbmodel.Strings{"CACERT 1", "CACERT 2"},
}

err = s.Database.AddCloud(ctx, &cl2)
Expand Down Expand Up @@ -131,15 +123,11 @@ func (s *dbSuite) TestGetClouds(c *qt.C) {
c.Check(clouds, qt.HasLen, 0)

cl := dbmodel.Cloud{
Name: "test-cloud",
Type: "test-provider",
Endpoint: "https://example.com",
IdentityEndpoint: "https://identity.example.com",
StorageEndpoint: "https://storage.example.com",
Name: "test-cloud",
Type: "test-provider",
Regions: []dbmodel.CloudRegion{{
Name: "test-cloud-region",
}},
CACertificates: dbmodel.Strings{"CACERT 1", "CACERT 2"},
}

err = s.Database.AddCloud(ctx, &cl)
Expand All @@ -163,15 +151,11 @@ func (s *dbSuite) TestUpdateCloud(c *qt.C) {
ctx := context.Background()

cl := dbmodel.Cloud{
Name: "test-cloud",
Type: "test-provider",
Endpoint: "https://example.com",
IdentityEndpoint: "https://identity.example.com",
StorageEndpoint: "https://storage.example.com",
Name: "test-cloud",
Type: "test-provider",
Regions: []dbmodel.CloudRegion{{
Name: "test-cloud-region",
}},
CACertificates: dbmodel.Strings{"CACERT 1", "CACERT 2"},
}

err := s.Database.UpdateCloud(ctx, &cl)
Expand All @@ -191,9 +175,6 @@ func (s *dbSuite) TestUpdateCloud(c *qt.C) {
c.Assert(err, qt.IsNil)
c.Check(cl2, jimmtest.DBObjectEquals, cl)

cl2.Endpoint = "https://new.example.com"
cl2.IdentityEndpoint = "https://new.identity.example.com"
cl2.StorageEndpoint = "https://new.storage.example.com"
cl2.Regions = append(cl2.Regions, dbmodel.CloudRegion{
Name: "test-cloud-region-2",
Endpoint: "https://new.region.example.com",
Expand Down Expand Up @@ -327,15 +308,11 @@ func (s *dbSuite) TestDeleteCloud(c *qt.C) {
ctx := context.Background()

cl := dbmodel.Cloud{
Name: "test-cloud",
Type: "test-provider",
Endpoint: "https://example.com",
IdentityEndpoint: "https://identity.example.com",
StorageEndpoint: "https://storage.example.com",
Name: "test-cloud",
Type: "test-provider",
Regions: []dbmodel.CloudRegion{{
Name: "test-cloud-region",
}},
CACertificates: dbmodel.Strings{"CACERT 1", "CACERT 2"},
}

err := s.Database.DeleteCloud(ctx, &cl)
Expand Down
2 changes: 1 addition & 1 deletion internal/db/cloudcredential_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/clouddefaults_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/controller_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/db.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

// Package db contains routines to store and retrieve data from a database.
package db
Expand Down
2 changes: 1 addition & 1 deletion internal/db/db_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/export_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db

Expand Down
2 changes: 1 addition & 1 deletion internal/db/group_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/identity_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/model_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/resource_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.
package db_test

import (
Expand Down
2 changes: 1 addition & 1 deletion internal/db/role_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/rootkeys_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
2 changes: 1 addition & 1 deletion internal/db/secrets_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package db_test

Expand Down
72 changes: 8 additions & 64 deletions internal/dbmodel/cloud.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Canonical.
// Copyright 2025 Canonical.

package dbmodel

Expand Down Expand Up @@ -26,29 +26,8 @@ type Cloud struct {
// cloud is hosted.
HostCloudRegion string

// AuthTypes is the authentication types supported by this cloud.
AuthTypes Strings

// Endpoint is the API endpoint URL for the cloud.
Endpoint string

// IdentityEndpoint is the API endpoint URL of the cloud identity
// service.
IdentityEndpoint string

// StorageEndpoint is the API endpoint URL of the cloud storage
// service.
StorageEndpoint string

// Regions contains the regions associated with this cloud.
Regions []CloudRegion `gorm:"foreignKey:CloudName;references:Name"`

// CACertificates contains the CA Certificates associated with this
// cloud.
CACertificates Strings

// Config contains the configuration associated with this cloud.
Config Map
}

// Tag returns a names.Tag for this cloud.
Expand Down Expand Up @@ -82,14 +61,14 @@ func (c Cloud) Region(name string) CloudRegion {

// ToJujuCloud converts the Cloud object into a jujuparams.Cloud. The
// cloud must have its regions association filled out.
func (c Cloud) ToJujuCloud() jujuparams.Cloud {
func (c Cloud) ToJujuCloud(jujuCloud jujuparams.Cloud) jujuparams.Cloud {
var cl jujuparams.Cloud
cl.Type = c.Type
cl.HostCloudRegion = c.HostCloudRegion
cl.AuthTypes = []string(c.AuthTypes)
cl.Endpoint = c.Endpoint
cl.IdentityEndpoint = c.IdentityEndpoint
cl.StorageEndpoint = c.StorageEndpoint
cl.AuthTypes = []string(jujuCloud.AuthTypes)
cl.Endpoint = jujuCloud.Endpoint
cl.IdentityEndpoint = jujuCloud.IdentityEndpoint
cl.StorageEndpoint = jujuCloud.StorageEndpoint
cl.Regions = make([]jujuparams.CloudRegion, len(c.Regions))
cl.RegionConfig = make(map[string]map[string]interface{}, len(c.Regions))
for i, r := range c.Regions {
Expand All @@ -98,8 +77,8 @@ func (c Cloud) ToJujuCloud() jujuparams.Cloud {
cl.RegionConfig[r.Name] = map[string]interface{}(r.Config)
}
}
cl.CACertificates = []string(c.CACertificates)
cl.Config = map[string]interface{}(c.Config)
cl.CACertificates = []string(jujuCloud.CACertificates)
cl.Config = map[string]interface{}(jujuCloud.Config)
return cl
}

Expand All @@ -108,12 +87,6 @@ func (c Cloud) ToJujuCloud() jujuparams.Cloud {
func (c *Cloud) FromJujuCloud(cld jujuparams.Cloud) {
c.Type = cld.Type
c.HostCloudRegion = cld.HostCloudRegion
c.AuthTypes = Strings(cld.AuthTypes)
c.Endpoint = cld.Endpoint
c.IdentityEndpoint = cld.IdentityEndpoint
c.StorageEndpoint = cld.StorageEndpoint
c.CACertificates = Strings(cld.CACertificates)
c.Config = Map(cld.Config)
regions := make([]CloudRegion, 0, len(c.Regions))
for _, r := range cld.Regions {
reg := c.Region(r.Name)
Expand All @@ -124,35 +97,6 @@ func (c *Cloud) FromJujuCloud(cld jujuparams.Cloud) {
c.Regions = regions
}

// ToJujuCloudDetails converts the Cloud object into a
// jujuparams.CloudDetails. The cloud must have its regions association
// filled out.
func (c Cloud) ToJujuCloudDetails() jujuparams.CloudDetails {
var cd jujuparams.CloudDetails
cd.Type = c.Type
cd.AuthTypes = []string(c.AuthTypes)
cd.Endpoint = c.Endpoint
cd.IdentityEndpoint = c.IdentityEndpoint
cd.StorageEndpoint = c.StorageEndpoint
cd.Regions = make([]jujuparams.CloudRegion, len(c.Regions))
for i, r := range c.Regions {
cd.Regions[i] = r.ToJujuCloudRegion()
}
return cd
}

// ToJujuCloudInfo converts the Cloud object into a
// jujuparams.CloudInfo. The cloud must have its regions and users
// associations filled out.
func (c Cloud) ToJujuCloudInfo() jujuparams.CloudInfo {
var ci jujuparams.CloudInfo
ci.CloudDetails = c.ToJujuCloudDetails()
// TODO(Kian) CSS-6040 Determine whether to combine OpenFGA Tuples
// with Postgres data objects for a consolidated view.
ci.Users = nil
return ci
}

// A CloudRegion is a region of a cloud.
type CloudRegion struct {
gorm.Model
Expand Down
Loading

0 comments on commit 8cc9a90

Please sign in to comment.