Skip to content

Commit

Permalink
Adding Azure Subscription persistence support
Browse files Browse the repository at this point in the history
  • Loading branch information
kickroot committed Mar 7, 2024
1 parent 1adde41 commit ab5a869
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.openraven.magpie.api.Emitter;
import io.openraven.magpie.api.MagpieAzureResource;
import io.openraven.magpie.api.Session;
import io.openraven.magpie.data.azure.subscriptions.Subscription;
import io.openraven.magpie.plugins.azure.discovery.VersionedMagpieEnvelopeProvider;
import org.slf4j.Logger;

Expand All @@ -47,10 +48,12 @@ public void discover(ObjectMapper mapper, Session session, Emitter emitter, Logg

private void discoverSubscriptions(ObjectMapper mapper, Session session, Emitter emitter, Logger logger, String subscriptionID, AzureResourceManager azrm, AzureProfile profile) {

final var resourceType = Subscription.RESOURCE_TYPE;

try {
azrm.subscriptions().list().forEach(sa -> {
var maybeTenantInfo = azrm.tenants().list().stream().filter(t -> t.tenantId().equals(azrm.tenantId())).map(Tenant::innerModel).findFirst();
final var resourceType = fullService() + ":subscriptions";

final var builder = new MagpieAzureResource.MagpieAzureResourceBuilder(mapper, sa.subscriptionId())
.withResourceType(resourceType)
.withResourceName(sa.displayName())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*-
* #%L
* Magpie API
* %%
* Copyright (C) 2021 Open Raven Inc
* %%
* 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.
* #L%
*/
/*
* Copyright 2021 Open Raven Inc
*
* 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.
*/
package io.openraven.magpie.data.azure.subscriptions;

import io.openraven.magpie.data.azure.AzureResource;

@javax.persistence.Entity
@javax.persistence.Inheritance(strategy = javax.persistence.InheritanceType.TABLE_PER_CLASS)
@javax.persistence.Table(name = Subscription.TABLE_NAME)
public class Subscription extends AzureResource {

protected static final String TABLE_NAME = "azuresubscription";
public static final String RESOURCE_TYPE = "Azure::Subscription";

@SuppressWarnings("unused")
public Subscription() {
this.resourceType = RESOURCE_TYPE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ create table azuresqldatabase () INHERITS (azure);
create table azuresqlserver () INHERITS (azure);
create table azurestorageaccount () INHERITS (azure);
create table azurestorageblobcontainer () INHERITS (azure);
create table azuresubscription () INHERITS (azure);

0 comments on commit ab5a869

Please sign in to comment.