Skip to content

Commit

Permalink
Add table gcp_artifact_registry_repository Closes #473 (#496)
Browse files Browse the repository at this point in the history
Co-authored-by: Madhushree Ray <[email protected]>
  • Loading branch information
ParthaI and madhushreeray30 authored Oct 4, 2023
1 parent a759191 commit 4204413
Show file tree
Hide file tree
Showing 5 changed files with 487 additions and 1 deletion.
103 changes: 103 additions & 0 deletions docs/tables/gcp_artifact_registry_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Table: gcp_artifact_registry_repository

Google Cloud Artifact Registry is a managed artifact repository service provided by Google Cloud Platform (GCP). It is designed to store and manage software packages, container images, and other development artifacts. Artifact Registry helps organizations manage their dependencies, share software artifacts, and ensure the reliability and security of their software supply chain.

### Basic info

```sql
select
name,
cleanup_policy_dry_run,
create_time,
format,
kms_key_name,
mode
from
gcp_artifact_registry_repository;
```

### List unencrypted repositories

```sql
select
name,
cleanup_policy_dry_run,
create_time,
kms_key_name
from
gcp_artifact_registry_repository
where
kms_key_name = '';
```

### List docker format package repositories

```sql
select
name,
create_time,
description,
size_bytes,
format
from
gcp_artifact_registry_repository
where
format = 'DOCKER';
```

### List standard repositories

```sql
select
name,
format,
mode,
create_time
from
gcp_artifact_registry_repository
where
mode = 'STANDARD_REPOSITORY';
```

### List repositories that satisfies physical zone separation

```sql
select
name,
mode,
format,
satisfies_pzs,
description,
create_time
from
gcp_artifact_registry_repository
where
satisfies_pzs;
```

### Get docker configuration of repositories

```sql
select
name,
docker_config -> 'ImmutableTags' as immutable_tags,
docker_config ->> 'ForceSendFields' as force_send_fields,
docker_config ->> 'NullFields' as null_fields
from
gcp_artifact_registry_repository;
```

### Get remote repository config details of repositories

```sql
select
name,
remote_repository_config ->> 'AptRepository' as apt_repository,
remote_repository_config ->> 'DockerRepository' as docker_repository,
remote_repository_config ->> 'MavenRepository' as maven_repository,
remote_repository_config ->> 'NpmRepository' as npm_repository,
remote_repository_config ->> 'PythonRepository' as python_repository,
remote_repository_config ->> 'YumRepository' as yum_repository
from
gcp_artifact_registry_repository;
```
55 changes: 55 additions & 0 deletions gcp/artifact_registry_location_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package gcp

import (
"context"

"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"google.golang.org/api/artifactregistry/v1"
)


// BuildregionList :: return a list of matrix items, one per region specified
func BuildArtifactRegistryLocationList(ctx context.Context, d *plugin.QueryData) []map[string]interface{} {

// have we already created and cached the locations?
locationCacheKey := "ArtifactRegistry"
if cachedData, ok := d.ConnectionManager.Cache.Get(locationCacheKey); ok {
plugin.Logger(ctx).Trace("listlocationDetails:", cachedData.([]map[string]interface{}))
return cachedData.([]map[string]interface{})
}

// Create Service Connection
service, err := ArtifactRegistryService(ctx, d)
if err != nil {
return nil
}

// Get project details
projectData, err := activeProject(ctx, d)
if err != nil {
return nil
}
project := projectData.Project

resp := service.Projects.Locations.List("projects/" + project)
if err != nil {
return nil
}

var locations []*artifactregistry.Location

if err := resp.Pages(ctx, func(page *artifactregistry.ListLocationsResponse) error {
locations = append(locations, page.Locations...)
return nil
}); err != nil {
return nil
}

// validate location list
matrix := make([]map[string]interface{}, len(locations))
for i, location := range locations {
matrix[i] = map[string]interface{}{matrixKeyLocation: location.LocationId}
}
d.ConnectionManager.Cache.Set(locationCacheKey, matrix)
return matrix
}
1 change: 1 addition & 0 deletions gcp/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
},
TableMap: map[string]*plugin.Table{
"gcp_apikeys_key": tableGcpApiKeysKey(ctx),
"gcp_artifact_registry_repository": tableGcpArtifactRegistryRepository(ctx),
"gcp_audit_policy": tableGcpAuditPolicy(ctx),
"gcp_bigquery_dataset": tableGcpBigQueryDataset(ctx),
"gcp_bigquery_job": tableGcpBigQueryJob(ctx),
Expand Down
24 changes: 23 additions & 1 deletion gcp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package gcp
import (
"context"

redis "cloud.google.com/go/redis/apiv1"
"cloud.google.com/go/redis/apiv1"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"google.golang.org/api/accessapproval/v1"
"google.golang.org/api/apikeys/v2"
"google.golang.org/api/artifactregistry/v1"
"google.golang.org/api/bigquery/v2"
"google.golang.org/api/bigtableadmin/v2"
"google.golang.org/api/billingbudgets/v1"
Expand Down Expand Up @@ -136,6 +137,27 @@ func BigQueryService(ctx context.Context, d *plugin.QueryData) (*bigquery.Servic
return svc, nil
}

// ArtifactRegistryService returns the service connection for GCP ArtifactRegistry service
func ArtifactRegistryService(ctx context.Context, d *plugin.QueryData) (*artifactregistry.Service, error) {
// have we already created and cached the service?
serviceCacheKey := "ArtifactRegistryService"
if cachedData, ok := d.ConnectionManager.Cache.Get(serviceCacheKey); ok {
return cachedData.(*artifactregistry.Service), nil
}

// To get config arguments from plugin config file
opts := setSessionConfig(ctx, d.Connection)

// so it was not in cache - create service
svc, err := artifactregistry.NewService(ctx, opts...)
if err != nil {
return nil, err
}

d.ConnectionManager.Cache.Set(serviceCacheKey, svc)
return svc, nil
}

// BigtableAdminService returns the service connection for GCP Bigtable Admin service
func BigtableAdminService(ctx context.Context, d *plugin.QueryData) (*bigtableadmin.Service, error) {
// have we already created and cached the service?
Expand Down
Loading

0 comments on commit 4204413

Please sign in to comment.