mongo

package
v0.0.0-...-252f4b7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 27 Imported by: 3

Documentation

Overview

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

View Source
const (
	DbVersion     = "2.0.0"
	DbName        = "deviceauth"
	DbDevicesColl = "devices"
	DbAuthSetColl = "auth_sets"
	DbTokensColl  = "tokens"
	DbLimitsColl  = "limits"

	DbKeyDeviceRevision = "revision"
)

Variables

View Source
var DbAuthSetsCollectionIndices = []mongo.IndexModel{
	{
		Keys: bson.D{
			{Key: mstore.FieldTenantID, Value: 1},
			{Key: dbFieldIDDataSha, Value: 1},
			{Key: dbFieldPubKey, Value: 1},
		},
		Options: mopts.Index().
			SetName(strings.Join([]string{
				mstore.FieldTenantID,
				dbFieldIDDataSha,
				dbFieldPubKey,
			}, "_")).
			SetUnique(true),
	},
	{
		Keys: bson.D{
			{Key: mstore.FieldTenantID, Value: 1},
			{Key: dbFieldDeviceID, Value: 1},
		},
		Options: mopts.Index().
			SetName(strings.Join([]string{
				mstore.FieldTenantID,
				dbFieldDeviceID,
			}, "_")),
	},
}
View Source
var DbDevicesCollectionIndices = []mongo.IndexModel{
	{
		Keys: bson.D{
			{Key: mstore.FieldTenantID, Value: 1},
			{Key: dbFieldIDDataSha, Value: 1},
		},

		Options: mopts.Index().
			SetName(strings.Join([]string{
				mstore.FieldTenantID,
				dbFieldIDDataSha,
			}, "_")).
			SetUnique(true).
			SetBackground(false),
	},
	{
		Keys: bson.D{
			{Key: mstore.FieldTenantID, Value: 1},
			{Key: dbFieldStatus, Value: 1},
			{Key: dbFieldID, Value: 1},
		},

		Options: mopts.Index().
			SetName(strings.Join([]string{
				mstore.FieldTenantID,
				dbFieldStatus,
				dbFieldID,
			}, "_")).
			SetBackground(false),
	},
}
View Source
var DbLimitsCollectionIndices = []mongo.IndexModel{
	{
		Keys: bson.D{
			{Key: mstore.FieldTenantID, Value: 1},
			{Key: dbFieldName, Value: 1},
		},
		Options: mopts.Index().
			SetName(strings.Join([]string{
				mstore.FieldTenantID,
				dbFieldName,
			},
				"_",
			),
			).
			SetUnique(true),
	},
}
View Source
var DbTokensCollectionIndices = []mongo.IndexModel{
	{
		Keys: bson.D{
			{Key: dbFieldTenantClaim, Value: 1},
			{Key: dbFieldSubject, Value: 1},
		},
		Options: mopts.Index().
			SetName(
				strings.Join(
					[]string{
						strings.ReplaceAll(dbFieldTenantClaim, ".", "_"),
						dbFieldSubject,
					},
					"_",
				),
			),
	},
	{
		Keys: bson.D{
			{Key: dbFieldExpTime, Value: 1},
		},
		Options: mopts.Index().
			SetName(
				strings.Join(
					[]string{
						strings.ReplaceAll(dbFieldExpTime, ".", "_"),
					},
					"_",
				),
			).
			SetExpireAfterSeconds(0),
	},
}

Functions

This section is empty.

Types

type DataStoreMongo

type DataStoreMongo struct {
	// contains filtered or unexported fields
}

func NewDataStoreMongo

func NewDataStoreMongo(config DataStoreMongoConfig) (*DataStoreMongo, error)

func NewDataStoreMongoWithClient

func NewDataStoreMongoWithClient(client *mongo.Client) *DataStoreMongo

func (*DataStoreMongo) AddAuthSet

func (db *DataStoreMongo) AddAuthSet(ctx context.Context, set model.AuthSet) error

func (*DataStoreMongo) AddDevice

func (db *DataStoreMongo) AddDevice(ctx context.Context, d model.Device) error

func (*DataStoreMongo) AddToken

func (db *DataStoreMongo) AddToken(ctx context.Context, t *jwt.Token) error

func (*DataStoreMongo) DeleteAuthSetForDevice

func (db *DataStoreMongo) DeleteAuthSetForDevice(
	ctx context.Context,
	devId string,
	authId string,
) error

func (*DataStoreMongo) DeleteAuthSetsForDevice

func (db *DataStoreMongo) DeleteAuthSetsForDevice(ctx context.Context, devid string) error

func (*DataStoreMongo) DeleteBrokenAuthSets

func (db *DataStoreMongo) DeleteBrokenAuthSets(tenantId string) error

Deletes auth sets owned by devices that are in decommissioning state and auth sets not owned by any device.

func (*DataStoreMongo) DeleteDevice

func (db *DataStoreMongo) DeleteDevice(ctx context.Context, id string) error

func (*DataStoreMongo) DeleteDevicesBeingDecommissioned

func (db *DataStoreMongo) DeleteDevicesBeingDecommissioned(tenantId string) error

Deletes devices with decommissioning flag set

func (*DataStoreMongo) DeleteLimit

func (db *DataStoreMongo) DeleteLimit(ctx context.Context, lim string) error

func (*DataStoreMongo) DeleteToken

func (db *DataStoreMongo) DeleteToken(ctx context.Context, jti oid.ObjectID) error

func (*DataStoreMongo) DeleteTokenByDevId

func (db *DataStoreMongo) DeleteTokenByDevId(
	ctx context.Context,
	devID oid.ObjectID,
) error

func (*DataStoreMongo) DeleteTokens

func (db *DataStoreMongo) DeleteTokens(ctx context.Context) error

func (*DataStoreMongo) ForEachTenant

func (db *DataStoreMongo) ForEachTenant(
	ctx context.Context,
	mapFunc store.MapFunc,
) error

func (*DataStoreMongo) GetAuthSetById

func (db *DataStoreMongo) GetAuthSetById(
	ctx context.Context,
	auth_id string,
) (*model.AuthSet, error)

func (*DataStoreMongo) GetAuthSetByIdDataHashKey

func (db *DataStoreMongo) GetAuthSetByIdDataHashKey(
	ctx context.Context,
	idDataHash []byte,
	key string,
) (*model.AuthSet, error)

func (*DataStoreMongo) GetAuthSetByIdDataHashKeyByStatus

func (db *DataStoreMongo) GetAuthSetByIdDataHashKeyByStatus(
	ctx context.Context,
	idDataHash []byte,
	key string,
	status string,
) (*model.AuthSet, error)

func (*DataStoreMongo) GetAuthSetsForDevice

func (db *DataStoreMongo) GetAuthSetsForDevice(
	ctx context.Context,
	devid string,
) ([]model.AuthSet, error)

func (*DataStoreMongo) GetBrokenAuthSets

func (db *DataStoreMongo) GetBrokenAuthSets(tenantId string) ([]string, error)

Retrieves Ids of the auth sets owned by devices that are in decommissioning state or not owned by any device.

func (*DataStoreMongo) GetDevCountByStatus

func (db *DataStoreMongo) GetDevCountByStatus(ctx context.Context, status string) (int, error)

func (*DataStoreMongo) GetDeviceById

func (db *DataStoreMongo) GetDeviceById(ctx context.Context, id string) (*model.Device, error)

func (*DataStoreMongo) GetDeviceByIdentityDataHash

func (db *DataStoreMongo) GetDeviceByIdentityDataHash(
	ctx context.Context,
	idataHash []byte,
) (*model.Device, error)

func (*DataStoreMongo) GetDeviceStatus

func (db *DataStoreMongo) GetDeviceStatus(ctx context.Context, devId string) (string, error)

func (*DataStoreMongo) GetDevices

func (db *DataStoreMongo) GetDevices(
	ctx context.Context,
	skip,
	limit uint,
	filter model.DeviceFilter,
) ([]model.Device, error)

func (*DataStoreMongo) GetDevicesBeingDecommissioned

func (db *DataStoreMongo) GetDevicesBeingDecommissioned(tenantId string) ([]model.Device, error)

Retrieves devices with decommissioning flag set

func (*DataStoreMongo) GetLimit

func (db *DataStoreMongo) GetLimit(ctx context.Context, name string) (*model.Limit, error)

func (*DataStoreMongo) GetToken

func (db *DataStoreMongo) GetToken(
	ctx context.Context,
	jti oid.ObjectID,
) (*jwt.Token, error)

func (*DataStoreMongo) ListTenantsIds

func (db *DataStoreMongo) ListTenantsIds(
	ctx context.Context,
) ([]string, error)

func (*DataStoreMongo) Migrate

func (db *DataStoreMongo) Migrate(ctx context.Context, version string) error

func (*DataStoreMongo) MigrateTenant

func (db *DataStoreMongo) MigrateTenant(ctx context.Context, database, version string) error

func (*DataStoreMongo) Ping

func (db *DataStoreMongo) Ping(ctx context.Context) error

func (*DataStoreMongo) PutLimit

func (db *DataStoreMongo) PutLimit(ctx context.Context, lim model.Limit) error

func (*DataStoreMongo) RejectAuthSetsForDevice

func (db *DataStoreMongo) RejectAuthSetsForDevice(
	ctx context.Context,
	deviceID string,
) error

func (*DataStoreMongo) StoreMigrationVersion

func (db *DataStoreMongo) StoreMigrationVersion(
	ctx context.Context,
	version *migrate.Version,
) error

func (*DataStoreMongo) UpdateAuthSet

func (db *DataStoreMongo) UpdateAuthSet(
	ctx context.Context,
	filter interface{},
	mod model.AuthSetUpdate,
) error

func (*DataStoreMongo) UpdateAuthSetById

func (db *DataStoreMongo) UpdateAuthSetById(
	ctx context.Context,
	id string,
	mod model.AuthSetUpdate,
) error

func (*DataStoreMongo) UpdateDevice

func (db *DataStoreMongo) UpdateDevice(ctx context.Context,
	deviceID string, updev model.DeviceUpdate) error

func (*DataStoreMongo) WithAutomigrate

func (db *DataStoreMongo) WithAutomigrate() store.DataStore

func (*DataStoreMongo) WithMultitenant

func (db *DataStoreMongo) WithMultitenant() *DataStoreMongo

type DataStoreMongoConfig

type DataStoreMongoConfig struct {
	// connection string
	ConnectionString string

	// SSL support
	SSL           bool
	SSLSkipVerify bool

	// Overwrites credentials provided in connection string if provided
	Username string
	Password string
}

type DeviceFilter

type DeviceFilter model.DeviceFilter

func (DeviceFilter) MarshalBSON

func (fltr DeviceFilter) MarshalBSON() (b []byte, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL