-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a98715
commit 17f1a8d
Showing
15 changed files
with
433 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2022 The sacloud/object-storage-service-go Authors | ||
// | ||
// 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 accountkey | ||
|
||
import ( | ||
"github.com/sacloud/packages-go/validate" | ||
) | ||
|
||
type CreateRequest struct { | ||
SiteId string `service:"-" validate:"required"` | ||
} | ||
|
||
func (req *CreateRequest) Validate() error { | ||
return validate.New().Struct(req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022 The sacloud/object-storage-service-go Authors | ||
// | ||
// 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 accountkey | ||
|
||
import ( | ||
"context" | ||
|
||
objectstorage "github.com/sacloud/object-storage-api-go" | ||
v1 "github.com/sacloud/object-storage-api-go/apis/v1" | ||
) | ||
|
||
func (s *Service) Create(req *CreateRequest) (*v1.AccountKey, error) { | ||
return s.CreateWithContext(context.Background(), req) | ||
} | ||
|
||
func (s *Service) CreateWithContext(ctx context.Context, req *CreateRequest) (*v1.AccountKey, error) { | ||
if err := req.Validate(); err != nil { | ||
return nil, err | ||
} | ||
client := objectstorage.NewAccountOp(s.client) | ||
return client.CreateAccessKey(ctx, req.SiteId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2022 The sacloud/object-storage-service-go Authors | ||
// | ||
// 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 accountkey | ||
|
||
import ( | ||
"github.com/sacloud/packages-go/validate" | ||
) | ||
|
||
type DeleteRequest struct { | ||
SiteId string `service:"-" validate:"required"` | ||
Id string `service:"-" validate:"required"` // リソースId | ||
} | ||
|
||
func (req *DeleteRequest) Validate() error { | ||
return validate.New().Struct(req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2022 The sacloud/object-storage-service-go Authors | ||
// | ||
// 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 accountkey | ||
|
||
import ( | ||
"context" | ||
|
||
objectstorage "github.com/sacloud/object-storage-api-go" | ||
) | ||
|
||
func (s *Service) Delete(req *DeleteRequest) error { | ||
return s.DeleteWithContext(context.Background(), req) | ||
} | ||
|
||
func (s *Service) DeleteWithContext(ctx context.Context, req *DeleteRequest) error { | ||
if err := req.Validate(); err != nil { | ||
return err | ||
} | ||
_, err := s.ReadWithContext(ctx, &ReadRequest{ | ||
SiteId: req.SiteId, | ||
Id: req.Id, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
client := objectstorage.NewAccountOp(s.client) | ||
return client.DeleteAccessKey(ctx, req.SiteId, req.Id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2022 The sacloud/object-storage-service-go Authors | ||
// | ||
// 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 accountkey | ||
|
||
import "github.com/sacloud/packages-go/validate" | ||
|
||
type FindRequest struct { | ||
SiteId string `service:"-" validate:"required"` | ||
} | ||
|
||
func (req *FindRequest) Validate() error { | ||
return validate.New().Struct(req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2022 The sacloud/object-storage-service-go Authors | ||
// | ||
// 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 accountkey | ||
|
||
import ( | ||
"context" | ||
|
||
objectstorage "github.com/sacloud/object-storage-api-go" | ||
v1 "github.com/sacloud/object-storage-api-go/apis/v1" | ||
) | ||
|
||
func (s *Service) Find(req *FindRequest) ([]*v1.AccountKey, error) { | ||
return s.FindWithContext(context.Background(), req) | ||
} | ||
|
||
func (s *Service) FindWithContext(ctx context.Context, req *FindRequest) ([]*v1.AccountKey, error) { | ||
if req == nil { | ||
req = &FindRequest{} | ||
} | ||
if err := req.Validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
client := objectstorage.NewAccountOp(s.client) | ||
return client.ListAccessKeys(ctx, req.SiteId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2022 The sacloud/object-storage-service-go Authors | ||
// | ||
// 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 accountkey | ||
|
||
import ( | ||
"github.com/sacloud/packages-go/validate" | ||
) | ||
|
||
type ReadRequest struct { | ||
SiteId string `service:"-" validate:"required"` | ||
Id string `service:"-" validate:"required"` // リソースId | ||
} | ||
|
||
func (req *ReadRequest) Validate() error { | ||
return validate.New().Struct(req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2022 The sacloud/object-storage-service-go Authors | ||
// | ||
// 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 accountkey | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
objectstorage "github.com/sacloud/object-storage-api-go" | ||
v1 "github.com/sacloud/object-storage-api-go/apis/v1" | ||
service "github.com/sacloud/object-storage-service-go" | ||
) | ||
|
||
func (s *Service) Read(req *ReadRequest) (*v1.AccountKey, error) { | ||
return s.ReadWithContext(context.Background(), req) | ||
} | ||
|
||
func (s *Service) ReadWithContext(ctx context.Context, req *ReadRequest) (*v1.AccountKey, error) { | ||
if err := req.Validate(); err != nil { | ||
return nil, err | ||
} | ||
client := objectstorage.NewAccountOp(s.client) | ||
accountKey, err := client.ReadAccessKey(ctx, req.SiteId, req.Id) | ||
if err != nil { | ||
if v1.IsError404(err) { | ||
return nil, service.NotFoundError(fmt.Errorf("account-key %q not found", req.Id)) | ||
} | ||
return nil, err | ||
} | ||
return accountKey, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2022 The sacloud/object-storage-service-go Authors | ||
// | ||
// 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 accountkey | ||
|
||
import objectstorage "github.com/sacloud/object-storage-api-go" | ||
|
||
// Service provides a high-level API of for Site | ||
type Service struct { | ||
client *objectstorage.Client | ||
} | ||
|
||
// New returns new service instance of Archive | ||
func New(client *objectstorage.Client) *Service { | ||
return &Service{client: client} | ||
} |
Oops, something went wrong.